Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(CommandParams $params, CommandExecutionContext $executionContext)
 {
     $fileName = $params->getFirstArgument();
     if (is_readable($fileName)) {
         $contents = file_get_contents($fileName);
     } else {
         if (!$executionContext->hasFileInWorkingDirectory($fileName)) {
             throw new ExecutionFailedException("File '{$fileName}' does not exist.");
         }
         $contents = $executionContext->getContentsOfFileInWorkingDirectory($fileName);
     }
     switch ($params->getSecondArgument()) {
         case 'class':
             return $this->findClass($contents, $params, $fileName);
         case 'abstract':
             return $this->findAbstract($contents);
         case 'method':
             return $this->findMethod($contents, $params, $fileName);
         case 'function':
             return $this->findFunction($contents, $params, $fileName);
         case 'line':
             return $this->findLines($contents, $params);
         default:
             return $this->wrapLines($contents);
     }
 }
Exemplo n.º 2
0
 /**
  * @param Image         $img
  * @param CommandParams $params
  *
  * @return string
  *
  * @throws ExecutionFailedException
  */
 private function returnImage(Image $img, CommandParams $params)
 {
     switch ($this->returnType) {
         case self::RETURN_TYPE_URL:
         case self::RETURN_TYPE_PATH:
             $tmpDir = $this->executionContext->ensureTempDirectory();
             $tmpFile = $tmpDir . '/' . md5($params->getParams()) . '.png';
             $img->encode('png')->save($tmpFile);
             if ($this->returnType === self::RETURN_TYPE_PATH) {
                 return $tmpFile;
             }
             return '<img src="/_tmp/' . basename($tmpFile) . '">';
         case self::RETURN_TYPE_DATA_URL:
             return '![Image](' . $img->encode('data-url')->getEncoded() . ')';
         case self::RETURN_TYPE_DATA:
             return $img->encode('png')->getEncoded();
         default:
             throw new ExecutionFailedException("Invalid return type '{$this->returnType}' detected.");
     }
 }
Exemplo n.º 3
0
 /**
  * !include File.php.
  */
 public function testFile()
 {
     $expected = file_get_contents($this->ctx->getWorkingDirectory() . '/Calc.php');
     $actual = $this->cmd->execute(new CommandParams('Calc.php'), $this->ctx);
     $this->assertSourceCode($expected, $actual);
 }
Exemplo n.º 4
0
 /**
  * @param string $article
  *
  * @return string
  */
 private function getCacheFilePath($article)
 {
     $tmpDir = $this->executionContext->ensureTempDirectory();
     $tmpFile = $tmpDir . '/summary-' . md5($article) . '.txt';
     return $tmpFile;
 }