zfcampus / zf-apigility-doctrine

Doctrine-enabled services for Apigility
BSD 3-Clause "New" or "Revised" License
107 stars 50 forks source link

How to add dependency inside resource? #302

Closed brndusic closed 6 years ago

brndusic commented 6 years ago

How can we add a dependency to a resource? Can someone explain how can we use a custom service inside a resource because we do not have access to ServiceManager anymore.

What I want to accomplish is for example to totally override one method inside a resource as others remain untouched.

snapshotpl commented 6 years ago

Use constructor injection

TomHAnderson commented 6 years ago

I strongly recommend you do not modify the resources. You probably just need a query provider instead.

TomHAnderson commented 6 years ago

@brndusic For every method in DoctrineResource there is an event you can subscribe to which will allow you to stop the method and return an ApiProblem.

https://github.com/zfcampus/zf-apigility-doctrine/blob/master/src/Server/Resource/DoctrineResource.php#L574

If you're trying to do more than what an event before and after the hydrator is used on the target resource then that means you're not actually targeting a resource. Maybe a RPC is what you need?

michalbundyra commented 6 years ago

@brndusic Did you resolve your issue? You've got two good suggestions, please reopen the issue if you have any further questions.