| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package WPEmerge |
| 4 |
* @author Atanas Angelov <hi@atanas.dev> |
| 5 |
* @copyright 2017-2019 Atanas Angelov |
| 6 |
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
| 7 |
* @link https://wpemerge.com/ |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace WPEmerge\Responses; |
| 11 |
|
| 12 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 13 |
|
| 14 |
/** |
| 15 |
* Provide responses dependencies. |
| 16 |
* |
| 17 |
* @codeCoverageIgnore |
| 18 |
*/ |
| 19 |
class ResponsesServiceProvider implements ServiceProviderInterface { |
| 20 |
/** |
| 21 |
* {@inheritDoc} |
| 22 |
*/ |
| 23 |
public function register( $container ) { |
| 24 |
$container[ WPEMERGE_RESPONSE_SERVICE_KEY ] = function ( $c ) { |
| 25 |
return new ResponseService( $c[ WPEMERGE_REQUEST_KEY ], $c[ WPEMERGE_VIEW_SERVICE_KEY ] ); |
| 26 |
}; |
| 27 |
|
| 28 |
$app = $container[ WPEMERGE_APPLICATION_KEY ]; |
| 29 |
$app->alias( 'responses', WPEMERGE_RESPONSE_SERVICE_KEY ); |
| 30 |
|
| 31 |
$app->alias( 'response', function () use ( $app ) { |
| 32 |
return call_user_func_array( [$app->responses(), 'response'], func_get_args() ); |
| 33 |
} ); |
| 34 |
|
| 35 |
$app->alias( 'output', function () use ( $app ) { |
| 36 |
return call_user_func_array( [$app->responses(), 'output'], func_get_args() ); |
| 37 |
} ); |
| 38 |
|
| 39 |
$app->alias( 'json', function () use ( $app ) { |
| 40 |
return call_user_func_array( [$app->responses(), 'json'], func_get_args() ); |
| 41 |
} ); |
| 42 |
|
| 43 |
$app->alias( 'redirect', function () use ( $app ) { |
| 44 |
return call_user_func_array( [$app->responses(), 'redirect'], func_get_args() ); |
| 45 |
} ); |
| 46 |
|
| 47 |
$app->alias( 'error', function () use ( $app ) { |
| 48 |
return call_user_func_array( [$app->responses(), 'error'], func_get_args() ); |
| 49 |
} ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* {@inheritDoc} |
| 54 |
*/ |
| 55 |
public function bootstrap( $container ) { |
| 56 |
// Nothing to bootstrap. |
| 57 |
} |
| 58 |
} |
| 59 |
|