Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Trying to get a factory/service inside resource #184

Open
lucasmonstrox opened this issue Dec 27, 2016 · 9 comments
Open

Trying to get a factory/service inside resource #184

lucasmonstrox opened this issue Dec 27, 2016 · 9 comments

Comments

@lucasmonstrox
Copy link

Tell me one thing if you can help me:

How can I get a Factory/Service inside a resource?

@michalbundyra
Copy link
Member

REST resource is created via container (service manager, if it is there defined) or directly:
https://github.com/zfcampus/zf-rest/blob/master/src/Factory/RestControllerFactory.php#L117-L121
If you want inject something intro REST resource you can define your own factory for the resource and inject whatever you want.

@lucasmonstrox
Copy link
Author

Yes, but my ResourceFactory is not called or if I put a "exit" inside file, the php continues.

:'( I cloned apigility default project.

@lucasmonstrox
Copy link
Author

I just cloned the project, I created the service in apigility admin but ResourceFactory is never called or used.

@michalbundyra
Copy link
Member

Did you add to your configuration:

'service_manager' => [
     'factories' => [
        YourApi\V1\Rest\YourService\Resource::class => YourResourceFactory::class,
    ],
],

?

You can use also abstract factory if you want, or the same factory for multiple resources.

@lucasmonstrox
Copy link
Author

No I didn't. But I need to include this config inside module config or in global config?

@lucasmonstrox
Copy link
Author

Yeah Nice, it works like a charm. Big thanks dude <3

@michalbundyra
Copy link
Member

michalbundyra commented Dec 27, 2016

But I need to include this config inside module config or in global config?

Doesn't matter. If this is just for one module it should be in module.config.php. If this is a global configuration for your application (applied for multiple modules) than it can be in global config.

@lucasmonstrox
Copy link
Author

You can close this issue and a lot of people are searching for this in "google" or "stackoverflow".

Big thanks and HNY ;)

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools; a new issue has been opened at laminas-api-tools/api-tools#10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants