Mezzio: Getting Started
Total Page:16
File Type:pdf, Size:1020Kb
Mezzio: Getting Started CREATE A MEZZIO APPLICATION BY HAND Matthew Setter SOFTWARE ENGINEER, LINUX SYSTEMS ADMINISTRATOR @settermjd www.matthewsetter.com Summary Build an application by hand A simple movie database Use no command-line tooling support Not full-featured Iteration One Build in a series of iterations A router A small bootstrap file A dependency injection container Iteration Two Make the default route’s handler more reusable and maintainable Iteration Three Register the route’s handler with the DI container Iteration Four Make the app configuration-driven Iteration Five Extract the routes Iteration Six Make the application more resilient We created a basic application Iteration One We created the essential config files In Review It could be difficult to maintain A more sophisticated body? What About… Reusing the body in different routes? A more sophisticated response? Coming Up Next Register the default route’s handler as a DI service Iteration Two We made the default route’s handler In Review reusable A minimalist application What We Have Refactored to be flexible and reusable Achieved Less labor-intensive Configuration-driven Mezzio is flexible and minimalist What We Middleware’s not too complicated Have Learned It’s just another class Delegation Pattern The delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance. In delegation, an object handles a request by delegating to a second object (the delegate). The delegate is a helper object, but with the original context. Delegator Factories Mezzio supports the concept of delegator factories, which allow decoration of services created by your dependency injection container, across all dependency injection containers supported by Mezzio. Delegator Factories A delegator factory is pretty much a wrapper around a real factory. In essence, it allows us to either replace the actual service with a "delegate" or interact with an object produced by a factory before the laminas- servicemanager returns it. Summary We’ve defined the routes in our module Coming Up Next Make our app more resilient Summary We’ve manually created an application It started out quite simplistic We refactored it to be more flexible, reusable, and maintainable We used available middleware to make it more robust Learned how a Mezzio application is Summary composed Mezzio starts off slim and lightweight Mezzio can be iteratively grown and extended Manual construction can be a lot of work Coming Up Next Start using the Mezzio Skeleton Installer Re-create the application Learn the benefits which it provides.