I did implement a Catalyst authentication application (captchas, password reminders, access logs, etc...).
How am I supposed to re-use it in different Catalyst applications? I.e.:
Or - more generally - how am I supposed to let two applications talk each other?
You're basically asking : I have build two airplanes, how do I let them talk to each other?
Maybe see Catalyst::Plugin::Authentication (and module that use it) and make one yourself,
or something else entirely, like a radio
You can abstract common components in your local catalystX namespace and extend your controllers and models from that namespace .
Related
How can I manipulate other modules without editing them ? very the same thing that wordpress modules do .
They add functionality to core system without changing the core code and they work together like a charm.
I always wanted to know how to implement this in my own modular application
A long time ago I wrote the blog post "Use 3rd party modules in Zend Framework 2" specifically about extending Zend Framework 2 modules. The answer from Bez is technically correct, it could be a bit more specific about the framework.
Read the full post at https://juriansluiman.nl/article/117/use-3rd-party-modules-in-zend-framework-2, but it gives you a clue about:
Changing a route from a module (say, you want to have the url /account/login instead of /user/login)
Overriding a view script, so you can completely modify the page's rendering
Changing a form object, so you could add new form fields or mark some required field as not required anymore.
This is a long topic, but here is a short gist.
Extensibility in Zend Framework 2 heavily relies on the premise that components can be interchanged, added, and/or substituted.
Read up on SOLID principles: http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
Modules typically consists of objects working together as a well-oiled machinery, designed to accomplish one thing or a bunch of related things, whatever that may be. These objects are called services, and managed by the service locator/service manager.
A big part of making your module truly extensible is to expect your developers to extend a class or implement a certain interface, which the developer register as services. You should provide a mode of definition wherein the developers can specify which things he wants to substitute, and/or add their own services to -- and this is where the application configuration comes in.
Given the application configuration, you should construct your machinery a.k.a. module services according to options the developer has specified i.e., use the developer defined Foo\Bar\UserService service as the YourModule\UserServiceInterface within your module, etc. (This is usually delegated to service factories, which has the opportunity to read the application configuration, and constructs the appropriate object given a particular set of configuration values.)
EDIT:
To add, a lot can be accomplished by leveraging Zend's Zend\EventManager component. This allows you to give developers the freedom to hook and listen to certain operations of your module and act accordingly (See: http://en.wikipedia.org/wiki/Observer_pattern)
i need one function which i use in views, hydrator, some controllers and so on...
Where i can put it?
Where it would be the best add that can be maintained PHP OOP and zend 2 architecture?
Thanks
It sounds like you should be looking at the Zend\ServiceManager. You can register factories (functions) and services in the service manager, and technically access them from anywhere in your application. Your class would need to implement the ServiceLocatorAwareInterface in order to access the service manager, OR you would pass/inject the service into your class/model/hydrator/etc.
I'm maintaining a large application that makes heavy use of StructureMap to load it's components. I'm trying to split the components up so they can run on different machines, connected via network. They already run in different threads, but within the same process (making use of a single StructureMap container).
I'm not sure how to do this. Is it possible to have StructureMap automatically create a proxy for all components and use them over network instead of locally? What changes to the components are needed to make them distributable?
Interesting! Theoretically I guess it is possible, the real underlying question is if you really want to do so, we are talking about a major architectural change.
Disclaimer: I don't know how familiar you are with WCF, I'll attempt to explain very roughly how I imagine it being possible, but consider that if we are talking about this sort of communication over a network you want to use WCF.
Define every interface for the components that you want to use over a network as a WCF service contract
Wrap your components with services and host them somewhere/somehow
Write clients for these services, having them implement your components interfaces
Let StructureMap inject your clients when the code expects a component
While it sounds quite straightforward, a relevant complexity is hiding behind these steps. To name a few potential issues off the top of my head: which components are you going to wrap into services? How easy is wrapping them going to be? Where are you going to host them, how? What about security? Does your logging mechanism need to be adjusted?
I have several classes that exist persistently throughout application lifetime and can contain any code a programmer might need to run (stuff like for example that is executed when a user resizes the app window). These classes are basically empty templates and aren't for a single task (uh oh, sounds like bad OOP, but please stay with me here). There are several of these classes in my framework and which one is integrated into the rest of the framework depends on the build target (web, desktop, mobile, etc). Currently these classes are named:
AppModule
AppDesktopModule
AppAndroidModule
etc.
But I'm not happy with this naming. I'd like to give them a name that somehow clarifies that these classes are persistent throughout app lifetime. Does anyone have ideas for a better naming?
Do you have it as a separate Module, or just one separate Controller, or multiple Controllers without any logical separation from Frontend (except for Auth ofcourse), or something else?
Assuming that backend is reasonably complicated, i.e. something more than review/confirm/delete comments for your BLOG.
Definatly belongs in a new module then it is easy to create a separate layout in my opinion.
In a recent project a colleague created a separate admin controller in each module with the layout defined in an admin module. This way he could drop in/remove modules from the project with the main admin module autodetecting which modules are installed and creating menus based on the admin controller found in each pluggable module.
I have explained that poorly, but it's a good system.
I would create a separate module. Otherwise you might run into context issues because the ArticleController in the frontend should have other/limited functionalities then the administrative ArticleController and you end up implementing mixed controller classes (bad idea!) or prefix the administrative class.
So having multiple modules makes it easier to separate different concerns.
(Plus it will make it easier for you to implement an ACL and handle the corresponding resource/role definitions.)