/** * {@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}"); }