Service_Provider.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods\CLI; |
| 4 | |
| 5 | use Pods\CLI\Commands\Field; |
| 6 | use Pods\CLI\Commands\Group; |
| 7 | use Pods\CLI\Commands\Playbook; |
| 8 | use Pods\CLI\Commands\Pod; |
| 9 | use WP_CLI; |
| 10 | |
| 11 | /** |
| 12 | * Class Service_Provider |
| 13 | * |
| 14 | * Add CLI commands and objects. |
| 15 | * |
| 16 | * @since 2.8.0 |
| 17 | */ |
| 18 | class Service_Provider extends \tad_DI52_ServiceProvider { |
| 19 | |
| 20 | /** |
| 21 | * Binds and sets up implementations. |
| 22 | */ |
| 23 | public $namespace; |
| 24 | |
| 25 | /** |
| 26 | * Registers the classes and functionality needed for CLI. |
| 27 | * |
| 28 | * @since 2.8.0 |
| 29 | */ |
| 30 | public function register() { |
| 31 | $this->container->singleton( 'pods.cli.commands.pods.pod', Pod::class, [ 'hook' ] ); |
| 32 | $this->container->singleton( 'pods.cli.commands.pods.group', Group::class, [ 'hook' ] ); |
| 33 | $this->container->singleton( 'pods.cli.commands.pods.field', Field::class, [ 'hook' ] ); |
| 34 | |
| 35 | $this->hooks(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Hooks all the methods and actions the class needs. |
| 40 | * |
| 41 | * @since 2.8.0 |
| 42 | */ |
| 43 | protected function hooks() { |
| 44 | // Add dynamic commands. |
| 45 | pods_container( 'pods.cli.commands.pods.pod' ); |
| 46 | pods_container( 'pods.cli.commands.pods.group' ); |
| 47 | pods_container( 'pods.cli.commands.pods.field' ); |
| 48 | |
| 49 | // Add static commands. |
| 50 | if ( defined( 'WP_CLI' ) ) { |
| 51 | WP_CLI::add_command( 'pods playbook', Playbook::class ); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 |