DaveLiddament / php-language-extensions

Attributes to define new PHP language features (that are enforced by static analysis)
MIT License
135 stars 5 forks source link

Add #[RestrictTraitTo] #32

Closed DaveLiddament closed 3 months ago

DaveLiddament commented 3 months ago

This limits the use of a Trait to only be used by a specified class of a child of that class.

E.g. this trait is limited to classes that are or extend Controller

#[RestrictTraitTo(Controller::class)]
trait ControllerHelpers {}

This would be allowed:

class LoginController extends Controller {
    use ControllerHelpers;
}

But this would NOT be allowed:

class Repository {
    use ControllerHelpers;
}
DaveLiddament commented 3 months ago

Actioned #33