zend-expressive 3.0.0alpha2
Added
-
#543 adds support for the final PSR-15 interfaces, and explicitly depends on psr/http-server-middleware.
-
#543 adds a new class,
Zend\Expressive\MiddlewareContainer. The class decorates a PSR-11ContainerInterface, and adds the following behavior:- If a class is not in the container, but exists,
has()will returntrue. - If a class is not in the container, but exists,
get()will attempt to instantiate it, caching the instance locally if it is valid. - Any instance pulled from the container or directly instantiated is tested. If it is a PSR-15
RequestHandlerInterface, it will decorate it in a zend-stratigilityRequestHandlerMiddlewareinstance. If the instance is not a PSR-15MiddlewareInterface, the container will raise aZend\Expressive\Exception\InvalidMiddlewareException.
- If a class is not in the container, but exists,
-
#543 adds a new class,
Zend\Expressive\MiddlewareFactory. The class composes aMiddlewareContainer, and exposes the following methods:callable(callable $middleware) : CallableMiddlewareDecoratorhandler(RequestHandlerInterface $handler) : RequestHandlerMiddlewarelazy(string $service) : LazyLoadingMiddlewareprepare($middleware) : MiddlewareInterface: accepts a string service name, callable,RequestHandlerInterface,MiddlewareInterface, or array of such values, and returns aMiddlewareInterface, raising an exception if it cannot determine what to do.pipeline(...$middleware) : MiddlewarePipe: passes each argument toprepare(), and the result toMiddlewarePipe::pipe(), returning the pipeline when complete.
-
#543 adds the following factory classes, each within the
Zend\Expressive\Containernamespace:ApplicationPipelineFactory: creates and returns aZend\Stratigility\MiddlewarePipeto use as the application middleware pipeline.DispatchMiddlewareFactory: creates and returns aZend\Expressive\Router\DispatchMiddlewareinstance.EmitterFactory: creates and returns aZend\HttpHandlerRunner\Emitter\EmitterStackinstance composing anSapiEmitterfrom that same namespace as the only emitter on the stack. This is used as a dependency for theZend\HttpHandlerRunner\RequestHandlerRunnerservice.MiddlewareContainerFactory: creates and returns aZend\Expressive\MiddlewareContainerinstance decorating the PSR-11 container passed to the factory.MiddlewareFactoryFactory: creates and returns aZend\Expressive\MiddlewareFactoryinstance decorating aMiddlewareContainerinstance as pulled from the container.RequestHandlerRunnerFactory: creates and returns aZend\HttpHandlerRunner\RequestHandlerRunnerinstance, using the servicesZend\Expressive\Application,Zend\HttpHandlerRunner\Emitter\EmitterInterface,Zend\Expressive\ServerRequestFactory, andZend\Expressive\ServerRequestErrorResponseGenerator.RouteMiddlewareFactory: creates and returns aZend\Expressive\Router\PathBasedRoutingMiddlewareinstance.ServerRequestFactoryFactory: creates and returns acallablefactory for generating a PSR-7ServerRequestInterfaceinstance; this returned factory is a dependency for theZend\HttpHandlerRunner\RequestHandlerRunnerservice.ServerRequestErrorResponseGeneratorFactory: creates and returns acallablethat accepts a PHPThrowablein order to generate a PSR-7ResponseInterfaceinstance; this returned factory is a dependency for theZend\HttpHandlerRunner\RequestHandlerRunnerservice, which uses it to generate a response in the scenario that theServerRequestFactoryis unable to create a request instance.
-
#543 adds the class
Zend\Expressive\Container\ApplicationConfigInjectionDelegator. This class may be used either as a delegator factory on theZend\Expressive\Applicationinstance, or you may use the two static methods it defines to inject pipeline middleware and/or routes from configuration:injectPipelineFromConfig(Application $application, array $config) : voidinjectRoutesFromConfig(Application $application, array $config) : void
These methods work the same way as the associated
Applicationmethods from version 2, accepting the same configuration. -
#543 adds
Zend\Expressive\ConfigProvider, which details the default service mappings.
Changed
-
#543 adds dependencies on each of:
- zend-stratigility 3.0.0alpha3
- zend-expressive-router 3.0.0alpha1
- zend-httphandlerrunner 1.0.0
and removes the dependency http-interop/http-server-middleware.
-
#543 renames
Zend\Expressive\Middleware\NotFoundHandlertoZend\Expressive\Middleware\NotFoundMiddleware, and its accompanying factoryZend\Expressive\Container\NotFoundHandlerFactorytoZend\Expressive\Container\NotFoundMiddlewareFactory. -
#543 renames
Zend\Expressive\Delegate\NotFoundDelegatetoZend\Expressive\Handler\NotFoundHandler, updating it to implement the PSR-15RequestHandlerInterface. It also renames the factoryZend\Expressive\Container\NotFoundDelegateFactorytoZend\Expressive\Container\NotFoundHandlerFactory. -
#543 refactors
Zend\Expressive\Applicationcompletely.The class no longer extends
Zend\Stratigility\MiddlewarePipe, and instead implements the PSR-15MiddlewareInterfaceandRequestHandlerInterface.It now requires the following dependencies via constructor injection, in the following order:
Zend\Expressive\MiddlewareFactoryZend\Stratigility\MiddlewarePipe; this is the pipeline representing the application.Zend\Expressive\Router\PathBasedRoutingMiddlewareZend\HttpHandlerRunner\RequestHandlerRunner
It removes all "getter" methods (as detailed in the "Removed" section of this release), but retains the following methods, with the changes described below. Please note: in most cases, these methods accept the same arguments as in the version 2 series, with the exception of callable double-pass middleware (these may be decorated manually using
Zend\Stratigility\doublePassMiddleware()), and http-interop middleware (no longer supported; rewrite as PSR-15 middleware).-
pipe($middlewareOrPath, $middleware = null) : voidpasses its arguments to the composedMiddlewareFactory'sprepare()method; if two arguments are provided, the second is passed to the factory, and the two together are passed toZend\Stratigility\path()in order to decorate them to work as middleware. The prepared middleware is then piped to the composedMiddlewarePipeinstance.As a result of switching to use the
MiddlewareFactoryto prepare middleware, you may now pipeRequestHandlerInterfaceinstances as well. -
route(string $path, $middleware, array $methods = null, string $name) : Routepasses its$middlewareargument to theMiddlewareFactory::prepare()method, and then all arguments to the composedPathBasedRoutingMiddlewareinstance'sroute()method.As a result of switching to use the
MiddlewareFactoryto prepare middleware, you may now route toRequestHandlerInterfaceinstances as well. -
Each of
get,post,patch,put,delete, andanynow proxy toroute()after marshaling the correct$methods. -
getRoutes() : Route[]proxies to the composedPathBasedRoutingMiddlewareinstance. -
handle(ServerRequestInterface $request) : ResponseInterfaceproxies to the composedMiddlewarePipeinstance'shandle()method. -
process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterfaceproxies to the composedMiddlewarePipeinstance'sprocess()method. -
run() : voidproxies to the composedRequestHandlerRunnerinstance. Please note that the method no longer accepts any arguments.
-
#543 modifies the
Zend\Expressive\Container\ApplicationFactoryto reflect the changes to theZend\Expressive\Applicationclass as detailed above. It pulls the following services to inject via the constructor:Zend\Expressive\MiddlewareFactoryZend\Stratigility\ApplicationPipeline, which should resolve to aMiddlewarePipeinstance; use theZend\Expressive\Container\ApplicationPipelineFactory.Zend\Expressive\Router\PathBasedRoutingMiddlewareZend\HttpHandlerRunner\RequestHandlerRunner
Deprecated
- Nothing.
Removed
-
#543 removes support for http-interop/http-server-middleware.
-
#543 removes the class
Zend\Expressive\Middleware\RouteMiddleware. Use thePathBasedRoutingMiddlewareorRouteMiddlewarefrom zend-expressive-router instead; the factoryZend\Expressive\Container\RouteMiddlewareFactorywill return aPathBasedRoutingMiddlewareinstance for you. -
#543 removes the class
Zend\Expressive\Middleware\DispatchMiddleware. Use theDispatchMiddlewarefrom zend-expressive-router instead; the factoryZend\Expressive\Container\DispatchMiddlewareFactorywill return an instance for you. -
#543 removes the class
Zend\Expressive\Emitter\EmitterStack; use the classZend\HttpHandlerRunner\Emitter\EmitterStackinstead. -
#543 removes the following methods from
Zend\Expressive\Application:pipeRoutingMiddleware(): usepipe(\Zend\Expressive\Router\PathBasedRoutingMiddleware::class)instead.pipeDispatchMiddleware(): usepipe(\Zend\Expressive\Router\DispatchMiddleware::class)instead.getContainer()getDefaultDelegate(): ensure you pipe middleware capable of returning a response at the innermost layer; this can be done by decorating a request handler usingZend\Stratigility\Middleware\RequestHandlerMiddleware, usingZend\Expressive\Middleware\NotFoundMiddleware, or other approaches.getEmitter(): use theZend\HttpHandlerRunner\Emitter\EmitterInterfaceservice from the container.injectPipelineFromConfig(): use the newApplicationConfigInjectionDelegatorand/or the static method of the same name it defines.injectRoutesFromConfig(): use the newApplicationConfigInjectionDelegatorand/or the static method of the same name it defines.
-
#543 removes the class
Zend\Expressive\AppFactory.
Fixed
- Nothing.