获取imi命令行

@param string $toolName 工具名，如server
@param string $operation 操作名，如start
@param array $args 参数
@return string
162843
public static function getImiCmd($toolName, $operation, $args = [])
    {
        if(isset($_SERVER['_']) && $_SERVER['SCRIPT_FILENAME'] === $_SERVER['_'])
        {
            $cmd = $_SERVER['_'];
        }
        else
        {
            $cmd = ($_SERVER['_'] ?? 'php') . ' ' . $_SERVER['argv'][0];
        }
        $cmd .= ' ' . $toolName . '/' . $operation;
        if(null !== ($appNamespace = Args::get('appNamespace')))
        {
            $cmd .= ' -appNamespace "' . $appNamespace . '"';
        }
        foreach($args as $k => $v)
        {
            if(is_numeric($k))
            {
                $cmd .= ' -' . $v;
            }
            else
            {
                $cmd .= ' -' . $k . ' "' . $v . '"';
            }
        }
        return $cmd;
    }
1113628
public function execute($command = null, array $args = array(), array $options = array())
    {
        $command = $command ?: $this->defaultCommand;
        if (!isset($this->commands[$command])) {
            throw new ConsoleException("Command '$command' does not exist");
        }
        
        $callback = $this->commands[$command];
        if (is_callable($callback)) {
            $params = array($args, $options);
            if (is_string($callback)) {
                if (strpos($callback, '::') !== false) {
                    list($classname, $methodname) = explode('::', $callback);
                    $reflection = new ReflectionMethod($classname, $methodname);
                } else {
                    $reflection = new ReflectionFunction($callback);
                }
                $params = Utils::computeFuncParams($reflection, $args, $options);
            }
            $params[] = $this;
            return call_user_func_array($callback, $params);
        }

        $method = new ReflectionMethod($callback, 'execute');
        $params = Utils::computeFuncParams($method, $args, $options);
        return $method->invokeArgs(new $callback($this), $params);
    }
116536
public function execute(string $type, string $operation, array $parameters = [])
    {
        return $this->{$type}->{$operation}(...$parameters);
    }
347226
public static OpResultInfo invokeOp(String name, int index, String[] args) throws JMException
   {
      MBeanServer server = getMBeanServer();
      ObjectName objName = new ObjectName(name);
      MBeanInfo info = server.getMBeanInfo(objName);
      MBeanOperationInfo[] opInfo = info.getOperations();
      MBeanOperationInfo op = opInfo[index];
      MBeanParameterInfo[] paramInfo = op.getSignature();
      String[] argTypes = new String[paramInfo.length];

      for (int p = 0; p < paramInfo.length; p++)
         argTypes[p] = paramInfo[p].getType();
 
      return invokeOpByName(name, op.getName(), argTypes, args);
   }
621609
public function execute(Arguments $args, ConsoleIo $io)
    {
        $this->loadModel('MeCms.Users');

        $users = $this->Users->find()->contain('Groups', function (Query $q) {
            return $q->select(['label']);
        })->map(function (User $user) {
            if ($user->banned) {
                $user->status = __d('me_cms', 'Banned');
            } elseif (!$user->active) {
                $user->status = __d('me_cms', 'Pending');
            } else {
                $user->status = __d('me_cms', 'Active');
            }

            $user->created = $user->created instanceof Time ? $user->created->i18nFormat('yyyy/MM/dd HH:mm') : $user->created;
            $user->group = $user->group instanceof UsersGroup ? $user->group->label : $user->group;

            return $user->extract(['id', 'username', 'group', 'full_name', 'email', 'post_count', 'status', 'created']);
        });

        if ($users->isEmpty()) {
            $io->error(__d('me_cms', 'There are no users'));

            return null;
        }

        //Sets headers and prints as table
        $headers = [I18N_ID, I18N_USERNAME, I18N_GROUP, I18N_NAME, I18N_EMAIL, I18N_POSTS, I18N_STATUS, I18N_DATE];
        $io->helper('table')->output(array_merge([$headers], $users->toList()));

        return null;
    }
