Pipeline commands.

@param  \Closure $pipeline Pipelined commands
@return array
19731
public function pipeline(Closure $pipeline): array
	{
		// Enable pipelining

		$this->pipelined = true;

		// Build commands

		$pipeline($this);

		// Send all commands to server and fetch responses

		$responses = [];

		$commands = count($this->commands);

		$this->sendCommandToServer(implode('', $this->commands));

		for($i = 0; $i < $commands; $i++)
		{
			$responses[] = $this->getResponse();
		}

		// Reset pipelining

		$this->commands = [];

		$this->pipelined = false;

		// Return array of responses

		return $responses;
	}
722532
protected function _getArgumentNames($controller, $command)
    {
        $controllerClassName = $this->_getControllerClassName($controller);
        if (!class_exists($controllerClassName)) {
            return [];
        }

        $command = Text::camelize($command) . 'Command';
        if (!method_exists($controllerClassName, $command)) {
            return [];
        }

        $arguments = [];
        foreach ((new \ReflectionMethod($controllerClassName, $command))->getParameters() as $parameter) {
            $arguments[] = '--' . strtr($parameter->name, '_', '-');
        }

        return $arguments;
    }
652550
protected function carry(): Closure
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                if ($this->always !== null) {
                    $passable = ($this->always)($passable, $pipe);
                }
                $slice = parent::carry();

                $callable = $slice($stack, $pipe);

                return $callable($passable);
            };
        };
    }
364897
protected function getCommandNames()
    {
        // Command::Hidden isn't supported before Symfony Console 3.2.0
        // We don't complete hidden command names as these are intended to be private
        if (method_exists('\Symfony\Component\Console\Command\Command', 'isHidden')) {
            $commands = array();

            foreach ($this->application->all() as $name => $command) {
                if (!$command->isHidden()) {
                    $commands[] = $name;
                }
            }

            return $commands;

        } else {

            // Fallback for compatibility with Symfony Console < 3.2.0
            // This was the behaviour prior to pull #75
            $commands = $this->application->all();
            unset($commands['_completion']);

            return array_keys($commands);
        }
    }
577986
protected function executeCommand($command)
    {
        if (method_exists(Process::class, 'fromShellCommandline')) {
            $process = Process::fromShellCommandline($command, null, $this->env);
        } else {
            $process = new Process($command, null, $this->env);
        }

        if (false !== $this->timeout) {
            $process->setTimeout($this->timeout);
        }

        $process->run();

        return [
            $process->getExitCode(),
            $process->getOutput(),
            $process->getErrorOutput(),
        ];
    }
1305045
public function command($signature, Closure $callback)
    {
        $command = new ClosureCommand($signature, $callback);

        Artisan::starting(function ($artisan) use ($command) {
            $artisan->add($command);
        });

        return $command;
    }
1242167
public function closure($closure)
    {
        // Retrieving the class and method to launch.
        if (!is_callable($closure)) {
            return null;
        }

        $injections = $this->injectorForClosure($closure);

        return [
            'action' => $closure,
            'injection' => $injections
        ];
    }
1272974
protected function mergePipelines($new)
    {
        if (!isset($this->nodes['pipelines']) || !count($this->nodes['pipelines'])) {
            return $new;
        }

        if (!count($new)) {
            return $this->nodes['pipelines'];
        }

        /** @var array $pipelinesKeys */
        $pipelinesKeys = array_merge(
            array_keys($this->nodes['pipelines']),
            array_keys($new)
        );

        return array_reduce($pipelinesKeys, function($carry, $key) use ($new) {
            $existing = $this->nodes['pipelines'];
            if (!isset($new[$key])) {
                $carry[$key] = $existing;
                return $carry;
            }
            if (!isset($existing[$key])) {
                $carry[$key] = $new[$key];
                return $carry;
            }

            $carry[$key] = $this->mergePipeline($existing[$key], $new[$key]);
            return $carry;
        }, []);
    }
361642
public function getPipeline()
    {
        $pipeline = [];
        foreach ($this->pipeline as $k => $v) {
            $pipeline[] = [$k => $v];
        }

        return $pipeline;
    }
