| 1 |
<?php |
| 2 |
namespace Depicter\WordPress; |
| 3 |
|
| 4 |
use Depicter\Dynamic\ContentTypes\Post; |
| 5 |
use Depicter\Dynamic\ContentTypes\Product; |
| 6 |
use Depicter\Dynamic\ContentTypes\Types; |
| 7 |
use Pimple\Container; |
| 8 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 9 |
|
| 10 |
class RestApiServiceProvider implements ServiceProviderInterface |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* Register all dependencies in the IoC container. |
| 15 |
* |
| 16 |
* @param Container $container |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function register($container) |
| 21 |
{ |
| 22 |
$container[ Types::class ] = function () { |
| 23 |
return new Types(); |
| 24 |
}; |
| 25 |
|
| 26 |
$container[ Post::class ] = function () { |
| 27 |
return new Post(); |
| 28 |
}; |
| 29 |
|
| 30 |
$container[ Product::class ] = function () { |
| 31 |
return new Product(); |
| 32 |
}; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Bootstrap any services if needed. |
| 37 |
* |
| 38 |
* @param Container $container |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function bootstrap($container) |
| 43 |
{ |
| 44 |
add_action( 'rest_api_init', [ $this, 'registerRoutes' ]); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Register routes |
| 49 |
* |
| 50 |
*/ |
| 51 |
public function registerRoutes() |
| 52 |
{ |
| 53 |
register_rest_route( 'depicter/v1', '/dynamic/content-types', [ |
| 54 |
'methods' => 'GET', |
| 55 |
'callback' => \Depicter::closure()->method( Types::class, 'index' ), |
| 56 |
'permission_callback' => '__return_true' |
| 57 |
]); |
| 58 |
|
| 59 |
register_rest_route( 'depicter/v1', '/dynamic/content-types/post', [ |
| 60 |
'methods' => 'GET', |
| 61 |
'callback' => \Depicter::closure()->method( Post::class, 'index' ), |
| 62 |
'permission_callback' => '__return_true' |
| 63 |
]); |
| 64 |
|
| 65 |
register_rest_route( 'depicter/v1', '/dynamic/content-types/product', [ |
| 66 |
'methods' => 'GET', |
| 67 |
'callback' => \Depicter::closure()->method( Product::class, 'index' ), |
| 68 |
'permission_callback' => '__return_true' |
| 69 |
]); |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|