WebDevStudios / oops-wp

A collection of abstract classes, interfaces, and traits to promote object-oriented programming practices in WordPress.
57 stars 9 forks source link

Store services somewhere #11

Closed aubreypwd closed 5 years ago

aubreypwd commented 5 years ago

Currently we store the service in a anonymous variable $service and then that service can't be accessed again, e.g. to re-run a method, etc.

Would like to see this stored somewhere (e.g. a collection) so that we can get back to them or access them again if need be?

aubreypwd commented 5 years ago

A do_action( 'oops_wp_service_created', $service ); might work. This could alleviate the need to store all of them in variables/big list. You want it, hook into it and do things with it?

jmichaelward commented 5 years ago

@aubreypwd I opened a PR in #13. Note that I don't agree with the hook approach as hooks obfuscate what's happening in the initialization process and I want to promote SOLID principles as part of this library. That said, the value of service objects gets cached back to the protected property after they're initialized, so plugin authors can use that value however they wish after the run method is called.