772308
private function createStageCallback() : Closure
    {
        return function ($stages, $stage) {
            return function ($input) use ($stages, $stage) {
                if ($stage instanceof Closure) {
                    return $stage($input, $stages);
                } else {
                    if ($this->methodToCall === null) {
                        throw new PipelineException('Method must not be null');
                    }

                    if (!method_exists($stage, $this->methodToCall)) {
                        throw new PipelineException(get_class($stage) . "::{$this->methodToCall} does not exist");
                    }

                    return $stage->{$this->methodToCall}($input, $stages);
                }
            };
        };
    }
14766
public function execute(string $command) : array
    {
        $this->result = [];
        $process = new Process(
            $this->propelCommand . ' ' . $command . ' --config-dir=' . $this->configDir,
            $this->rootDirectory
        );

        $process->run([$this, 'handle']);

        return $this->result;
    }
285405
public function execute($command, $cwd = null)
    {
        if (strpos($command, '<') === 0) {
            return array(true, trim($command, '< '));
        }
        
        $processExecutor = $this->getProcessExecutor();

        $logger = $this->logger;

        $output = '';
        
        $outputHandler = function ($type, $data) use ($logger, &$output) {
            $output .= $data;
            
            $logger->writeVerbose('comment', trim($data));
        };
        
        if ($this->logger->getOutputInstance()->isVerbose()) {
            $this->logger->writeIndentation();
        }
        
        $result = $processExecutor->execute($command, $outputHandler, $cwd);

        return array($result === 0, $output);
    }
1271782
public function project($projection)
    {
        if ($projection instanceof Closure) {
            $callback = $projection;
            $projection = new Projection();
            $callback($projection);
        }

        if ($projection instanceof Projection) {
            $projection = $projection->getProjection();
        }

        $this->pipeline[] = ['$project' => $projection];

        return $this;
    }
7366
public function handle($command, Closure $next)
    {
        if (property_exists($command, 'rules') && is_array($command->rules)) {
            $this->validate($command);
        }

        return $next($command);
    }
810351
public function aggregate(array $pipeline, array $options = array())
    {
        $command = array(
            'aggregate' => $this->getCollectionName(),
            'pipeline' => $pipeline
        );
        $result = $this->command($command, $options);

        return $result['result'];
    }
488044
protected function getInitialSlice( Closure $destination )
	{
		return function ( $passable ) use ( $destination )
		{
			try
			{
				return call_user_func( $destination, $passable );
			}
			catch ( \Exception $e )
			{
				if ( is_callable( $this->exceptionHandler ) )
					return call_user_func( $this->exceptionHandler, $passable, $e );
				else
					throw new PipelineException( $e->getMessage(), 0, $e );
			}
			catch ( \Throwable $e )
			{
				if ( is_callable( $this->exceptionHandler ) )
					return call_user_func( $this->exceptionHandler, $passable, new FatalThrowableError( $e ) );
				else
					throw new PipelineException( $e->getMessage(), 0, $e );
			}
		};
	}
254436
protected function doAggregate(array $pipeline, array $options = array())
    {
        if (isset($options['cursor']) && ($options['cursor'] || is_array($options['cursor']))) {
            return $this->doAggregateCursor($pipeline, $options);
        }

        unset($options['cursor']);

        list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
            ? $this->splitCommandAndClientOptions($options)
            : array($options, array());

        $command = array();
        $command['aggregate'] = $this->riakCollection->getName();
        $command['pipeline'] = $pipeline;
        $command = array_merge($command, $commandOptions);

        $database = $this->database;
        $result = $this->retry(function() use ($database, $command, $clientOptions) {
            return $database->command($command, $clientOptions);
        });

        if (empty($result['ok'])) {
            throw new ResultException($result);
        }

        /* If the pipeline ends with an $out operator, return a cursor on that
         * collection so a table scan may be performed.
         */
        if (isset($pipeline[count($pipeline) - 1]['$out'])) {
            $outputCollection = $pipeline[count($pipeline) - 1]['$out'];

            return $database->selectCollection($outputCollection)->find();
        }

        $arrayIterator = new ArrayIterator(isset($result['result']) ? $result['result'] : array());
        $arrayIterator->setCommandResult($result);

        return $arrayIterator;
    }