Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Process] Normalize exceptions #5398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process\Exception;

/**
* InvalidArgumentException for the Process Component.
*
* @author Romain Neutron <[email protected]>
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
21 changes: 21 additions & 0 deletions src/Symfony/Component/Process/Exception/LogicException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process\Exception;

/**
* LogicException for the Process Component.
*
* @author Romain Neutron <[email protected]>
*/
class LogicException extends \LogicException implements ExceptionInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ProcessFailedException extends RuntimeException
public function __construct(Process $process)
{
if ($process->isSuccessful()) {
throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
}

parent::__construct(
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Process/PhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\RuntimeException;

/**
* PhpProcess runs a PHP script in an independent process.
*
Expand Down Expand Up @@ -68,7 +70,7 @@ public function run($callback = null)
{
if (null === $this->getCommandLine()) {
if (false === $php = $this->executableFinder->find()) {
throw new \RuntimeException('Unable to find the PHP executable.');
throw new RuntimeException('Unable to find the PHP executable.');
}
$this->setCommandLine($php);
}
Expand Down
31 changes: 17 additions & 14 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\RuntimeException;

/**
* Process is a thin wrapper around proc_* functions to ease
* start independent PHP processes.
Expand Down Expand Up @@ -111,14 +114,14 @@ class Process
* @param integer $timeout The timeout in seconds
* @param array $options An array of options for proc_open
*
* @throws \RuntimeException When proc_open is not installed
* @throws RuntimeException When proc_open is not installed
*
* @api
*/
public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
{
if (!function_exists('proc_open')) {
throw new \RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
}

$this->commandline = $commandline;
Expand Down Expand Up @@ -158,7 +161,7 @@ public function __destruct()
*
* @return integer The exit status code
*
* @throws \RuntimeException When process can't be launch or is stopped
* @throws RuntimeException When process can't be launch or is stopped
*
* @api
*/
Expand Down Expand Up @@ -187,13 +190,13 @@ public function run($callback = null)
* @param Closure|string|array $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @throws \RuntimeException When process can't be launch or is stopped
* @throws \RuntimeException When process is already running
* @throws RuntimeException When process can't be launch or is stopped
* @throws RuntimeException When process is already running
*/
public function start($callback = null)
{
if ($this->isRunning()) {
throw new \RuntimeException('Process is already running');
throw new RuntimeException('Process is already running');
}

$this->stdout = '';
Expand Down Expand Up @@ -233,7 +236,7 @@ public function start($callback = null)
$this->process = proc_open($commandline, $descriptors, $this->pipes, $this->cwd, $this->env, $this->options);

if (!is_resource($this->process)) {
throw new \RuntimeException('Unable to launch a new process.');
throw new RuntimeException('Unable to launch a new process.');
}
$this->status = self::STATUS_STARTED;

Expand Down Expand Up @@ -270,7 +273,7 @@ public function start($callback = null)
if ($n === 0) {
proc_terminate($this->process);

throw new \RuntimeException('The process timed out.');
throw new RuntimeException('The process timed out.');
}

if ($w) {
Expand Down Expand Up @@ -311,7 +314,7 @@ public function start($callback = null)
*
* @return int The exitcode of the process
*
* @throws \RuntimeException
* @throws RuntimeException
*/
public function wait($callback = null)
{
Expand All @@ -337,7 +340,7 @@ public function wait($callback = null)
if (0 === $n) {
proc_terminate($this->process);

throw new \RuntimeException('The process timed out.');
throw new RuntimeException('The process timed out.');
}

foreach ($r as $pipe) {
Expand All @@ -361,7 +364,7 @@ public function wait($callback = null)
}
$this->updateStatus();
if ($this->processInformation['signaled']) {
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
}

$time = 0;
Expand All @@ -373,7 +376,7 @@ public function wait($callback = null)
$exitcode = proc_close($this->process);

if ($this->processInformation['signaled']) {
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
throw new RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
}

$this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
Expand Down Expand Up @@ -546,7 +549,7 @@ public function isRunning()
*
* @return integer The exitcode of the process
*
* @throws \RuntimeException if the process got signaled
* @throws RuntimeException if the process got signaled
*/
public function stop($timeout=10)
{
Expand Down Expand Up @@ -622,7 +625,7 @@ public function setTimeout($timeout)
$timeout = (integer) $timeout;

if ($timeout < 0) {
throw new \InvalidArgumentException('The timeout value must be a valid positive integer.');
throw new InvalidArgumentException('The timeout value must be a valid positive integer.');
}

$this->timeout = $timeout;
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;

/**
* Process builder.
*
Expand Down Expand Up @@ -99,7 +102,7 @@ public function setTimeout($timeout)
$timeout = (integer) $timeout;

if ($timeout < 0) {
throw new \InvalidArgumentException('The timeout value must be a valid positive integer.');
throw new InvalidArgumentException('The timeout value must be a valid positive integer.');
}

$this->timeout = $timeout;
Expand All @@ -117,7 +120,7 @@ public function setOption($name, $value)
public function getProcess()
{
if (!count($this->arguments)) {
throw new \LogicException('You must add() command arguments before calling getProcess().');
throw new LogicException('You must add() command arguments before calling getProcess().');
}

$options = $this->options;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function shouldNotReplaceExplicitlySetVars()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromSetter()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Symfony\Component\Process\Tests;

use Symfony\Component\Process\Process,
Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessFailedException;

/**
* @author Sebastian Marek <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
class ProcessTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromConstructor()
{
new Process('', null, null, null, -1);
}

/**
* @expectedException \InvalidArgumentException
* @expectedException Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function testNegativeTimeoutFromSetter()
{
Expand Down