diff --git a/src/Address/Concerns/LegacyConstants.php b/src/Address/Concerns/LegacyConstants.php new file mode 100644 index 00000000000..ddfabf2d591 --- /dev/null +++ b/src/Address/Concerns/LegacyConstants.php @@ -0,0 +1,15 @@ +getFieldLabel($attribute, $countryCode); + } +} diff --git a/yii2-adapter/constants/Asset/Concerns/LegacyConstants.php b/yii2-adapter/constants/Asset/Concerns/LegacyConstants.php new file mode 100644 index 00000000000..dca5111f415 --- /dev/null +++ b/yii2-adapter/constants/Asset/Concerns/LegacyConstants.php @@ -0,0 +1,197 @@ +value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_AUDIO = FileKind::Audio->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_CAPTIONS_SUBTITLES = FileKind::CaptionsSubtitles->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_COMPRESSED = FileKind::Compressed->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_EXCEL = FileKind::Excel->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_FLASH = FileKind::Flash->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_HTML = FileKind::Html->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_ILLUSTRATOR = FileKind::Illustrator->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_IMAGE = FileKind::Image->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_JAVASCRIPT = FileKind::Javascript->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_JSON = FileKind::Json->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_PDF = FileKind::Pdf->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_PHOTOSHOP = FileKind::Photoshop->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_PHP = FileKind::Php->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_POWERPOINT = FileKind::Powerpoint->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_TEXT = FileKind::Text->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_VIDEO = FileKind::Video->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_WORD = FileKind::Word->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_XML = FileKind::Xml->value; + + /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ + public const string KIND_UNKNOWN = FileKind::Unknown->value; + + // Events + // ------------------------------------------------------------------------- + + /** + * @event AssetEvent The event that is triggered before an asset is uploaded to volume. + */ + public const string EVENT_BEFORE_HANDLE_FILE = 'beforeHandleFile'; + + /** + * @event GenerateTransformEvent The event that is triggered before a transform is generated for an asset. + */ + public const string EVENT_BEFORE_GENERATE_TRANSFORM = 'beforeGenerateTransform'; + + /** + * @event GenerateTransformEvent The event that is triggered after a transform is generated for an asset. + */ + public const string EVENT_AFTER_GENERATE_TRANSFORM = 'afterGenerateTransform'; + + public static function registerEvents(): void + { + Event::listen(function(AssetUrlResolving $event) { + if (YiiEvent::hasHandlers(Asset::class, self::EVENT_BEFORE_DEFINE_URL)) { + $yiiEvent = new DefineAssetUrlEvent([ + 'transform' => $event->transform, + 'asset' => $event->asset, + 'sender' => $event->asset, + ]); + + YiiEvent::trigger(Asset::class, self::EVENT_BEFORE_DEFINE_URL, $yiiEvent); + + $event->url = $yiiEvent->url; + $event->handled = $yiiEvent->handled; + } + }); + + Event::listen(function(AssetUrlDefined $event) { + if (YiiEvent::hasHandlers(Asset::class, self::EVENT_DEFINE_URL)) { + $yiiEvent = new DefineAssetUrlEvent([ + 'transform' => $event->transform, + 'asset' => $event->asset, + 'sender' => $event->asset, + ]); + + YiiEvent::trigger(Asset::class, self::EVENT_DEFINE_URL, $yiiEvent); + + $event->url = $yiiEvent->url; + $event->handled = $yiiEvent->handled; + } + }); + + Event::listen(function(TransformGenerating $event) { + if (YiiEvent::hasHandlers(Asset::class, self::EVENT_BEFORE_GENERATE_TRANSFORM)) { + $yiiEvent = new GenerateTransformEvent([ + 'transform' => $event->transform, + 'asset' => $event->asset, + 'url' => $event->url, + 'sender' => $event->asset, + ]); + + YiiEvent::trigger(Asset::class, self::EVENT_BEFORE_GENERATE_TRANSFORM, $yiiEvent); + + $event->url = $yiiEvent->url; + } + }); + + Event::listen(function(AfterGenerateTransform $event) { + if (YiiEvent::hasHandlers(Asset::class, self::EVENT_AFTER_GENERATE_TRANSFORM)) { + $yiiEvent = new GenerateTransformEvent([ + 'transform' => $event->transform, + 'asset' => $event->asset, + 'url' => $event->url, + 'sender' => $event->asset, + ]); + + YiiEvent::trigger(Asset::class, self::EVENT_AFTER_GENERATE_TRANSFORM, $yiiEvent); + } + }); + + Event::listen(function(AssetFileHandling $event) { + if (YiiEvent::hasHandlers(Asset::class, self::EVENT_BEFORE_HANDLE_FILE)) { + $yiiEvent = new AssetEvent([ + 'asset' => $event->asset, + 'isNew' => $event->isNew, + ]); + + YiiEvent::trigger(Asset::class, self::EVENT_BEFORE_HANDLE_FILE, $yiiEvent); + } + }); + } +} diff --git a/yii2-adapter/constants/Element/Concerns/LegacyNestedElementManager.php b/yii2-adapter/constants/Element/Concerns/LegacyNestedElementManager.php new file mode 100644 index 00000000000..31743c8c588 --- /dev/null +++ b/yii2-adapter/constants/Element/Concerns/LegacyNestedElementManager.php @@ -0,0 +1,69 @@ + $event->elements, + 'sender' => $event->manager, + ])); + }); + + Event::listen(function(NewDuplicateNestedElementsEvent $event) { + if (!YiiEvent::hasHandlers(NestedElementManager::class, self::EVENT_AFTER_DUPLICATE_NESTED_ELEMENTS)) { + return; + } + + YiiEvent::trigger(NestedElementManager::class, self::EVENT_AFTER_DUPLICATE_NESTED_ELEMENTS, new DuplicateNestedElementsEvent([ + 'source' => $event->source, + 'target' => $event->target, + 'newElementIds' => $event->newElementIds, + 'sender' => $event->manager, + ])); + }); + + Event::listen(function(NestedElementRevisionsCreated $event) { + if (!YiiEvent::hasHandlers(NestedElementManager::class, self::EVENT_AFTER_CREATE_REVISIONS)) { + return; + } + + YiiEvent::trigger(NestedElementManager::class, self::EVENT_AFTER_CREATE_REVISIONS, new DuplicateNestedElementsEvent([ + 'source' => $event->source, + 'target' => $event->target, + 'newElementIds' => $event->newElementIds, + 'sender' => $event->manager, + ])); + }); + } +} diff --git a/yii2-adapter/constants/Entry/Concerns/LegacyConstants.php b/yii2-adapter/constants/Entry/Concerns/LegacyConstants.php new file mode 100644 index 00000000000..71a25143748 --- /dev/null +++ b/yii2-adapter/constants/Entry/Concerns/LegacyConstants.php @@ -0,0 +1,94 @@ + $event->entryTypes, + 'sender' => $event->entry, + ]); + + YiiEvent::trigger(Entry::class, self::EVENT_DEFINE_ENTRY_TYPES, $yiiEvent); + + $event->entryTypes = $yiiEvent->entryTypes; + } + }); + + Event::listen(function(EntryMetaFieldsResolving $event) { + if (YiiEvent::hasHandlers(Entry::class, self::EVENT_DEFINE_META_FIELDS)) { + $yiiEvent = new DefineMetaFields([ + 'element' => $event->entry, + 'sender' => $event->entry, + 'static' => $event->static, + 'fields' => $event->fields, + ]); + + YiiEvent::trigger(Entry::class, self::EVENT_DEFINE_META_FIELDS, $yiiEvent); + + $event->fields = $yiiEvent->fields; + } + }); + + Event::listen(function(EntryParentSelectionCriteriaResolving $event) { + if (YiiEvent::hasHandlers(Entry::class, self::EVENT_DEFINE_PARENT_SELECTION_CRITERIA)) { + $yiiEvent = new ElementCriteriaEvent([ + 'sender' => $event->entry, + 'criteria' => $event->criteria, + ]); + + YiiEvent::trigger(Entry::class, self::EVENT_DEFINE_PARENT_SELECTION_CRITERIA, $yiiEvent); + + $event->criteria = $yiiEvent->criteria; + } + }); + } +} diff --git a/yii2-adapter/constants/Field/Elements/Concerns/LegacyConstants.php b/yii2-adapter/constants/Field/Elements/Concerns/LegacyConstants.php new file mode 100644 index 00000000000..1065fcd46d2 --- /dev/null +++ b/yii2-adapter/constants/Field/Elements/Concerns/LegacyConstants.php @@ -0,0 +1,16 @@ +fullName; + } + + public static function registerEvents(): void + { + Event::listen(function(UserNameResolving $event) { + if (YiiEvent::hasHandlers(User::class, self::EVENT_DEFINE_NAME)) { + $yiiEvent = new DefineValueEvent(); + $yiiEvent->sender = $event->user; + + YiiEvent::trigger(User::class, self::EVENT_DEFINE_NAME, $yiiEvent); + + if ($yiiEvent->value !== null) { + $event->name = $yiiEvent->value; + } + } + }); + + Event::listen(function(UserFriendlyNameResolving $event) { + if (YiiEvent::hasHandlers(User::class, self::EVENT_DEFINE_FRIENDLY_NAME)) { + $yiiEvent = new DefineValueEvent(); + $yiiEvent->sender = $event->user; + + YiiEvent::trigger(User::class, self::EVENT_DEFINE_FRIENDLY_NAME, $yiiEvent); + + if ($yiiEvent->value !== null) { + $event->name = $yiiEvent->value; + } + } + }); + + Event::listen(UserAuthenticating::class, function(UserAuthenticating $event) { + if (YiiEvent::hasHandlers(User::class, self::EVENT_BEFORE_AUTHENTICATE)) { + $yiiEvent = new AuthenticateUserEvent(['password' => $event->credentials['password']]); + + YiiEvent::trigger(User::class, self::EVENT_BEFORE_AUTHENTICATE, $yiiEvent); + + $event->performAuthentication = $yiiEvent->performAuthentication; + } + }); + } +} diff --git a/yii2-adapter/legacy/base/Element.php b/yii2-adapter/legacy/base/Element.php index e85fb7c26ce..4a5e3accd8c 100644 --- a/yii2-adapter/legacy/base/Element.php +++ b/yii2-adapter/legacy/base/Element.php @@ -86,6 +86,7 @@ use CraftCms\Cms\Element\Events\SetRoute; use CraftCms\Cms\Element\Validation\ElementRules; use Illuminate\Support\Facades\Event; +use ReflectionClass; /** * @since 3.0.0 @@ -153,11 +154,11 @@ public static function registerEvents(): void Event::listen(function(ElementCacheTagsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_CACHE_TAGS)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_CACHE_TAGS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -166,7 +167,7 @@ public static function registerEvents(): void 'value' => $event->tags, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_CACHE_TAGS, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_CACHE_TAGS, $yiiEvent); $event->tags = $yiiEvent->value; } @@ -174,11 +175,11 @@ public static function registerEvents(): void Event::listen(function(ElementSourcesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_SOURCES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_SOURCES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -187,7 +188,7 @@ public static function registerEvents(): void 'sources' => $event->sources, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_SOURCES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_SOURCES, $yiiEvent); $event->sources = $yiiEvent->sources; } @@ -195,11 +196,11 @@ public static function registerEvents(): void Event::listen(function(ElementFieldLayoutsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_FIELD_LAYOUTS)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_FIELD_LAYOUTS)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -208,7 +209,7 @@ public static function registerEvents(): void 'fieldLayouts' => $event->fieldLayouts, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_FIELD_LAYOUTS, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_FIELD_LAYOUTS, $yiiEvent); $event->fieldLayouts = $yiiEvent->fieldLayouts; } @@ -216,11 +217,11 @@ public static function registerEvents(): void Event::listen(function(ElementPreviewTargetsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_PREVIEW_TARGETS)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_PREVIEW_TARGETS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -229,7 +230,7 @@ public static function registerEvents(): void 'previewTargets' => $event->previewTargets, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_PREVIEW_TARGETS, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_PREVIEW_TARGETS, $yiiEvent); $event->previewTargets = $yiiEvent->previewTargets; } @@ -237,11 +238,11 @@ public static function registerEvents(): void Event::listen(function(ElementActionsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_ACTIONS)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_ACTIONS)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -250,7 +251,7 @@ public static function registerEvents(): void 'actions' => $event->actions, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_ACTIONS, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_ACTIONS, $yiiEvent); $event->actions = $yiiEvent->actions; } @@ -258,11 +259,11 @@ public static function registerEvents(): void Event::listen(function(ElementExportersResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_EXPORTERS)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_EXPORTERS)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -271,7 +272,7 @@ public static function registerEvents(): void 'exporters' => $event->exporters, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_EXPORTERS, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_EXPORTERS, $yiiEvent); $event->exporters = $yiiEvent->exporters; } @@ -279,11 +280,11 @@ public static function registerEvents(): void Event::listen(function(ElementRendering $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_RENDER)) { + if (!self::hasEventHandlers($class, self::EVENT_RENDER)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -293,7 +294,7 @@ public static function registerEvents(): void 'variables' => $event->variables, ]); - YiiEvent::trigger($class, self::EVENT_RENDER, $yiiEvent); + self::triggerEvent($class, self::EVENT_RENDER, $yiiEvent); if (isset($yiiEvent->output)) { $event->output = $yiiEvent->output; @@ -305,11 +306,11 @@ public static function registerEvents(): void Event::listen(function(ElementKeywordsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_KEYWORDS)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_KEYWORDS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -319,7 +320,7 @@ public static function registerEvents(): void 'keywords' => $event->keywords, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_KEYWORDS, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_KEYWORDS, $yiiEvent); if ($yiiEvent->handled) { $event->keywords = $yiiEvent->keywords; @@ -330,11 +331,11 @@ public static function registerEvents(): void Event::listen(function(ElementSortOptionsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_SORT_OPTIONS)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_SORT_OPTIONS)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -342,7 +343,7 @@ public static function registerEvents(): void 'sortOptions' => $event->sortOptions, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_SORT_OPTIONS, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_SORT_OPTIONS, $yiiEvent); $event->sortOptions = $yiiEvent->sortOptions; } @@ -350,11 +351,11 @@ public static function registerEvents(): void Event::listen(function(ElementTableAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_TABLE_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_TABLE_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -362,7 +363,7 @@ public static function registerEvents(): void 'tableAttributes' => $event->tableAttributes, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_TABLE_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_TABLE_ATTRIBUTES, $yiiEvent); $event->tableAttributes = $yiiEvent->tableAttributes; } @@ -370,11 +371,11 @@ public static function registerEvents(): void Event::listen(function(ElementDefaultTableAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_DEFAULT_TABLE_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_DEFAULT_TABLE_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -383,7 +384,7 @@ public static function registerEvents(): void 'tableAttributes' => $event->tableAttributes, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_DEFAULT_TABLE_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_DEFAULT_TABLE_ATTRIBUTES, $yiiEvent); $event->tableAttributes = $yiiEvent->tableAttributes; } @@ -391,11 +392,11 @@ public static function registerEvents(): void Event::listen(function(ElementCardAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_CARD_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_CARD_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -404,7 +405,7 @@ public static function registerEvents(): void 'fieldLayout' => $event->fieldLayout, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_CARD_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_CARD_ATTRIBUTES, $yiiEvent); $event->cardAttributes = $yiiEvent->cardAttributes; } @@ -412,11 +413,11 @@ public static function registerEvents(): void Event::listen(function(ElementDefaultCardAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_DEFAULT_CARD_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_DEFAULT_CARD_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -424,7 +425,7 @@ public static function registerEvents(): void 'cardAttributes' => $event->cardAttributes, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_DEFAULT_CARD_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_DEFAULT_CARD_ATTRIBUTES, $yiiEvent); $event->cardAttributes = $yiiEvent->cardAttributes; } @@ -432,11 +433,11 @@ public static function registerEvents(): void Event::listen(function(ElementSearchableAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -444,7 +445,7 @@ public static function registerEvents(): void 'attributes' => $event->attributes, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES, $yiiEvent); $event->attributes = $yiiEvent->attributes; } @@ -452,11 +453,11 @@ public static function registerEvents(): void Event::listen(function(QueryForTableAttributePreparing $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_PREP_QUERY_FOR_TABLE_ATTRIBUTE)) { + if (!self::hasEventHandlers($class, self::EVENT_PREP_QUERY_FOR_TABLE_ATTRIBUTE)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -465,7 +466,7 @@ public static function registerEvents(): void 'attribute' => $event->attribute, ]); - YiiEvent::trigger($class, self::EVENT_PREP_QUERY_FOR_TABLE_ATTRIBUTE, $yiiEvent); + self::triggerEvent($class, self::EVENT_PREP_QUERY_FOR_TABLE_ATTRIBUTE, $yiiEvent); if ($yiiEvent->handled) { $event->handled = true; @@ -475,11 +476,11 @@ public static function registerEvents(): void Event::listen(function(ElementEagerLoadingMapResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_EAGER_LOADING_MAP)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_EAGER_LOADING_MAP)) { continue; } - if (!is_subclass_of($class, $event->elementType)) { + if (!self::matchesElementClass($class, $event->elementType)) { continue; } @@ -488,7 +489,7 @@ public static function registerEvents(): void 'handle' => $event->handle, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_EAGER_LOADING_MAP, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_EAGER_LOADING_MAP, $yiiEvent); if ($yiiEvent->elementType !== null) { $event->targetElementType = $yiiEvent->elementType; @@ -500,11 +501,11 @@ public static function registerEvents(): void Event::listen(function(SetEagerLoadedElements $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_SET_EAGER_LOADED_ELEMENTS)) { + if (!self::hasEventHandlers($class, self::EVENT_SET_EAGER_LOADED_ELEMENTS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -515,7 +516,7 @@ public static function registerEvents(): void 'plan' => $event->plan, ]); - YiiEvent::trigger($class, self::EVENT_SET_EAGER_LOADED_ELEMENTS, $yiiEvent); + self::triggerEvent($class, self::EVENT_SET_EAGER_LOADED_ELEMENTS, $yiiEvent); if ($yiiEvent->handled) { $event->handled = true; @@ -525,11 +526,11 @@ public static function registerEvents(): void Event::listen(function(ElementLifecycleSaving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_BEFORE_SAVE)) { + if (!self::hasEventHandlers($class, self::EVENT_BEFORE_SAVE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -538,7 +539,7 @@ public static function registerEvents(): void 'isNew' => $event->isNew, ]); - YiiEvent::trigger($class, self::EVENT_BEFORE_SAVE, $yiiEvent); + self::triggerEvent($class, self::EVENT_BEFORE_SAVE, $yiiEvent); if (!$yiiEvent->isValid) { $event->isValid = false; @@ -548,11 +549,11 @@ public static function registerEvents(): void Event::listen(function(ElementLifecycleSaved $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_AFTER_SAVE)) { + if (!self::hasEventHandlers($class, self::EVENT_AFTER_SAVE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -561,17 +562,17 @@ public static function registerEvents(): void 'isNew' => $event->isNew, ]); - YiiEvent::trigger($class, self::EVENT_AFTER_SAVE, $yiiEvent); + self::triggerEvent($class, self::EVENT_AFTER_SAVE, $yiiEvent); } }); Event::listen(function(ElementLifecyclePropagated $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_AFTER_PROPAGATE)) { + if (!self::hasEventHandlers($class, self::EVENT_AFTER_PROPAGATE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -580,17 +581,17 @@ public static function registerEvents(): void 'isNew' => $event->isNew, ]); - YiiEvent::trigger($class, self::EVENT_AFTER_PROPAGATE, $yiiEvent); + self::triggerEvent($class, self::EVENT_AFTER_PROPAGATE, $yiiEvent); } }); Event::listen(function(ElementLifecycleDeleting $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_BEFORE_DELETE)) { + if (!self::hasEventHandlers($class, self::EVENT_BEFORE_DELETE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -598,7 +599,7 @@ public static function registerEvents(): void 'sender' => $event->element, ]); - YiiEvent::trigger($class, self::EVENT_BEFORE_DELETE, $yiiEvent); + self::triggerEvent($class, self::EVENT_BEFORE_DELETE, $yiiEvent); if (!$yiiEvent->isValid) { $event->isValid = false; @@ -608,11 +609,11 @@ public static function registerEvents(): void Event::listen(function(ElementLifecycleDeleted $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_AFTER_DELETE)) { + if (!self::hasEventHandlers($class, self::EVENT_AFTER_DELETE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -620,17 +621,17 @@ public static function registerEvents(): void 'sender' => $event->element, ]); - YiiEvent::trigger($class, self::EVENT_AFTER_DELETE, $yiiEvent); + self::triggerEvent($class, self::EVENT_AFTER_DELETE, $yiiEvent); } }); Event::listen(function(ElementLifecycleRestoring $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_BEFORE_RESTORE)) { + if (!self::hasEventHandlers($class, self::EVENT_BEFORE_RESTORE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -638,7 +639,7 @@ public static function registerEvents(): void 'sender' => $event->element, ]); - YiiEvent::trigger($class, self::EVENT_BEFORE_RESTORE, $yiiEvent); + self::triggerEvent($class, self::EVENT_BEFORE_RESTORE, $yiiEvent); if (!$yiiEvent->isValid) { $event->isValid = false; @@ -648,11 +649,11 @@ public static function registerEvents(): void Event::listen(function(ElementLifecycleRestored $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_AFTER_RESTORE)) { + if (!self::hasEventHandlers($class, self::EVENT_AFTER_RESTORE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -660,17 +661,17 @@ public static function registerEvents(): void 'sender' => $event->element, ]); - YiiEvent::trigger($class, self::EVENT_AFTER_RESTORE, $yiiEvent); + self::triggerEvent($class, self::EVENT_AFTER_RESTORE, $yiiEvent); } }); Event::listen(function(ElementAdditionalButtonsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_ADDITIONAL_BUTTONS)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_ADDITIONAL_BUTTONS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -679,7 +680,7 @@ public static function registerEvents(): void 'html' => $event->html, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_ADDITIONAL_BUTTONS, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_ADDITIONAL_BUTTONS, $yiiEvent); $event->html = $yiiEvent->html; } @@ -687,11 +688,11 @@ public static function registerEvents(): void Event::listen(function(ElementAltActionsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_ALT_ACTIONS)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_ALT_ACTIONS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -700,7 +701,7 @@ public static function registerEvents(): void 'altActions' => $event->altActions, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_ALT_ACTIONS, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_ALT_ACTIONS, $yiiEvent); $event->altActions = $yiiEvent->altActions; } @@ -708,11 +709,11 @@ public static function registerEvents(): void Event::listen(function(ElementActionMenuItemsResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_ACTION_MENU_ITEMS)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_ACTION_MENU_ITEMS)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -721,7 +722,7 @@ public static function registerEvents(): void 'items' => $event->items, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_ACTION_MENU_ITEMS, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_ACTION_MENU_ITEMS, $yiiEvent); $event->items = $yiiEvent->items; } @@ -729,11 +730,11 @@ public static function registerEvents(): void Event::listen(function(ElementSidebarHtmlResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_SIDEBAR_HTML)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_SIDEBAR_HTML)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -742,7 +743,7 @@ public static function registerEvents(): void 'html' => $event->html, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_SIDEBAR_HTML, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_SIDEBAR_HTML, $yiiEvent); $event->html = $yiiEvent->html; } @@ -750,11 +751,11 @@ public static function registerEvents(): void Event::listen(function(ElementMetaFieldsHtmlResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_META_FIELDS_HTML)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_META_FIELDS_HTML)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -764,7 +765,7 @@ public static function registerEvents(): void 'html' => $event->html, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_META_FIELDS_HTML, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_META_FIELDS_HTML, $yiiEvent); $event->html = $yiiEvent->html; } @@ -772,11 +773,11 @@ public static function registerEvents(): void Event::listen(function(ElementMetadataResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_METADATA)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_METADATA)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -785,7 +786,7 @@ public static function registerEvents(): void 'metadata' => $event->metadata, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_METADATA, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_METADATA, $yiiEvent); $event->metadata = $yiiEvent->metadata; } @@ -793,11 +794,11 @@ public static function registerEvents(): void Event::listen(function(ElementHtmlAttributesResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_REGISTER_HTML_ATTRIBUTES)) { + if (!self::hasEventHandlers($class, self::EVENT_REGISTER_HTML_ATTRIBUTES)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -806,7 +807,7 @@ public static function registerEvents(): void 'htmlAttributes' => $event->htmlAttributes, ]); - YiiEvent::trigger($class, self::EVENT_REGISTER_HTML_ATTRIBUTES, $yiiEvent); + self::triggerEvent($class, self::EVENT_REGISTER_HTML_ATTRIBUTES, $yiiEvent); $event->htmlAttributes = $yiiEvent->htmlAttributes; } @@ -814,11 +815,11 @@ public static function registerEvents(): void Event::listen(function(ElementAttributeHtmlResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_ATTRIBUTE_HTML)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_ATTRIBUTE_HTML)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -827,7 +828,7 @@ public static function registerEvents(): void 'attribute' => $event->attribute, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_ATTRIBUTE_HTML, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_ATTRIBUTE_HTML, $yiiEvent); if (isset($yiiEvent->html)) { $event->html = $yiiEvent->html; @@ -837,11 +838,11 @@ public static function registerEvents(): void Event::listen(function(ElementInlineAttributeInputHtmlResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -850,7 +851,7 @@ public static function registerEvents(): void 'attribute' => $event->attribute, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML, $yiiEvent); if (isset($yiiEvent->html)) { $event->html = $yiiEvent->html; @@ -860,11 +861,11 @@ public static function registerEvents(): void Event::listen(function(SetRoute $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_SET_ROUTE)) { + if (!self::hasEventHandlers($class, self::EVENT_SET_ROUTE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -873,7 +874,7 @@ public static function registerEvents(): void 'route' => $event->route, ]); - YiiEvent::trigger($class, self::EVENT_SET_ROUTE, $yiiEvent); + self::triggerEvent($class, self::EVENT_SET_ROUTE, $yiiEvent); $event->route = $yiiEvent->route; if ($yiiEvent->handled) { @@ -884,11 +885,11 @@ public static function registerEvents(): void Event::listen(function(ElementUrlResolving $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_BEFORE_DEFINE_URL)) { + if (!self::hasEventHandlers($class, self::EVENT_BEFORE_DEFINE_URL)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -897,7 +898,7 @@ public static function registerEvents(): void 'url' => $event->url, ]); - YiiEvent::trigger($class, self::EVENT_BEFORE_DEFINE_URL, $yiiEvent); + self::triggerEvent($class, self::EVENT_BEFORE_DEFINE_URL, $yiiEvent); $event->url = $yiiEvent->url; if ($yiiEvent->handled) { @@ -908,11 +909,11 @@ public static function registerEvents(): void Event::listen(function(ElementUrlResolved $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_DEFINE_URL)) { + if (!self::hasEventHandlers($class, self::EVENT_DEFINE_URL)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -921,7 +922,7 @@ public static function registerEvents(): void 'url' => $event->url, ]); - YiiEvent::trigger($class, self::EVENT_DEFINE_URL, $yiiEvent); + self::triggerEvent($class, self::EVENT_DEFINE_URL, $yiiEvent); $event->url = $yiiEvent->url; if ($yiiEvent->handled) { @@ -932,11 +933,11 @@ public static function registerEvents(): void Event::listen(function(ElementMovingInStructure $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_BEFORE_MOVE_IN_STRUCTURE)) { + if (!self::hasEventHandlers($class, self::EVENT_BEFORE_MOVE_IN_STRUCTURE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -945,7 +946,7 @@ public static function registerEvents(): void 'structureId' => $event->structureId, ]); - YiiEvent::trigger($class, self::EVENT_BEFORE_MOVE_IN_STRUCTURE, $yiiEvent); + self::triggerEvent($class, self::EVENT_BEFORE_MOVE_IN_STRUCTURE, $yiiEvent); if (!$yiiEvent->isValid) { $event->isValid = false; @@ -955,11 +956,11 @@ public static function registerEvents(): void Event::listen(function(ElementMovedInStructure $event) use ($elementClasses) { foreach ($elementClasses as $class) { - if (!YiiEvent::hasHandlers($class, self::EVENT_AFTER_MOVE_IN_STRUCTURE)) { + if (!self::hasEventHandlers($class, self::EVENT_AFTER_MOVE_IN_STRUCTURE)) { continue; } - if (!is_subclass_of($class, $event->element::class)) { + if (!self::matchesElementClass($class, $event->element::class)) { continue; } @@ -968,8 +969,76 @@ public static function registerEvents(): void 'structureId' => $event->structureId, ]); - YiiEvent::trigger($class, self::EVENT_AFTER_MOVE_IN_STRUCTURE, $yiiEvent); + self::triggerEvent($class, self::EVENT_AFTER_MOVE_IN_STRUCTURE, $yiiEvent); } }); } + + private static function hasEventHandlers(string $class, string $name): bool + { + foreach (self::eventTargetClasses($class) as $targetClass) { + if (YiiEvent::hasHandlers($targetClass, $name)) { + return true; + } + } + + return false; + } + + private static function triggerEvent(string $class, string $name, \yii\base\Event $event): void + { + foreach (self::eventTargetClasses($class) as $targetClass) { + if (!YiiEvent::hasHandlers($targetClass, $name)) { + continue; + } + + YiiEvent::trigger($targetClass, $name, $event); + + if ($event->handled) { + return; + } + } + } + + /** + * @return list + */ + private static function eventTargetClasses(string $class): array + { + $classes = [$class]; + $resolvedClass = self::resolvedClass($class); + + if ($resolvedClass !== $class) { + $classes[] = $resolvedClass; + } + + if ( + $class !== self::class && + !is_subclass_of($class, self::class) && + is_a($resolvedClass, \CraftCms\Cms\Element\Element::class, true) + ) { + $classes[] = self::class; + } + + return array_values(array_unique($classes)); + } + + private static function matchesElementClass(string $class, string $elementClass): bool + { + $class = self::resolvedClass($class); + $elementClass = self::resolvedClass($elementClass); + + return $class === $elementClass || + is_subclass_of($class, $elementClass) || + is_subclass_of($elementClass, $class); + } + + private static function resolvedClass(string $class): string + { + if (!class_exists($class) && !interface_exists($class)) { + return $class; + } + + return (new ReflectionClass($class))->getName(); + } } diff --git a/yii2-adapter/legacy/elements/Address.php b/yii2-adapter/legacy/elements/Address.php index f7d6da1c148..27ac28f4e9a 100644 --- a/yii2-adapter/legacy/elements/Address.php +++ b/yii2-adapter/legacy/elements/Address.php @@ -2,34 +2,21 @@ namespace craft\elements; -use CommerceGuys\Addressing\AddressFormat\AddressField; -use craft\base\ElementEventConstants; -use CraftCms\Cms\Address\Addresses; use Deprecated; -/** - * Address element class - * - * @author Pixel & Tonic, Inc. - * - * @since 4.0.0 - * @deprecated 6.0.0 use {@see \CraftCms\Cms\Address\Elements\Address} instead. - */ -class Address extends \CraftCms\Cms\Address\Elements\Address -{ - use ElementEventConstants; - +/** @phpstan-ignore-next-line */ +if (false) { /** - * Returns an address attribute label. + * Address element class + * + * @author Pixel & Tonic, Inc. + * + * @since 4.0.0 + * @deprecated 6.0.0 use {@see \CraftCms\Cms\Address\Elements\Address} instead. */ - #[Deprecated(message: 'in 4.3.0. [[\craft\services\Addresses::getFieldLabel()]] should be used instead.')] - public static function addressAttributeLabel(string $attribute, string $countryCode): ?string + class Address extends \CraftCms\Cms\Address\Elements\Address { - if (!AddressField::exists($attribute)) { - return null; - } - - /** @phpstan-var AddressField::* $attribute */ - return app(Addresses::class)->getFieldLabel($attribute, $countryCode); } } + +class_alias(\CraftCms\Cms\Address\Elements\Address::class, Address::class); diff --git a/yii2-adapter/legacy/elements/Asset.php b/yii2-adapter/legacy/elements/Asset.php index 7e5bc01537a..620ca5dbf2a 100644 --- a/yii2-adapter/legacy/elements/Asset.php +++ b/yii2-adapter/legacy/elements/Asset.php @@ -9,192 +9,15 @@ namespace craft\elements; -use craft\base\ElementEventConstants; -use craft\base\Event as YiiEvent; -use craft\events\AssetEvent; -use craft\events\DefineAssetUrlEvent; -use craft\events\GenerateTransformEvent; -use CraftCms\Cms\Asset\Enums\FileKind; -use CraftCms\Cms\Asset\Events\AfterGenerateTransform; -use CraftCms\Cms\Asset\Events\AssetFileHandling; -use CraftCms\Cms\Asset\Events\AssetUrlDefined; -use CraftCms\Cms\Asset\Events\AssetUrlResolving; -use CraftCms\Cms\Asset\Events\TransformGenerating; -use CraftCms\Cms\Asset\Validation\AssetRules; -use CraftCms\Cms\Element\Validation\ElementRules; -use Illuminate\Support\Facades\Event; - -/** - * @since 3.0.0 - * @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Elements\Asset} instead. - */ -class Asset extends \CraftCms\Cms\Asset\Elements\Asset -{ - use ElementEventConstants; - - public const string SCENARIO_DEFAULT = ElementRules::SCENARIO_DEFAULT; - - public const string SCENARIO_ESSENTIALS = ElementRules::SCENARIO_ESSENTIALS; - - public const string SCENARIO_LIVE = ElementRules::SCENARIO_LIVE; - - public const string SCENARIO_MOVE = AssetRules::SCENARIO_MOVE; - - public const string SCENARIO_FILEOPS = AssetRules::SCENARIO_FILEOPS; - - public const string SCENARIO_INDEX = AssetRules::SCENARIO_INDEX; - - public const string SCENARIO_CREATE = AssetRules::SCENARIO_CREATE; - - public const string SCENARIO_REPLACE = AssetRules::SCENARIO_REPLACE; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_ACCESS = FileKind::Access->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_AUDIO = FileKind::Audio->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_CAPTIONS_SUBTITLES = FileKind::CaptionsSubtitles->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_COMPRESSED = FileKind::Compressed->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_EXCEL = FileKind::Excel->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_FLASH = FileKind::Flash->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_HTML = FileKind::Html->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_ILLUSTRATOR = FileKind::Illustrator->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_IMAGE = FileKind::Image->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_JAVASCRIPT = FileKind::Javascript->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_JSON = FileKind::Json->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_PDF = FileKind::Pdf->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_PHOTOSHOP = FileKind::Photoshop->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_PHP = FileKind::Php->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_POWERPOINT = FileKind::Powerpoint->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_TEXT = FileKind::Text->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_VIDEO = FileKind::Video->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_WORD = FileKind::Word->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_XML = FileKind::Xml->value; - - /** @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Enums\FileKind} instead. */ - public const string KIND_UNKNOWN = FileKind::Unknown->value; - - // Events - // ------------------------------------------------------------------------- - +/** @phpstan-ignore-next-line */ +if (false) { /** - * @event AssetEvent The event that is triggered before an asset is uploaded to volume. + * @since 3.0.0 + * @deprecated 6.0.0 use {@see \CraftCms\Cms\Asset\Elements\Asset} instead. */ - public const string EVENT_BEFORE_HANDLE_FILE = 'beforeHandleFile'; - - /** - * @event GenerateTransformEvent The event that is triggered before a transform is generated for an asset. - */ - public const string EVENT_BEFORE_GENERATE_TRANSFORM = 'beforeGenerateTransform'; - - /** - * @event GenerateTransformEvent The event that is triggered after a transform is generated for an asset. - */ - public const string EVENT_AFTER_GENERATE_TRANSFORM = 'afterGenerateTransform'; - - public static function registerEvents(): void + class Asset extends \CraftCms\Cms\Asset\Elements\Asset { - Event::listen(function(AssetUrlResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_BEFORE_DEFINE_URL)) { - $yiiEvent = new DefineAssetUrlEvent([ - 'transform' => $event->transform, - 'asset' => $event->asset, - 'sender' => $event->asset, - ]); - - YiiEvent::trigger(self::class, self::EVENT_BEFORE_DEFINE_URL, $yiiEvent); - - $event->url = $yiiEvent->url; - $event->handled = $yiiEvent->handled; - } - }); - - Event::listen(function(AssetUrlDefined $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_URL)) { - $yiiEvent = new DefineAssetUrlEvent([ - 'transform' => $event->transform, - 'asset' => $event->asset, - 'sender' => $event->asset, - ]); - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_URL, $yiiEvent); - - $event->url = $yiiEvent->url; - $event->handled = $yiiEvent->handled; - } - }); - - Event::listen(function(TransformGenerating $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_BEFORE_GENERATE_TRANSFORM)) { - $yiiEvent = new GenerateTransformEvent([ - 'transform' => $event->transform, - 'asset' => $event->asset, - 'url' => $event->url, - 'sender' => $event->asset, - ]); - - YiiEvent::trigger(self::class, self::EVENT_BEFORE_GENERATE_TRANSFORM, $yiiEvent); - - $event->url = $yiiEvent->url; - } - }); - - Event::listen(function(AfterGenerateTransform $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_AFTER_GENERATE_TRANSFORM)) { - $yiiEvent = new GenerateTransformEvent([ - 'transform' => $event->transform, - 'asset' => $event->asset, - 'url' => $event->url, - 'sender' => $event->asset, - ]); - - YiiEvent::trigger(self::class, self::EVENT_AFTER_GENERATE_TRANSFORM, $yiiEvent); - } - }); - - Event::listen(function(AssetFileHandling $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_BEFORE_HANDLE_FILE)) { - $yiiEvent = new AssetEvent([ - 'asset' => $event->asset, - 'isNew' => $event->isNew, - ]); - - YiiEvent::trigger(self::class, self::EVENT_BEFORE_HANDLE_FILE, $yiiEvent); - } - }); } } + +class_alias(\CraftCms\Cms\Asset\Elements\Asset::class, Asset::class); diff --git a/yii2-adapter/legacy/elements/ContentBlock.php b/yii2-adapter/legacy/elements/ContentBlock.php index 7a1a30b994d..63b9461aa0d 100644 --- a/yii2-adapter/legacy/elements/ContentBlock.php +++ b/yii2-adapter/legacy/elements/ContentBlock.php @@ -9,13 +9,15 @@ namespace craft\elements; -use craft\base\ElementEventConstants; - -/** - * @since 5.8.0 - * @deprecated 6.0.0 use {@see \CraftCms\Cms\Field\Elements\ContentBlock} instead. - */ -class ContentBlock extends \CraftCms\Cms\Field\Elements\ContentBlock -{ - use ElementEventConstants; +/** @phpstan-ignore-next-line */ +if (false) { + /** + * @since 5.8.0 + * @deprecated 6.0.0 use {@see \CraftCms\Cms\Field\Elements\ContentBlock} instead. + */ + class ContentBlock extends \CraftCms\Cms\Field\Elements\ContentBlock + { + } } + +class_alias(\CraftCms\Cms\Field\Elements\ContentBlock::class, ContentBlock::class); diff --git a/yii2-adapter/legacy/elements/Entry.php b/yii2-adapter/legacy/elements/Entry.php index 9f086c2f642..4fa8eb76204 100644 --- a/yii2-adapter/legacy/elements/Entry.php +++ b/yii2-adapter/legacy/elements/Entry.php @@ -9,89 +9,15 @@ namespace craft\elements; -use craft\base\ElementEventConstants; -use craft\base\Event as YiiEvent; -use craft\events\DefineEntryTypesEvent; -use craft\events\DefineMetaFields; -use craft\events\ElementCriteriaEvent; -use CraftCms\Cms\Entry\Events\EntryMetaFieldsResolving; -use CraftCms\Cms\Entry\Events\EntryParentSelectionCriteriaResolving; -use CraftCms\Cms\Entry\Events\EntryTypesResolving; -use Illuminate\Support\Facades\Event; - -/** - * @since 3.0.0 - * @deprecated 6.0.0 use {@see \CraftCms\Cms\Entry\Elements\Entry} instead. - */ -class Entry extends \CraftCms\Cms\Entry\Elements\Entry -{ - use ElementEventConstants; - - /** - * @event DefineEntryTypesEvent The event that is triggered when defining the available entry types for the entry - * - * @see getAvailableEntryTypes() - * @since 3.6.0 - */ - public const string EVENT_DEFINE_ENTRY_TYPES = 'defineEntryTypes'; - - /** - * @event ElementCriteriaEvent The event that is triggered when defining the parent selection criteria. - * - * @see _parentOptionCriteria() - * @since 4.4.0 - */ - public const string EVENT_DEFINE_PARENT_SELECTION_CRITERIA = 'defineParentSelectionCriteria'; - +/** @phpstan-ignore-next-line */ +if (false) { /** - * @event DefineMetaFields The event that is triggered when defining the meta fields. - * - * @see metaFieldsHtml() - * @since 5.9.0 + * @since 3.0.0 + * @deprecated 6.0.0 use {@see \CraftCms\Cms\Entry\Elements\Entry} instead. */ - public const string EVENT_DEFINE_META_FIELDS = 'defineEntryMetaFields'; - - public static function registerEvents(): void + class Entry extends \CraftCms\Cms\Entry\Elements\Entry { - Event::listen(function(EntryTypesResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_ENTRY_TYPES)) { - $yiiEvent = new DefineEntryTypesEvent([ - 'entryTypes' => $event->entryTypes, - 'sender' => $event->entry, - ]); - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_ENTRY_TYPES, $yiiEvent); - - $event->entryTypes = $yiiEvent->entryTypes; - } - }); - - Event::listen(function(EntryMetaFieldsResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_META_FIELDS)) { - $yiiEvent = new DefineMetaFields([ - 'element' => $event->entry, - 'sender' => $event->entry, - 'static' => $event->static, - 'fields' => $event->fields, - ]); - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_META_FIELDS, $yiiEvent); - - $event->fields = $yiiEvent->fields; - } - }); - - Event::listen(function(EntryParentSelectionCriteriaResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_PARENT_SELECTION_CRITERIA)) { - $yiiEvent = new ElementCriteriaEvent([ - 'sender' => $event->entry, - 'criteria' => $event->criteria, - ]); - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_PARENT_SELECTION_CRITERIA, $yiiEvent); - - $event->criteria = $yiiEvent->criteria; - } - }); } } + +class_alias(\CraftCms\Cms\Entry\Elements\Entry::class, Entry::class); diff --git a/yii2-adapter/legacy/elements/NestedElementManager.php b/yii2-adapter/legacy/elements/NestedElementManager.php index 9f5e05cf721..87a5f2b7c23 100644 --- a/yii2-adapter/legacy/elements/NestedElementManager.php +++ b/yii2-adapter/legacy/elements/NestedElementManager.php @@ -2,64 +2,14 @@ namespace craft\elements; -use craft\base\Event as YiiEvent; -use craft\events\BulkElementsEvent; -use craft\events\DuplicateNestedElementsEvent; -use CraftCms\Cms\Element\Events\NestedElementRevisionsCreated; -use CraftCms\Cms\Element\Events\NestedElementsDuplicated as NewDuplicateNestedElementsEvent; -use CraftCms\Cms\Element\Events\NestedElementsSaved; -use Illuminate\Support\Facades\Event; - -/** - * @deprecated 6.0.0 use {@see \CraftCms\Cms\Element\NestedElementManager} instead. - */ -class NestedElementManager extends \CraftCms\Cms\Element\NestedElementManager -{ - use \craft\base\LegacyEventConstants; - - public const EVENT_AFTER_SAVE_ELEMENTS = 'afterSaveElements'; - - public const EVENT_AFTER_DUPLICATE_NESTED_ELEMENTS = 'afterDuplicateNestedElements'; - - public const EVENT_AFTER_CREATE_REVISIONS = 'afterCreateRevisions'; - - public static function registerEvents(): void +/** @phpstan-ignore-next-line */ +if (false) { + /** + * @deprecated 6.0.0 use {@see \CraftCms\Cms\Element\NestedElementManager} instead. + */ + class NestedElementManager extends \CraftCms\Cms\Element\NestedElementManager { - Event::listen(function(NestedElementsSaved $event) { - if (!YiiEvent::hasHandlers(self::class, self::EVENT_AFTER_SAVE_ELEMENTS)) { - return; - } - - YiiEvent::trigger(self::class, self::EVENT_AFTER_SAVE_ELEMENTS, new BulkElementsEvent([ - 'elements' => $event->elements, - 'sender' => $event->manager, - ])); - }); - - Event::listen(function(NewDuplicateNestedElementsEvent $event) { - if (!YiiEvent::hasHandlers(self::class, self::EVENT_AFTER_DUPLICATE_NESTED_ELEMENTS)) { - return; - } - - YiiEvent::trigger(self::class, self::EVENT_AFTER_DUPLICATE_NESTED_ELEMENTS, new DuplicateNestedElementsEvent([ - 'source' => $event->source, - 'target' => $event->target, - 'newElementIds' => $event->newElementIds, - 'sender' => $event->manager, - ])); - }); - - Event::listen(function(NestedElementRevisionsCreated $event) { - if (!YiiEvent::hasHandlers(self::class, self::EVENT_AFTER_CREATE_REVISIONS)) { - return; - } - - YiiEvent::trigger(self::class, self::EVENT_AFTER_CREATE_REVISIONS, new DuplicateNestedElementsEvent([ - 'source' => $event->source, - 'target' => $event->target, - 'newElementIds' => $event->newElementIds, - 'sender' => $event->manager, - ])); - }); } } + +class_alias(\CraftCms\Cms\Element\NestedElementManager::class, NestedElementManager::class); diff --git a/yii2-adapter/legacy/elements/User.php b/yii2-adapter/legacy/elements/User.php index e1845c423e9..b0a321a7c50 100644 --- a/yii2-adapter/legacy/elements/User.php +++ b/yii2-adapter/legacy/elements/User.php @@ -9,109 +9,16 @@ namespace craft\elements; -use craft\base\ElementEventConstants; -use craft\base\Event as YiiEvent; -use craft\base\LegacyEventConstants; -use craft\events\AuthenticateUserEvent; -use craft\events\DefineValueEvent; -use CraftCms\Cms\Auth\Events\UserAuthenticating; -use CraftCms\Cms\Element\Validation\ElementRules; -use CraftCms\Cms\Twig\Attributes\AllowedInSandbox; use CraftCms\Cms\User\Elements\User as UserElement; -use CraftCms\Cms\User\Events\UserFriendlyNameResolving; -use CraftCms\Cms\User\Events\UserNameResolving; -use CraftCms\Cms\User\Validation\UserRules; -use Deprecated; -use Illuminate\Support\Facades\Event; - -/** - * @deprecated 6.0.0 use {@see UserElement} instead. - */ -class User extends UserElement -{ - use LegacyEventConstants; - use ElementEventConstants; - - public const string SCENARIO_DEFAULT = ElementRules::SCENARIO_DEFAULT; - - public const string SCENARIO_ESSENTIALS = ElementRules::SCENARIO_ESSENTIALS; - - public const string SCENARIO_LIVE = ElementRules::SCENARIO_LIVE; - - public const string SCENARIO_ACTIVATION = UserRules::SCENARIO_ACTIVATION; - - public const string SCENARIO_REGISTRATION = UserRules::SCENARIO_REGISTRATION; - - public const string SCENARIO_PASSWORD = UserRules::SCENARIO_PASSWORD; - - /** - * @event DefineValueEvent The event that is triggered when defining the user’s name, as returned by [[getName()]] or [[__toString()]]. - * - * @since 3.7.0 - */ - public const string EVENT_DEFINE_NAME = 'defineName'; - - /** - * @event DefineValueEvent The event that is triggered when defining the user’s friendly name, as returned by [[getFriendlyName()]]. - * - * @since 3.7.0 - */ - public const string EVENT_DEFINE_FRIENDLY_NAME = 'defineFriendlyName'; +/** @phpstan-ignore-next-line */ +if (false) { /** - * @event AuthenticateUserEvent The event that is triggered before a user is authenticated. - * - * If you wish to offload authentication logic, then set [[AuthenticateUserEvent::$performAuthentication]] to `false`, and set [[$authError]] to - * something if there is an authentication error. + * @deprecated 6.0.0 use {@see UserElement} instead. */ - public const string EVENT_BEFORE_AUTHENTICATE = 'beforeAuthenticate'; - - /** - * Returns the user’s full name. - */ - #[Deprecated(message: 'in 4.0.0. [[fullName]] should be used instead.')] - #[AllowedInSandbox] - public function getFullName(): ?string + class User extends UserElement { - return $this->fullName; - } - - public static function registerEvents(): void - { - Event::listen(function(UserNameResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_NAME)) { - $yiiEvent = new DefineValueEvent(); - $yiiEvent->sender = $event->user; - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_NAME, $yiiEvent); - - if ($yiiEvent->value !== null) { - $event->name = $yiiEvent->value; - } - } - }); - - Event::listen(function(UserFriendlyNameResolving $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_DEFINE_FRIENDLY_NAME)) { - $yiiEvent = new DefineValueEvent(); - $yiiEvent->sender = $event->user; - - YiiEvent::trigger(self::class, self::EVENT_DEFINE_FRIENDLY_NAME, $yiiEvent); - - if ($yiiEvent->value !== null) { - $event->name = $yiiEvent->value; - } - } - }); - - Event::listen(UserAuthenticating::class, function(UserAuthenticating $event) { - if (YiiEvent::hasHandlers(self::class, self::EVENT_BEFORE_AUTHENTICATE)) { - $yiiEvent = new AuthenticateUserEvent(['password' => $event->credentials['password']]); - - YiiEvent::trigger(self::class, self::EVENT_BEFORE_AUTHENTICATE, $yiiEvent); - - $event->performAuthentication = $yiiEvent->performAuthentication; - } - }); } } + +class_alias(UserElement::class, User::class); diff --git a/yii2-adapter/src/Mixins/UserMixin.php b/yii2-adapter/src/Mixins/UserMixin.php index 8cf006e3a64..f0580565420 100644 --- a/yii2-adapter/src/Mixins/UserMixin.php +++ b/yii2-adapter/src/Mixins/UserMixin.php @@ -56,4 +56,14 @@ public function handleInvalidLoginParam(): Closure app(AuthMethods::class)->handleInvalidLogin($this); }; } + + public function getFullName(): Closure + { + return function(): ?string { + Deprecator::log('User-getFullName', 'Calling ->getFullName on a User is deprecated. Use $user->fullName instead.'); + + /** @phpstan-ignore-next-line */ + return $this->fullName; + }; + } } diff --git a/yii2-adapter/tests-laravel/Behavior/LegacyBehaviorCompatibilityTest.php b/yii2-adapter/tests-laravel/Behavior/LegacyBehaviorCompatibilityTest.php index 2ab146af00b..eb7ca2148d4 100644 --- a/yii2-adapter/tests-laravel/Behavior/LegacyBehaviorCompatibilityTest.php +++ b/yii2-adapter/tests-laravel/Behavior/LegacyBehaviorCompatibilityTest.php @@ -87,23 +87,21 @@ public function updateOwnerDescription(string $description): void ->toBe([]); }); -test('discovered legacy behavior targets are real wrappers rather than class aliases', function() { - $unexpectedAliasTargets = collect(LegacyBehaviorCatalog::discoveredTargets()) +test('discovered class alias behavior targets resolve to their migrated classes', function() { + $aliasTargets = collect(LegacyBehaviorCatalog::discoveredTargets()) ->filter(function(array $target) { $contents = (string) file_get_contents($target['path']); - if (!str_contains($contents, 'class_alias(')) { - return false; - } - - return !str_contains($target['path'], '/legacy/elements/actions/') - && !str_contains($target['path'], '/legacy/elements/exporters/'); + return str_contains($contents, 'class_alias('); }) - ->pluck('legacyClass') - ->values() - ->all(); + ->values(); - expect($unexpectedAliasTargets)->toBe([]); + expect($aliasTargets)->not->toBeEmpty(); + + $aliasTargets->each(function(array $target) { + expect((new ReflectionClass($target['legacyClass']))->getName()) + ->toBe($target['targetClass']); + }); }); test('component-backed classes inherit behaviors from base model, base component, and concrete legacy classes', function() {