nette / di

💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 8 features.
https://doc.nette.org/dependency-injection
Other
869 stars 70 forks source link

SearchExtension: compatible with trait Nette\StaticClass #292

Closed h4kuna closed 1 year ago

h4kuna commented 1 year ago

Hello if I use trait Nette\StaticClass the extension Search automatically register the class like a service to container.

There are two ways: 1) in trait Nette\StaticClass change visibility of constructor from final public to private. The ReflectionClass::isInstantiable will work fine. I prefer

2) add exception for this trait to Search extension

I know if you have registered static classes, it doesn't matter, because these classes are not in constructors, but this is no reason to register in container.

Example of bad behavior:

namespace Uget;

use Nette\StaticClass;

final class Tools
{
    use StaticClass;
}

In Container i see

    public function createService017(): Uget\Tools
    {
        return new Uget\Tools; // throw exception
    }

I must add to ignore

search:
    exclude:
        classes:
            - Uget\Tools
dg commented 1 year ago

Yes, it's better to use a private constructor.