2015-04-09 08:51:45 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\ProcessControl;
|
2015-04-09 08:51:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct an appropriate ProcessControl instance.
|
|
|
|
*
|
|
|
|
* @author Adirelle <adirelle@gmail.com>
|
|
|
|
*/
|
|
|
|
class Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* ProcessControl singleton.
|
|
|
|
*
|
|
|
|
* @var ProcessControlInterface
|
|
|
|
*/
|
|
|
|
protected static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ProcessControl singleton.
|
|
|
|
*
|
|
|
|
* @return ProcessControlInterface
|
|
|
|
*/
|
|
|
|
public static function getInstance()
|
|
|
|
{
|
|
|
|
if (static::$instance === null) {
|
|
|
|
static::$instance = static::createProcessControl();
|
|
|
|
}
|
|
|
|
return static::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a ProcessControl depending on available extensions and the underlying OS.
|
|
|
|
*
|
|
|
|
* Check PosixProcessControl, WindowsProcessControl and UnixProcessControl, in that order.
|
|
|
|
*
|
|
|
|
* @return ProcessControlInterface
|
2017-11-05 15:48:36 +01:00
|
|
|
*
|
2017-02-01 16:27:47 +01:00
|
|
|
* @throws \Exception
|
2015-04-09 08:51:45 +02:00
|
|
|
*/
|
|
|
|
public static function createProcessControl()
|
|
|
|
{
|
2015-10-05 15:17:13 +02:00
|
|
|
switch (true) {
|
2015-04-09 08:51:45 +02:00
|
|
|
case PosixProcessControl::isAvailable():
|
|
|
|
return new PosixProcessControl();
|
|
|
|
case UnixProcessControl::isAvailable():
|
|
|
|
return new UnixProcessControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \Exception("No ProcessControl implementation available.");
|
|
|
|
}
|
|
|
|
}
|