/** * {@inheritdoc} */ public function execute(CommandParams $params, CommandExecutionContext $executionContext) { $fileName = $params->getFirstArgument(); if (!$executionContext->hasFileInWorkingDirectory($fileName)) { throw new ExecutionFailedException("File '{$fileName}' does not exist."); } $img = $this->imageManager->make($executionContext->getPathOfFileInWorkingDirectory($fileName)); if (!$params->hasSecondArgument()) { return $this->returnImage($img, $params); } list($width, $height) = $this->parseDimension($params->getSecondArgument()); switch ($params->getThirdArgument()) { case 'stretch': $img->resize($width, $height); break; case 'fit': $img->fit($width, $height); break; case 'crop': $x = $this->filterIntOrNullArgument($params->getArgument(3)); $y = $this->filterIntOrNullArgument($params->getArgument(4)); $img->crop($width, $height, $x, $y); break; default: $img->resize($width, $height, function (Constraint $constraint) { $constraint->aspectRatio(); }); break; } return $this->returnImage($img, $params); }
/** * {@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); } }
public function testEscapedStrings() { $params = new CommandParams('"foo bar" "baz fu" \'bar baz\''); $this->assertEquals(['foo bar', 'baz fu', "'bar", "baz'"], $params->getArguments()); $this->assertSame('foo bar', $params->getFirstArgument()); $this->assertSame('baz fu', $params->getSecondArgument()); $this->assertSame("'bar", $params->getThirdArgument()); $this->assertSame('foo bar', $params->getArgument(0)); $this->assertSame('baz fu', $params->getArgument(1)); $this->assertSame("'bar", $params->getArgument(2)); $this->assertSame("baz'", $params->getArgument(3)); }
/** * {@inheritdoc} */ public function execute(CommandParams $params, CommandExecutionContext $executionContext) { $article = $params->getFirstArgument(); $numSentences = (int) $params->getSecondArgument(0); $cacheFile = $this->getCacheFilePath($article); if (is_readable($cacheFile)) { $summary = file_get_contents($cacheFile); return $this->quote($summary, $numSentences); } $url = $this->buildURL($article); $response = file_get_contents($url); $data = json_decode($response); if (!$data) { throw new ExecutionFailedException('Wikipedia API response could not be decoded. Request URL: ' . $url . '. Response: ' . var_export($response, true)); } foreach ($data->query->pages as $page) { if (isset($page->missing)) { continue; } file_put_contents($cacheFile, $page->extract); return $this->quote($page->extract, $numSentences); } throw new ExecutionFailedException("Failed to query for Wikipedia article '{$article}'. Request URL: {$url}"); }