Download the PHP package asgrim/mini-mezzio without Composer
On this page you can find all versions of the php package asgrim/mini-mezzio. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download asgrim/mini-mezzio
More information about asgrim/mini-mezzio
Files in asgrim/mini-mezzio
Package mini-mezzio
Short Description Minimal Application Factory for Mezzio
License MIT
Informations about the package mini-mezzio
Mini Mezzio
Make setting up a Mezzio application even quicker by using this package. This makes an assumption that you are happy to use:
laminas/diactoros
for the application's PSR-7 server request implementation- You do not need to use the
SapiStreamEmitter
- Your
ServerRequest
comes from$_SERVER
All you need to provide is:
- A container instance implementing
ContainerInterface
, for example laminas-servicemanager - A router instance implementing
RouterInterface
, for example FastRoute
You would then pipe the RouteMiddleware
, DispatchMiddleware
, and any other
middleware or request handlers that your application needs.
Basic Usage: Example Application using Mini Mezzio
First you must require Mini Mezzio, a container, and a router with Composer. In this example, we'll use Laminas ServiceManager and FastRoute.
Then in public/index.php
we can create our application:
You can use the PHP built-in web server to check this works. Spin this up with:
Now if you visit http://localhost:8080/hello-world in your browser, you should see the text
Hello world!
displayed. Now you're ready to make middleware in minutes!
Use the container for pipeline and endpoints
It probably won't be long before you'll want to leverage the container to use
dependency injection for your middleware handlers instead of putting them all
in the public/index.php
. Since Mezzio already can pull middleware from the
container it is given, you can put your handler in a proper class:
You can update your public/index.php
to pull things from the container:
We've updated several things here, using the power of Laminas Service Manager:
- Added the
ReflectionBasedAbstractFactory
- this allows DI autowiring based on reflection. This can autowire most things - Added a factory for
\Mezzio\Router\RouterInterface
which returns the instance ofMezzio\Router\FastRouteRouter
. TheRouteMiddleware
can then be autowired using theReflectionBasedAbstractFactory
RouteMiddleware
andDispatchMiddleware
are now referred to with just::class
rather than creating instances; since they're just strings, they are looked up in the container.- The route
GET /hello-world
is mapped to\MyApp\Handler\HelloWorldHandler
that we created above; again, since this is a string, the instance is fetched from the container.
All versions of mini-mezzio with dependencies
laminas/laminas-diactoros Version ^3.1
laminas/laminas-httphandlerrunner Version ^2.7
laminas/laminas-stratigility Version ^3.10
mezzio/mezzio Version ^3.17
mezzio/mezzio-router Version ^3.16
psr/container Version ^2.0