-
Notifications
You must be signed in to change notification settings - Fork 45
Subclasses for aliased classes #105
Comments
Another (probably better) way would be to use class_alias. A new file somewhere which is included as soon as possible (probably in the bootstrap file or the service provider) which either calls File would be something like this then: <?php
$aliasedClasses = [
'DaveJamesMiller\Breadcrumbs\Manager' => 'DaveJamesMiller\Breadcrumbs\Breadcrumbs',
// More aliases go here
];
foreach ($aliasedClasses as $original => $alias) {
class_alias($original, $alias);
} We could also put the array in a (new) config file and only keep the foreach in that file. |
I think this is the only class that needs to be subclassed and that's because we don't own it ourselves. Personally I think subclassing is a lot less work and overhead than setting up class aliases in the way you describe. |
It's a one liner if we add it to the service provider. Also laravel has a lot of classes named Repository (season, config, ...) or Manager which are already aliased in some places and should be aliased on others too. |
I still don't think How is my IDE or editor going to know about the alias? If I see a My vote is -1 for |
I agree, I dislike using alias as it makes things much less understandable at first glance.
|
So we're going with subclasses here? Any preferred way where they should be saved and in which namespace? |
Yeah, subclasses would be my preference.
|
Something else I've noticed: There's a facade |
Yeah, they should be.
|
Ok, apparently I've been inactive for way too long. The Facade is used in the base view to call |
Service providers are loaded in the order they're defined in the config, so double check the breadcrumbs service provider is above the twig one. I'll have a look over the weekend, we can talk through it and possible approaches then. |
As @wpillar suggested here: #99 (comment) we should create sub classes for classes we usually alias (like
Manager
orRepository
)DaveJamesMiller\Breadcrumbs\Manager
should be subclassed toBreadcrumbs
and stored in a sensible namespace.The text was updated successfully, but these errors were encountered: