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