Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Mark deprecated functionality #429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"zendframework/zend-diactoros": "^1.1",
"zendframework/zend-expressive-router": "^1.1",
"zendframework/zend-expressive-template": "^1.0.1",
"zendframework/zend-stratigility": ">=1.1.0 < 1.3.0 || >=1.3.1 <2.0.0"
"zendframework/zend-stratigility": "^1.3.3"
},
"require-dev": {
"filp/whoops": "^1.1 || ^2.0",
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ public function pipe($path, $middleware = null)
* Once middleware detection and wrapping (if necessary) is complete,
* proxies to pipe().
*
* @deprecated since 1.1.0; to remove in 2.0.0. Stratigility v1-style
* "error middleware" (middleware with four arguments, the first of which
* being an error) was deprecated in Stratigility 1.3, and support
* removed in Stratigility 2.0. You can start using standard middleware
* for error handling by calling `raiseThrowables()` on the `Application`
* instance, and piping such middleware in an outer layer of your application.
* For an example, see `Zend\Stratigility\Middleware\ErrorHandler`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{@see Zend\Stratigility\Middleware\ErrorHandler} ?

* @param string|callable $path Either a URI path prefix, or middleware.
* @param null|string|callable $middleware Middleware
* @return self
Expand Down Expand Up @@ -410,6 +417,11 @@ public function pipeRouteResultObserverMiddleware()
* Allow header, and `$next()` is called with its `$error` argument set
* to the value `405` (invoking the next error middleware).
*
* @deprecated since 1.1.0; to remove in 2.0.0. This method is extracted to
* its own dedicated middleware class starting in 2.0.0. If you are
* manually piping this method into your application or middleware
* pipelines, or overriding the method, you will need to update your
* code when migrating to 2.0.
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
Expand Down Expand Up @@ -453,6 +465,11 @@ public function routeMiddleware(ServerRequestInterface $request, ResponseInterfa
* Finally, it attempts to marshal the middleware, and dispatches it when
* complete, return the response.
*
* @deprecated since 1.1.0; to remove in 2.0.0. This method is extracted to
* its own dedicated middleware class starting in 2.0.0. If you are
* manually piping this method into your application or middleware
* pipelines, or overriding the method, you will need to update your
* code when migrating to 2.0.
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
Expand Down Expand Up @@ -598,6 +615,9 @@ public function getContainer()
/**
* Return the final handler to use during `run()` if the stack is exhausted.
*
* @deprecated since 1.1.0; renamed to `getDefaultDelegate()` in version
* 2.0.0. If you are consuming this method, please update your code to call
* getDefaultDelegate() instead.
* @param null|ResponseInterface $response Response instance with which to seed the
* FinalHandler; used to determine if the response passed to the handler
* represents the original or final response state.
Expand All @@ -618,6 +638,20 @@ public function getFinalHandler(ResponseInterface $response = null)
return $this->finalHandler;
}

/**
* Return the default delegate to use during `run()` when the stack is exhausted.
*
* Provided as a forwards compatibility measure with version 2, and proxies
* to getFinalHandler(); please note that it does not accept any arguments,
* nor pass them on to that method.
*
* @return callable|null
*/
public function getDefaultDelegate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to expose a getter for final handler after all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used internally to lazy-load it when required and none was injected during instantiation, which makes it a canonical source for locating it if the service is not defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but it does not need to be public, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it becomes the canonical source for the service if no service is registered in the container. As such, if you need access to it for any reason (e.g., to re-use it elsewhere), it would need to be public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhmm, sorry but it's not clear to me why would someone want to re-use it outside of Application context. Any example? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure: you could be nesting an application within another, and want to re-use the default delegate from the parent application. As such, you might build the factory like this:

use Zend\Expressive\AppFactory;
use Zend\Expressive\Application;
use Zend\Expressive\Router\FastRouteRouter;

function ($container)
{
    $app = $container->get(Application::class);
    $nested = new Application(
        new FastRouteRouter(),
        $container,
        $app->getDefaultDelegate()
    );
    
    /* pipe and/or route some middleware */
    $nested->pipe(/* ... */);
    $nested->get('/subpath', /* ... */);
    
    return $nested;
}

In normal circumstances, if this were dispatched, if a call to $next()/$delegate->process() occurs but the pipeline is exhausted, this would return handling to the parent, which might lead to execution later down the stack. By passing the default delegate in, we ensure that this nested application then becomes terminal; once it is dispatched, it must return a response, ensuring no deeper layers are executed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haa, thanks for clarifying! These fallback services would be a lot easier if Expressive could provide its default container config that people could override, but unfortunately it would not work with all container interop implementations. 😕

{
return $this->getFinalHandler();
}

/**
* Retrieve an emitter to use during run().
*
Expand Down
6 changes: 6 additions & 0 deletions src/Container/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

use Interop\Container\Exception\ContainerException;

/**
* @deprecated since 1.1.0; to remove in 2.0.0. This exception is currently
* thrown by `Zend\Expressive\Container\ApplicationFactory`; starting
* in 2.0.0, that factory will instead throw
* `Zend\Expressive\Exception\InvalidArgumentException`.
*/
class InvalidArgumentException extends \InvalidArgumentException implements
ContainerException,
ExceptionInterface
Expand Down
3 changes: 3 additions & 0 deletions src/Container/Exception/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

/**
* Exception indicating a service was not found in the container.
*
* @deprecated since 1.1.0; to remove in 2.0.0. This exception is not thrown
* by any classes within Expressive at this time.
*/
class NotFoundException extends RuntimeException implements
ExceptionInterface,
Expand Down
7 changes: 7 additions & 0 deletions src/Container/TemplatedErrorHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
* </code>
*
* If any of the keys are missing, default values will be used.
*
* @deprecated since 1.1.0, to be removed in 2.0.0. The "final handler" concept
* will be replaced with a "default delegate", which will be an
* implementation of Interop\Http\ServerMiddleware\DelegateInterface that
* returns a canned response. Expressive will provide tools to migrate your
* code to use default delegates for 2.0; you will only need to manually
* change your code if you are extending this class.
*/
class TemplatedErrorHandlerFactory
{
Expand Down
7 changes: 7 additions & 0 deletions src/Container/WhoopsErrorHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
* </code>
*
* All values are booleans; omission of any implies boolean false.
*
* @deprecated since 1.1.0, to be removed in 2.0.0. The "final handler" concept
* will be replaced with a "default delegate", which will be an
* implementation of Interop\Http\ServerMiddleware\DelegateInterface that
* returns a canned response. Expressive will provide tools to migrate your
* code to use default delegates for 2.0; you will only need to manually
* change your code if you are extending this class.
*/
class WhoopsErrorHandlerFactory
{
Expand Down
8 changes: 8 additions & 0 deletions src/ErrorMiddlewarePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
* It is not implemented as an extension of MiddlewarePipe, as that class
* implements the MiddlewareInterface, which prevents its use as error
* middleware.
*
* @deprecated since 1.1.0; to remove in 2.0.0. Stratigility 1.3 deprecates the
* concept of "error middleware" (middleware accepting exactly four arguments
* the first of which being an error) in favor of using standard middleware
* for error handling; you can use `Zend\Stratigility\ErrorHandler` either
* directly or as an example of how to implement such middleware. If you are
* using Stratigility 1.3, you can enable such error handling by calling
* `raiseThrowables()` on your `Application` instance.
*/
class ErrorMiddlewarePipe
{
Expand Down
7 changes: 7 additions & 0 deletions src/TemplatedErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
* Provides the optional ability to render a template for each of 404 and
* general error conditions. If no template renderer is provided, returns
* empty responses with appropriate status codes.
*
* @deprecated since 1.1.0, to be removed in 2.0.0. The "final handler" concept
* will be replaced with a "default delegate", which will be an
* implementation of Interop\Http\ServerMiddleware\DelegateInterface that
* returns a canned response. Expressive will provide tools to migrate your
* code to use default delegates for 2.0; you will only need to manually
* change your code if you are extending this class.
*/
class TemplatedErrorHandler
{
Expand Down
6 changes: 6 additions & 0 deletions src/WhoopsErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* interface for navigating an exception stack trace.
*
* @see http://filp.github.io/whoops/
* @deprecated since 1.1.0, to be removed in 2.0.0. The "final handler" concept
* will be replaced with a "default delegate", which will be an
* implementation of Interop\Http\ServerMiddleware\DelegateInterface that
* returns a canned response. Expressive will provide tools to migrate your
* code to use default delegates for 2.0; you will only need to manually
* change your code if you are extending this class.
*/
class WhoopsErrorHandler extends TemplatedErrorHandler
{
Expand Down