309455
protected function prepareOperator($parameter, string $operator): string
    {
        if (!$parameter instanceof ParameterInterface) {
            //Probably fragment
            return $operator;
        }

        if ($parameter->getType() == \PDO::PARAM_NULL) {
            switch ($operator) {
                case '=':
                    return 'IS';
                case '!=':
                    return 'IS NOT';
            }
        }

        return parent::prepareOperator($parameter, $operator);
    }
627565
public function getCallable($tool, $operation)
    {
        if(isset($this->data['tool'][$tool][$operation]))
        {
            $callable = $this->data['tool'][$tool][$operation];
            $callable[0] = App::getBean($callable[0]);
            return $callable;
        }
        else
        {
            return null;
        }
    }
1276394
private function createCommandWithUri(
        Operation $operation,
        CommandInterface $command,
        ServiceClientInterface $client
    ) {
        // Get the path values and use the client config settings
        $variables = [];
        foreach ($operation->getParams() as $name => $arg) {
            /* @var Parameter $arg */
            if ($arg->getLocation() == 'uri') {
                if (isset($command[$name])) {
                    $variables[$name] = $arg->filter($command[$name]);
                    if (!is_array($variables[$name])) {
                        $variables[$name] = (string) $variables[$name];
                    }
                }
            }
        }

        // Expand the URI template.
        $uri = Utils::uriTemplate($operation->getUri(), $variables);

        return $client->getHttpClient()->createRequest(
            $operation->getHttpMethod(),
            $this->description->getBaseUrl()->combine($uri),
            $command['request_options'] ?: []
        );
    }
682285
public function run(InputInterface $input, OutputInterface $output, array $args)
    {
        $arguments = [];
        $options   = [];

        foreach ($args as $arg) {
            $matches = [];
            if (0 < preg_match('/^\-{1,2}(?<key>[^\=]+)(\=(?<value>.*))?$/', $arg, $matches)) {
                $options[$matches['key']] = isset($matches['value']) ? $matches['value'] : true;
            } else {
                $arguments[] = $arg;
            }
        }

        if (!count($arguments)) {
            array_unshift($arguments, 'help');
        }

        $config = new Config(
            [
                'uses' => [
                    'core'     => null,
                    'git'      => null,
                    'php'      => null,
                    'composer' => null,
                    'phpunit'  => null,
                    'phpcs'    => null,
                    'travis'   => null,
                    'npm'      => null,
                    'gulp'     => null,
                    'itiqiti'  => null,
                ],
            ]
        );

        $el = new ExpressionLanguage();

        $expressionService = new ExpressionService($el);
        $s                 = new Service\ConfigService($expressionService);

        $s->load($config);

        $commandNames = array_shift($arguments);

        return $this->executeCommandFromName($input, $output, $commandNames, $arguments, $options, $config, $s);
    }
924523
private function createOperationOutput(array &$output, OperationInterface $operation)
    {
        $operationHandler = $this->getOperationHandler($operation);

        if (!$operationHandler) {
            return;
        }

        $output[] = '';

        $urlGenerator = $this->getUrlGenerator(
            $operationHandler->extractSourceUrl($operation)
        );

        $output = array_merge(
            $output,
            $operationHandler->getOutput($operation, $urlGenerator)
        );
    }
276142
public function execute($operation, $parameter = array(), $version = null)
    {
        // remove '/' from operation
        $operation = preg_replace('/\//', '', $operation);

        $className = 'RakutenRws_Api_Definition_'.$operation;
        if (!class_exists($className)) {
            throw new LogicException('Operation is not definied.');
        }

        $api = new $className($this, $this->options);
        if ($version !== null) {
            $api->setVersion($version);
        }

        return $api->execute($parameter);
    }
578645
public function process($src, OperationInterface $operation)
    {
        $field = $operation->getField();
        $order = $operation->getOrder();
        $src->order .= "ORDER BY $field $order";
        return $src;
    }
