<?php
/**
 * 导库转用
 * 
 */
namespace app\crm\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Runtransdata extends Command{

    protected function configure()
    {
        
        $this->setName('runtransdata')->setDescription('Suxuan transdata command');
        $this->addArgument('method');
        $this->addArgument('action');
    }
    protected function execute(Input $input, Output $output)
    {

        if($input->getArgument('method') && $input->getArgument('action')){
            $controller = $input->getArgument('method');
            $action = $input->getArgument('action');
        }else{
            throw new \Exception("请在命令行后面输入要执行的修复方法，如：php think repair test", 1);
            die;
        }
        /**
         *要操作的类，此类必须在LIB下面
         * 
         */
        //$controller = 'Runtransdata';
        /**
         * 类里的方法
         */
        //$method = 'CaomeijuanJsj';
        
        if(!class_exists('app\\crm\\lib\\'.ucwords($controller))){
            echo '没有发现这个类：'.$controller."\r\n";
            exit();
        }
        $instance = new \ReflectionClass('app\\crm\\lib\\'.ucwords($controller));
        if (!$instance->hasMethod($action)) {
            echo '没有发现这个方法：'.$action."\r\n";
            exit();
        }

        $objMethod = $instance->getMethod($action);
        $handle = $instance->newInstance();
        try{
            $objMethod->invokeArgs($handle, array());

        }  catch (\Exception $e){
            echo '程序报错：'."\r\n";
            echo $e->getMessage()."\r\n";
            print_r($e->getTraceAsString());
        }
        
        
    }

}



