OSDN Git Service

merge MethodSubcommand into Subcommand
authorscribu <mail@scribu.net>
Fri, 26 Apr 2013 18:50:59 +0000 (21:50 +0300)
committerscribu <mail@scribu.net>
Fri, 26 Apr 2013 18:57:51 +0000 (21:57 +0300)
php/WP_CLI/Dispatcher/MethodSubcommand.php [deleted file]
php/WP_CLI/Dispatcher/Subcommand.php
php/class-wp-cli.php
php/dispatcher.php

diff --git a/php/WP_CLI/Dispatcher/MethodSubcommand.php b/php/WP_CLI/Dispatcher/MethodSubcommand.php
deleted file mode 100644 (file)
index f66329b..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-namespace WP_CLI\Dispatcher;
-
-class MethodSubcommand extends Subcommand {
-
-       function __construct( CommandContainer $parent, $class, \ReflectionMethod $method ) {
-               $docparser = new \WP_CLI\DocParser( $method );
-
-               $name = $docparser->get_tag( 'subcommand' );
-               if ( !$name )
-                       $name = $method->name;
-
-               $callable = new CallableMethod( $class, $method->name );
-
-               parent::__construct( $parent, $name, $callable, $docparser );
-       }
-
-       function get_alias() {
-               return $this->docparser->get_tag( 'alias' );
-       }
-}
-
index 80d43f6..8b3bae2 100644 (file)
@@ -4,15 +4,28 @@ namespace WP_CLI\Dispatcher;
 
 class Subcommand implements Command, AtomicCommand, Documentable {
 
-       function __construct( CommandContainer $parent, $name, $callable, $docparser ) {
+       private $parent, $name, $method, $docparser;
+
+       function __construct( CommandContainer $parent, \ReflectionMethod $method, $name = false ) {
+               $docparser = new \WP_CLI\DocParser( $method );
+
+               if ( !$name )
+                       $name = $docparser->get_tag( 'subcommand' );
+
+               if ( !$name )
+                       $name = $method->name;
+
                $this->parent = $parent;
                $this->name = $name;
 
-               $this->callable = $callable;
-
+               $this->method = $method;
                $this->docparser = $docparser;
        }
 
+       function get_alias() {
+               return $this->docparser->get_tag( 'alias' );
+       }
+
        function show_usage( $prefix = 'usage: ' ) {
                \WP_CLI::line( $prefix . $this->get_full_synopsis() );
        }
@@ -53,7 +66,9 @@ class Subcommand implements Command, AtomicCommand, Documentable {
                                array( $this, 'show_usage' ) );
                }
 
-               call_user_func( $this->callable, $args, $assoc_args );
+               $instance = new $this->method->class;
+
+               call_user_func( array( $instance, $this->method->name ), $args, $assoc_args );
        }
 
        function get_name() {
index befc509..b8abecc 100644 (file)
@@ -40,7 +40,8 @@ class WP_CLI {
                $reflection = new \ReflectionClass( $class );
 
                if ( $reflection->hasMethod( '__invoke' ) ) {
-                       $command = new Dispatcher\MethodSubcommand( self::$root, $reflection->name, $reflection->getMethod( '__invoke' ) );
+                       $command = new Dispatcher\Subcommand( self::$root,
+                               $reflection->getMethod( '__invoke' ), $name );
                } else {
                        $command = self::create_composite_command( $name, $reflection );
                }
@@ -57,7 +58,7 @@ class WP_CLI {
                        if ( !self::_is_good_method( $method ) )
                                continue;
 
-                       $subcommand = new Dispatcher\MethodSubcommand( $container, $reflection->name, $method );
+                       $subcommand = new Dispatcher\Subcommand( $container, $method );
 
                        $subcommand_name = $subcommand->get_name();
                        $full_name = self::get_full_name( $subcommand );
index da4e1b0..168ced1 100644 (file)
@@ -52,18 +52,3 @@ interface Documentable {
        function get_full_synopsis();
 }
 
-
-class CallableMethod {
-
-       function __construct( $class, $method ) {
-               $this->class = $class;
-               $this->method = $method;
-       }
-
-       function __invoke( $args, $assoc_args ) {
-               $instance = new $this->class;
-
-               call_user_func( array( $instance, $this->method ), $args, $assoc_args );
-       }
-}
-