571938
public function execute(Arguments $args, ConsoleIo $io)
    {
        if (!$args->getOption('xml')) {
            $io->out('<info>Current Paths:</info>', 2);
            $io->out('* app:  ' . APP_DIR . DIRECTORY_SEPARATOR);
            $io->out('* root: ' . ROOT . DIRECTORY_SEPARATOR);
            $io->out('* core: ' . CORE_PATH);
            $io->out('');

            $io->out('<info>Available Commands:</info>', 2);
        }

        $commands = $this->commands->getIterator();
        $commands->ksort();

        if ($args->getOption('xml')) {
            $this->asXml($io, $commands);

            return static::CODE_SUCCESS;
        }
        $this->asText($io, $commands);

        return static::CODE_SUCCESS;
    }
701239
protected function doOperation($operation, OperationArguments $args)
    {
        try {
            // Trigger 'beforeOperation' event.
            $this->fireBeforeOperation($operation, $args);
            // Run the internal operation.
            $forwardMethod = 'forward' . ucfirst($operation);
            $returnValue   = call_user_func([$this, $forwardMethod], $args);
            // Trigger 'afterOperation' event.
            $this->fireAfterOperation($operation, $args, $returnValue);
            // Return the operation result.
            return $returnValue;
        } catch (Exception $e) {
            // Trigger 'onOperationException' event.
            $this->fireOnOperationException($operation, $args, $e);
            // Throw the original exception.
            throw $e;
        }
    }
1350868
public function batch(string $operation)
    {
        $this->request->allowMethod(['post']);

        $table = $this->loadModel();
        Assert::isInstanceOf($table, Table::class);

        $redirectUrl = $this->getBatchRedirectUrl();

        $batchIds = (array)$this->request->getData('batch.ids');
        if (empty($batchIds)) {
            $this->Flash->error((string)__('No records selected.'));

            return $this->redirect($redirectUrl);
        }

        $batchIdsCount = count($batchIds);

        // broadcast batch ids event
        $event = new Event((string)EventName::BATCH_IDS(), $this, [
            $batchIds,
            $operation,
            $this->Auth->user()
        ]);
        $this->getEventManager()->dispatch($event);

        $batchIds = is_array($event->result) ? $event->result : $batchIds;

        if (empty($batchIds)) {
            $operation = strtolower(Inflector::humanize($operation));
            $this->Flash->error((string)__('Insufficient permissions to ' . $operation . ' the selected records.'));

            return $this->redirect($redirectUrl);
        }

        if ('delete' === $operation) {
            $primaryKey = $table->getPrimaryKey();
            if (! is_string($primaryKey)) {
                throw new UnsupportedPrimaryKeyException();
            }

            $conditions = [$primaryKey . ' IN' => $batchIds];
            // execute batch delete
            if ($table->deleteAll($conditions)) {
                $this->Flash->success(
                    (string)__(count($batchIds) . ' of ' . $batchIdsCount . ' selected records have been deleted.')
                );
            } else {
                $this->Flash->error((string)__('Selected records could not be deleted. Please, try again.'));
            }

            return $this->redirect($redirectUrl);
        }

        if ('edit' === $operation && (bool)$this->request->getData('batch.execute')) {
            $fields = (array)$this->request->getData($this->name);
            if (empty($fields)) {
                $this->Flash->error((string)__('Selected records could not be updated. No changes provided.'));

                return $this->redirect($redirectUrl);
            }

            $primaryKey = $table->getPrimaryKey();
            if (! is_string($primaryKey)) {
                throw new UnsupportedPrimaryKeyException();
            }

            $conditions = [$primaryKey . ' IN' => $batchIds];
            // execute batch edit
            if ($table->updateAll($fields, $conditions)) {
                $this->Flash->success(
                    (string)__(count($batchIds) . ' of ' . $batchIdsCount . ' selected records have been updated.')
                );
            } else {
                $this->Flash->error((string)__('Selected records could not be updated. Please, try again.'));
            }

            return $this->redirect($redirectUrl);
        }

        $this->set('entity', $table->newEntity());
        $this->set('fields', Field::getCsvView($table, $operation, true, true));
        $this->render('CsvMigrations.Common/batch');
    }
