Creates the command execution code.

@param string            $name
@param \ReflectionMethod $method

@return \Closure
359525
private function createCode($name, \ReflectionMethod $method)
    {
        return function (InputInterface $input, OutputInterface $output) use ($name, $method) {
            $client = new Client([], null, $output);

            if ($input->getOption('token')) {
                $client->authorize($input->getOption('token'));
            }

            $methodName = $method->getName();
            $api = $client->api(strtolower($name));
            $args = (new NamedArgumentsResolver($method))->resolve(array_merge($input->getOptions(), $input->getArguments()));
            $outputClass = $this->generateOutputClassFromApiClass($api);

            $response = call_user_func_array([$api, $methodName], $args);

            if (method_exists($outputClass, $methodName) && false === $input->getOption('debug') && $response->getStatusCode() < 400) {
                (new $outputClass())->{$methodName}($output, $response);
            } elseif (!method_exists($outputClass, $methodName) || true === $input->getOption('debug')) {
                $output->writeln("Headers:\n" . print_r($response->getHeaders(), true) . "Body:\n" . print_r((string) $response->getBody(), true));
            }
        };
    }
176406
protected function createCallback(string $method): \Closure
    {
        return \Closure::bind(static function (...$args) use ($method) {
            return self::$method(...$args);
        }, null, $this->type);
    }
201877
public function command($name, Closure $action)
    {
        return $this->on(self::getEvent($action), self::getChecker($name));
    }
921255
public function execute($name, AnCommandContext $context)
    {
        $type = '';

        if ($context->caller) {
            $identifier = clone $context->caller->getIdentifier();

            if ($identifier->path) {
                $type = array_shift($identifier->path);
            } else {
                $type = $identifier->name;
            }
        }

        $parts = explode('.', $name);
        $method = !empty($type) ? '_'.$type.ucfirst(AnInflector::implode($parts)) : '_'.lcfirst(AnInflector::implode($parts));

        if (in_array($method, $this->getMethods())) {
            return $this->$method($context);
        }

        return true;
    }
1073396
public function addMethod($method, $name = null)
    {
        if (is_array($method)) {
            require_once 'Zend/Server/Method/Definition.php';
            $method = new Zend_Server_Method_Definition($method);
        } elseif (!$method instanceof Zend_Server_Method_Definition) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception('Invalid method provided');
        }

        if (is_numeric($name)) {
            $name = null;
        }
        if (null !== $name) {
            $method->setName($name);
        } else {
            $name = $method->getName();
        }
        if (null === $name) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception('No method name provided');
        }

        if (!$this->_overwriteExistingMethods && array_key_exists($name, $this->_methods)) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception(sprintf('Method by name of "%s" already exists', $name));
        }
        $this->_methods[$name] = $method;
        return $this;
    }
329917
protected function string(string $name): Closure
    {
        return function (Table $table, MigrationContextInterface $context) use ($name) {
            $length = $context->getModelSchemas()->getAttributeLength($context->getModelClass(), $name);
            $table->addColumn($name, Type::STRING)->setLength($length)->setNotnull(true);
        };
    }
337731
protected function newMethod($name, array $arguments = [])
    {
        return O\Expression::methodCall(
                $this->expression,
                O\Expression::value($name),
                array_map([O\Expression::getType(), 'argument'], array_map([O\Expression::getType(), 'value'], $arguments))
        );
    }
621944
protected function executeCommandHook($method, $event_type)
    {
        foreach ($this->getCommandsByMethodEventType($method, $event_type) as $command) {
            if (is_string($command)) {
                $command = (new CommandHook())
                    ->setType('raw')
                    ->setCommand($command);
            } elseif (is_array($command)) {
                $command = CommandHook::createWithData($command);
            }

            if (!$command instanceof CommandHookInterface) {
                continue;
            }

            switch ($command->getType()) {
                case 'symfony':
                    $this->executeSymfonyCmdHook($command, $method);
                    break;
                default:
                    $this->executeEngineCmdHook($command);
                    break;
            }
        }

        return $this;
    }
756766
protected function processMethod(\ReflectionMethod $method, Definition $definition)
    {
        $annotations = $this->reader->getMethodAnnotations($method);

        foreach ($annotations as $annotation)
        {
            if ($annotation instanceof AttributeAnnotation) {
                $this->validateMethodAttribute($annotation, $method);

                $attribute = $this->createAttributeByMethod($annotation, $method);
                $definition->addAttribute($attribute);
            }
        }
    }
808191
protected function invokeInaccessibleMethod($object, $name, array $args = [])
    {
        $method = new \ReflectionMethod($object, $name);
        $method->setAccessible(true);
        return $method->invokeArgs(is_object($object) ? $object : null, $args);
    }
63750
public function addMethod($name, callable $method)
    {
        $this->methods[$name] = \Closure::bind($method, $this, $this);

        return $this;
    }
279497
public function __callProtectedMethod($name, $arguments = [])
    {
        try {
            $method = $this->__reflection()->getMethod($name);
        }
        catch(\Exception $e) {
            return next::caller();
        }

        $method->setAccessible(true);
        $result =  $method->invokeArgs($this, $arguments);
        $method->setAccessible(false);

        return $result;
    }
716630
public function supportPortalMethod( $name, $method )
	{
		if( $name instanceof Module )
		{
			$name = $name->getKey();
		}

		return $this->module->support($name) && method_exists($this, $method);
	}
284889
public function addAuthMethod($name, MethodInterface $method)
    {
        $this->getAuthentication()->addMethod($name, $method);

        return $this;
    }
1337756
public function resolveStatic(string $name, string $method, ...$args)
    {
        return $this->resolve($name . '::' . $method, ...$args);
    }
453106
private function buildDefinition(\ReflectionMethod $method, $token = null)
    {
        $definition = new InputDefinition();

        foreach ($method->getParameters() as $parameter) {
            if ($parameter->isDefaultValueAvailable()) {
                //option
                $definition->addOption(new InputOption($parameter->getName(), null, InputOption::VALUE_REQUIRED, null, $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null));
            } else {
                //argument
                $definition->addArgument(new InputArgument($parameter->getName(), InputArgument::REQUIRED, null, null));
            }
        }

        $definition->addOption(new InputOption('token', null, InputOption::VALUE_REQUIRED, 'the auth token to use', $token));
        $definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'display raw response'));

        return $definition;
    }
518228
public function methods($name = [])
    {
        if (!func_num_args()) {
            return $this->_methods;
        }
        foreach ($name as $method => $returns) {
            if (is_callable($returns)) {
                $this->method($method, $returns);
            } elseif (is_array($returns)) {
                $stub = $this->method($method);
                call_user_func_array([$stub, 'andReturn'], $returns);
            } else {
                $error = "Stubbed method definition for `{$method}` must be a closure or an array of returned value(s).";
                throw new InvalidArgumentException($error);
            }
        }
    }