class-cloudsecure-wp-cli-disable-restapi.php
8 months ago
class-cloudsecure-wp-cli-disable.php
8 months ago
class-cloudsecure-wp-cli-enable.php
8 months ago
class-cloudsecure-wp-cli-list.php
8 months ago
class-cloudsecure-wp-cli-status.php
8 months ago
class-cloudsecure-wp-cli-list.php
97 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CloudSecure WP Security List Command |
| 4 | * 機能一覧表示専用のコマンドクラス |
| 5 | * |
| 6 | * @package CloudSecure_WP_Security |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | if ( ! class_exists( 'WP_CLI' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // ベースクラスを読み込み |
| 18 | require_once dirname( __DIR__ ) . '/class-cloudsecure-wp-cli-base.php'; |
| 19 | |
| 20 | /** |
| 21 | * CloudSecure WP Security List Command |
| 22 | * 機能一覧表示専用のコマンドクラス |
| 23 | */ |
| 24 | class CloudSecureWP_CLI_List extends CloudSecureWP_CLI_Base { |
| 25 | |
| 26 | /** |
| 27 | * 機能一覧を表示する |
| 28 | * |
| 29 | * ## EXAMPLES |
| 30 | * wp cldsec-wp-security list |
| 31 | * |
| 32 | * @param array $args 位置引数 |
| 33 | * @param array $assoc_args 関連� |
| 34 | �列引数 |
| 35 | */ |
| 36 | public function __invoke( $args = array(), $assoc_args = array() ) { |
| 37 | try { |
| 38 | $features_data = array(); |
| 39 | |
| 40 | foreach ( self::FEATURE_MAP as $cli_name => $property_name ) { |
| 41 | // 設定値が存在しない機能を除外 |
| 42 | if ( in_array( $cli_name, self::CONFIG_EXCLUDED_FEATURES, true ) ) { |
| 43 | WP_CLI::debug( "機能 '{$cli_name}' はCONFIG_EXCLUDED_FEATURESに含まれているためスキップします" ); |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | $feature_instance = $this->get_feature_instance( $cli_name ); |
| 48 | |
| 49 | // インスタンスが取得できない場合はエラー終了 |
| 50 | if ( ! $feature_instance ) { |
| 51 | $this->output_error_response( |
| 52 | array( |
| 53 | 'message' => "機能 '{$cli_name}' のインスタンスを取得できませんでした。", |
| 54 | ) |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | // is_enabled メソッドが存在しない場合はエラー終了 |
| 59 | if ( ! method_exists( $feature_instance, 'is_enabled' ) ) { |
| 60 | $this->output_error_response( |
| 61 | array( |
| 62 | 'message' => "機能 '{$cli_name}' の有効無効状� |
| 63 | �を取得できません。", |
| 64 | ) |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | // is_enabledメソッドを実行し機能の状� |
| 69 | �を取得 |
| 70 | $status = $feature_instance->is_enabled() ? 'enabled' : 'disabled'; |
| 71 | $description = self::FEATURE_DESCRIPTIONS[ $cli_name ] ?? $cli_name; |
| 72 | |
| 73 | $features_data[] = array( |
| 74 | 'name' => $cli_name, |
| 75 | 'description' => $description, |
| 76 | 'status' => $status, |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | // 成功レスポンスを出力 |
| 81 | $response_data = array( |
| 82 | 'result' => 'success', |
| 83 | 'data' => array( |
| 84 | 'features' => $features_data, |
| 85 | ), |
| 86 | ); |
| 87 | $this->output_success_response( $response_data ); |
| 88 | } catch ( Exception $e ) { |
| 89 | $this->output_error_response( |
| 90 | array( |
| 91 | 'message' => $e->getMessage(), |
| 92 | ) |
| 93 | ); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 |