Get command callback for cloning

@param string $path
@param string $ref
@param string $command
@return callable
197346
protected function getCloneCommandCallback($path, $ref, $command)
    {
        return function ($url) use ($ref, $path, $command) {
            return sprintf($command, ProcessExecutor::escape($url), ProcessExecutor::escape($path), ProcessExecutor::escape($ref));
        };
    }
1286740
public function init($path = null)
    {
        $path = is_null($path) ? $this->environment->path : $path;

        // Check if clone already exists at this path. If so we can safely skip.
        if (file_exists($path)) {
            $wrapper = new GitWrapper();
            $wrapper->setTimeout(3600);

            try {
                $working_copy = new GitWorkingCopy($wrapper, $path);
                $output = $working_copy->remote('-v');
            } catch (GitException $e) {
                throw new \Exception('Path already exists.');
            }

            // if repo exists in the remotes already, this working copy is ok.
            if (strpos(strtolower($output), strtolower($this->app->repo)) !== false) {
                return true;
            } else {
                throw new Exception('Git clone already exists at that path, but it is not for this app.');
            }
        }

        try {
            // Create App folder
            mkdir($path, 0755, TRUE);
            chdir($path);

            // Clone repo
            $wrapper = new GitWrapper();
            $wrapper->setTimeout(3600);
            $wrapper->streamOutput();
            $wrapper->cloneRepository($this->app->repo, $path);

            // Checkout correct version.
            $git = new GitWorkingCopy($wrapper, $this->getSourcePath());
            $git->checkout($this->environment->version);

        } catch (\GitWrapper\GitException $e) {

            // If exception is because there is no git ref, continue.
            if (strpos($e->getMessage(), 'error: pathspec') !== 0) {
                return false;
            }
        }

        chdir($path);
        $wrapper->git('branch');
        $wrapper->git('status');
        $this->loadConfig();

        // Run the build hooks
        if (!empty($this->config['hooks']['build'])) {
            chdir($this->getSourcePath());
            $process = new Process($this->config['hooks']['build']);
            $process->run(function ($type, $buffer) {
                if (Process::ERR === $type) {
                    echo $buffer;
                } else {
                    echo $buffer;
                }
            });
        }

        return $this->writeConfig();
    }
1204982
protected function createResource($path, $reference)
    {
        if (null === $reference) {
            $resource = new GenericResource();
        } elseif (isset($reference[0]) && '@' === $reference[0]) {
            $resource = new LinkResource(substr($reference, 1));
        } elseif (is_dir($reference)) {
            $resource = new DirectoryResource($reference);
        } elseif (is_file($reference)) {
            $resource = new FileResource($reference);
        } else {
            throw new RuntimeException(sprintf(
                'Trying to create a FilesystemResource on a non-existing file or directory "%s"',
                $reference
            ));
        }

        $resource->attachTo($this, $path);

        return $resource;
    }
240861
public function getCommandHandler($command)
    {
        $key = get_class($command);

        if (array_key_exists($key, $this->handlers)) {
            $handler = $this->handlers[$key];

            return $this->container->make($handler);
        }
    }
451165
public function repoGetFileInfo($repo, $path, $ref = null)
    {
        $src = $this->client->api('Repositories\Src');
        /** @var \Buzz\Message\Response $response */
        $response = $this->checkResponse($src->get($this->username, $repo, $ref, $path));

        return $this->cleanSrcData(json_decode($response->getContent(), true));
    }
1057840
public function execute($command, callable $next)
    {
        if ($this->transactionLevel > 0) {
            $this->storeMessages();
        }

        ++$this->transactionLevel;

        end($this->transactionMessages);
        $savepoint = key($this->transactionMessages);
        $savepoint = $savepoint === null ? 0 : ++$savepoint;

        try {
            $returnValue = $next($command);

            $this->storeMessages();

            --$this->transactionLevel;
        } catch (\Exception $e) {
            $this->capturer->clear();
            array_splice($this->transactionMessages, $savepoint);

            --$this->transactionLevel;
            throw $e;
        } catch (\Error $e) {
            $this->capturer->clear();
            array_splice($this->transactionMessages, $savepoint);

            --$this->transactionLevel;
            throw $e;
        }

        if ($this->transactionLevel === 0) {
            $this->publish();
        }

        return $returnValue;
    }
