| 1 |
<?php |
| 2 |
namespace Depicter\Routing; |
| 3 |
|
| 4 |
use Depicter\Routing\Conditions\EditorOpen; |
| 5 |
use Depicter\Routing\Conditions\EditorPreview; |
| 6 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Provide custom route conditions. |
| 10 |
* This is an example class so feel free to modify or remove it. |
| 11 |
*/ |
| 12 |
class RouteConditionsServiceProvider implements ServiceProviderInterface { |
| 13 |
/** |
| 14 |
* {@inheritDoc} |
| 15 |
*/ |
| 16 |
public function register( $container ) { |
| 17 |
$this->registerRouteCondition( $container, 'depicter.condition.editor.open' , EditorOpen::class ); |
| 18 |
$this->registerRouteCondition( $container, 'depicter.condition.editor.preview', EditorPreview::class ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* {@inheritDoc} |
| 23 |
*/ |
| 24 |
public function bootstrap( $container ) { |
| 25 |
// Nothing to bootstrap. |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register a class as a route condition |
| 30 |
* |
| 31 |
* @param \Pimple\Container $container |
| 32 |
* @param string $name |
| 33 |
* @param string $class_name |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
protected function registerRouteCondition( $container, $name, $class_name ) { |
| 37 |
$container[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ] = array_merge( |
| 38 |
$container[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ], |
| 39 |
[ |
| 40 |
$name => $class_name, |
| 41 |
] |
| 42 |
); |
| 43 |
} |
| 44 |
} |
| 45 |
|