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