289937
public function getAction(Request $request, $reference, $path)
    {
        $path = '/' . $path;
        // TODO add ß, ä, ö, perhaps other special chars
        $path = urldecode(
            str_replace(array('u%CC_', 'a%CC_', 'o%CC_', '%C3_'), array('ü', 'ä', 'ö', 'ß'), urlencode($path))
        );

        $session = $this->getSessionByHash($reference);
        $file = $session->getFile($path);

        if ($request->get('content') !== null) {
            return $this->getContent($file);
        }

        return $this->handleView($this->view(new File($file, $file->getName(), $reference)));
    }
266649
public function addCallbackCommand($command)
    {
        if (!is_object($command)) {
            if (!class_exists($command)) {
                throw new TelegramSDKException(
                    sprintf(
                        'Command class "%s" not found! Please make sure the class exists.',
                        $command
                    )
                );
            }

            if ($this->telegram->hasContainer()) {
                $command = $this->buildDependencyInjectedAnswer($command);
            } else {
                $command = new $command();
            }
        }

        if ($command instanceof CallbackCommandInterface) {

            /*
             * At this stage we definitely have a proper command to use.
             *
             * @var CallbackCommand $command
             */
            $this->commands[$command->getName()] = $command;

            return $this;
        }

        throw new TelegramSDKException(
            sprintf(
                'Command class "%s" should be an instance of "Telegram\Bot\Callback\CallbackCommandInterface"',
                get_class($command)
            )
        );
    }
339054
public function command($command, $method) {

        self::$commands[] = $command;
        self::$callbacks[$command] = $method;
    }
877806
public function request(CommandInterface $command)
    {
        if ($command instanceof UploadFile
            || $command instanceof UploadNewFileVersion) {
            return $command->execute($this->uploadClient);
        }

        return $command->execute($this->apiClient);
    }
229668
protected function forceCommand($command)
    {
        if ((
            Str::startsWith($command, 'migrate') === true && Str::startsWith($command, 'migrate:status') === false ||
            Str::startsWith($command, 'db:seed') === true
        ) && strpos($command, '--force') === false) {
            $command .= ' --force';
        }

        if ((
            is_null($this->laravel) === false &&
            version_compare($this->laravel->version(), 5.5, '>=') &&
            Str::startsWith($command, 'vendor:publish') === true
        ) && strpos($command, '--all') === false) {
            $command .= ' --all';
        }

        return $command;
    }
859185
public function exec($command, $callback = null)
    {
        $this->commandStack[] = [
            'command' => new Command($this->receiveCommand($command)),
            'callback' => $callback,
        ];

        return $this;
    }
415692
public static function fromCommand(CommandInterface $command)
	{
		$file = new self();
		$file->setParameters($command->getResponse()->json() + array('path' => $command['path']));
		$file->finishUpload();
		return $file->getParameters();
	}
515346
public function getOrCreateIfNotExists($command, array $args = [])
    {
        if (null !== $job = $this->findJob($command, $args)) {
            return $job;
        }

        $job = new Job($command, $args, false);
        $this->_em->persist($job);
        $this->_em->flush($job);

        $firstJob = $this->_em->createQuery('SELECT j FROM JMSJobQueueBundle:Job j WHERE j.command = :command AND j.args = :args ORDER BY j.id ASC')
            ->setParameter('command', $command)
            ->setParameter('args', $args, 'json_array')
            ->setMaxResults(1)
            ->getSingleResult();

        if ($firstJob === $job) {
            $job->setState(Job::STATE_PENDING);
            $this->_em->persist($job);
            $this->_em->flush($job);

            return $job;
        }

        $this->_em->remove($job);
        $this->_em->flush($job);

        return $firstJob;
    }
1121715
public function getChild($path)
	{
		$path    = str_replace(array('/', '\\'), '\\', $path);
		$names   = explode('\\', $path);
		$command = $this;

		foreach ($names as $name)
		{
			if (isset($command[$name]))
			{
				$command = $command[$name];

				continue;
			}

			return null;
		}

		return $command;
	}
952652
public function execute($command, callable $next)
    {
        $filename = $command->getFile()->path();
        $this->apiDocBuilder->debug('Starting to parse file: ' . $filename);
        try {
            return $next($command);
        } catch (\Exception $e) {
            $this->apiDocBuilder->log('Unable to parse file "' . $filename . '", ' . $e->getMessage());
        }
        return null;
    }
1314291
public function execute($command)
    {
        $deferred = new Deferred();

        if ($this->ending) {
            $deferred->reject(new RuntimeException('Shell is ending already'));
        } else {
            $this->pending []= $deferred;

            $this->sendCommand($command);
        }

        return $deferred->promise();
    }