603040
public function find($arg = null, $operator = '=', $fields = array('*'))
    {
        if ($fields[0] == '*') {
            $this->select();
        } else {
            $select_args = '';
            foreach ($fields as $key => $field) {
                if (is_array($field) && is_string($key)) {
                    foreach ($field as $part) {
                        $select_args .= $key . '.' . $part . ', ';
                    }
                } else {
                    $select_args .= $this->oosql_table . '.' . $field . ', ';
                }
            }

            $this->select(rtrim($select_args, ','));
        }
        if (!is_array($arg)) {
            $obj = $this->getEntityObject();
            $pri = $obj->getPrimary();
            if (null !== $arg) {
                $arg = array($pri[0] => $arg);
            }
        }
        $i = 0;
        $flag = '';
        if (is_array($arg)) {
            foreach ($arg as $col => $val) {
                if ($i > 0) {
                    $flag = 'and';
                }
                $this->where("$this->oosql_table.$col $operator ?", $val, $flag);
                $i++;
            }
        }



        return $this;
    }
69662
public function exec($modName, $method, $args)
    {
        $postData = $this->buildRpcReq($modName, $method, $args);

        $options = [
            CURLOPT_URL             => $this->host,
            CURLOPT_CUSTOMREQUEST   => 'POST', //请求类型 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'
            CURLOPT_POST            => true, //发送一个常规的post请求
            CURLOPT_RETURNTRANSFER  => true, //TRUE 将curl_exec()获取的信息以字符串返回，而不是直接输出
            CURLOPT_HEADER          => false, //启用时会将头文件的信息作为数据流输出。
            CURLOPT_CONNECTTIMEOUT  => 2, //在尝试连接时等待的秒数，(CURLOPT_CONNECTTIMEOUT_MS :以毫秒为单位)
            CURLOPT_TIMEOUT         => 2, //允许 cURL 函数执行的最长秒数
            CURLOPT_HTTPHEADER      => [ //header
                'User-Agent: ' . $this->userAgent,
            ],
            CURLOPT_POSTFIELDS      => http_build_query($postData), //这种方式强制采用 application/x-www-form-urlencoded
            CURLOPT_IPRESOLVE       => CURL_IPRESOLVE_V4, //允许程序选择想要解析的 IP 地址类别: ipv4
            //https不验证证书
            // CURLOPT_SSL_VERIFYHOST  => 0,
            // CURLOPT_SSL_VERIFYPEER  => false,
            // CURLOPT_HTTP_VERSION    => CURL_HTTP_VERSION_2_0, //强制使用 HTTP/2.0
        ];

        $ch = curl_init();
        curl_setopt_array($ch, $options);
        $response = curl_exec($ch);

        $errno = curl_errno($ch);
        if ($errno > 0) {
            $error = sprintf("curl error=%s, errno=%d.", curl_error($ch), $errno);
            curl_close($ch);
            throw new Exception($error);
        }

        //$curl_info 包含信息包括:url, content_type, http_code, header_size, request_size, total_time
        $curlInfo = curl_getinfo($ch);
        curl_close($ch);

        //$totalTime = $curlInfo['total_time'];
        if ($curlInfo['http_code'] != 200) {
            throw new Exception('rpc请求失败, http_code: ' . $curlInfo['http_code'] . ', response: ' . $response);
        }

        $data = json_decode($response, true);
        if (json_last_error() !== JSON_ERROR_NONE || ! is_array($data) || ! isset($data['code'])) {
            throw new Exception('rpc返回值非法, response: ' . $response);
        }

        if (0 === $data['code']) {
            return $data['data'];
        } else {
            throw new Exception('rpc返回值非法, code不为0, error msg: ' . $data['error']);
        }
    }