Fixed bugs with task runner classes
Fixed strict errors in foreground and background task classes.
This commit is contained in:
@@ -6,7 +6,7 @@ class RippingCluster_BackgroundTask {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run($command) {
|
public static function run($command) {
|
||||||
$pipes = array();
|
$pipes = array();
|
||||||
$pid = proc_open($command . ' &', array(), $pipes);
|
$pid = proc_open($command . ' &', array(), $pipes);
|
||||||
proc_close($pid);
|
proc_close($pid);
|
||||||
|
|||||||
@@ -59,7 +59,9 @@ class RippingCluster_ForegroundTask {
|
|||||||
$tx[] = $pipes[self::PIPE_STDIN];
|
$tx[] = $pipes[self::PIPE_STDIN];
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_select($rx, $tx, $ex = null, null, null); // Block til r/w possible
|
$ex = array();
|
||||||
|
|
||||||
|
stream_select($rx, $tx, $ex, null, null); // Block til r/w possible
|
||||||
if (!empty($tx)) {
|
if (!empty($tx)) {
|
||||||
$txRet = fwrite($pipes[self::PIPE_STDIN], substr($stdin, $txOff, 8192));
|
$txRet = fwrite($pipes[self::PIPE_STDIN], substr($stdin, $txOff, 8192));
|
||||||
if ($txRet !== false) {
|
if ($txRet !== false) {
|
||||||
|
|||||||
11
lib/RippingCluster/IPlugin.class.php
Normal file
11
lib/RippingCluster/IPlugin.class.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
interface RippingCluster_IPlugin {
|
||||||
|
|
||||||
|
public static function init();
|
||||||
|
|
||||||
|
public static function name();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
9
lib/RippingCluster/IPluginFactory.class.php
Normal file
9
lib/RippingCluster/IPluginFactory.class.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
interface RippingCluster_IPluginFactory {
|
||||||
|
|
||||||
|
public static function init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
abstract class RippingCluster_PluginFactory {
|
abstract class RippingCluster_PluginFactory implements RippingCluster_IPluginFactory {
|
||||||
|
|
||||||
static protected $validPlugins;
|
static private $validPlugins = array();
|
||||||
|
|
||||||
abstract public static function init();
|
protected static function ensureScanned() {
|
||||||
|
if (! isset(self::$validPlugins[get_called_class()])) {
|
||||||
|
static::scan();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function isValidPlugin($plugin) {
|
||||||
|
return isset(self::$validPlugins[get_called_class()][$plugin]);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getValidPlugins() {
|
public static function getValidPlugins() {
|
||||||
return array_keys(self::$validPlugins);
|
static::ensureScanned();
|
||||||
|
return array_keys(self::$validPlugins[get_called_class()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function findPlugins($directory) {
|
protected static function findPlugins($directory) {
|
||||||
@@ -23,28 +32,36 @@ abstract class RippingCluster_PluginFactory {
|
|||||||
return $plugins;
|
return $plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function loadPlugins($plugins, $prefix) {
|
protected static function loadPlugins($plugins, $prefix, $interface) {
|
||||||
self::$validPlugins = array();
|
self::$validPlugins[get_called_class()] = array();
|
||||||
|
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$fullClassname = $prefix . $plugin;
|
$fullClassname = $prefix . $plugin;
|
||||||
if ( ! class_exists($fullClassname, true)) {
|
if ( ! class_exists($fullClassname, true)) {
|
||||||
echo "Cannot load $fullClassname\n";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! in_array('RippingCluster_Worker_IPlugin', class_implements($fullClassname))) {
|
if ( ! in_array($interface, class_implements($fullClassname))) {
|
||||||
echo "$plugin does not implement the necessary interfaces\n";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise the plugin
|
// Initialise the plugin
|
||||||
call_user_func(array($fullClassname, 'init'));
|
call_user_func(array($fullClassname, 'init'));
|
||||||
|
|
||||||
self::$validPlugins[$plugin] = $fullClassname;
|
self::$validPlugins[get_called_class()][$plugin] = $fullClassname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function classname($plugin) {
|
||||||
|
static::ensureScanned();
|
||||||
|
|
||||||
|
if ( ! self::isValidPlugin($plugin)) {
|
||||||
|
throw new RippingCluster_Exception_InvalidPluginName($plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$validPlugins[get_called_class()][$plugin];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
15
lib/RippingCluster/Source/IPlugin.class.php
Normal file
15
lib/RippingCluster/Source/IPlugin.class.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
interface RippingCluster_Source_IPlugin extends RippingCluster_IPlugin {
|
||||||
|
|
||||||
|
public static function enumerate();
|
||||||
|
|
||||||
|
public static function load($source_filename, $scan = true, $use_cache = true);
|
||||||
|
|
||||||
|
public static function loadEncoded($encoded_filename, $scan = true, $use_cache = true);
|
||||||
|
|
||||||
|
public static function isValidSource($source);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
41
lib/RippingCluster/Source/PluginFactory.class.php
Normal file
41
lib/RippingCluster/Source/PluginFactory.class.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory {
|
||||||
|
|
||||||
|
const PLUGIN_DIR = 'RippingCluster/Source/Plugin/';
|
||||||
|
const PLUGIN_PREFIX = 'RippingCluster_Source_Plugin_';
|
||||||
|
const PLUGIN_INTERFACE = 'RippingCluster_Source_IPlugin';
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function scan() {
|
||||||
|
$candidatePlugins = parent::findPlugins(self::PLUGIN_DIR);
|
||||||
|
|
||||||
|
self::loadPlugins($candidatePlugins, self::PLUGIN_PREFIX, self::PLUGIN_INTERFACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function load($plugin, $source_filename, $scan = true, $use_cache = true) {
|
||||||
|
self::ensureScanned();
|
||||||
|
|
||||||
|
if ( ! self::isValidPlugin($plugin)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return call_user_func(array(self::classname($plugin), 'load'), $source_filename, $scan, $use_cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadEncoded($plugin, $encoded_filename, $scan = true, $use_cache = true) {
|
||||||
|
self::ensureScanned();
|
||||||
|
|
||||||
|
if ( ! self::isValidPlugin($plugin)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return call_user_func(array(self::classname($plugin), 'loadEncoded'), $encoded_filename, $scan, $use_cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
interface RippingCluster_Worker_IPlugin {
|
interface RippingCluster_Worker_IPlugin extends RippingCluster_IPlugin {
|
||||||
|
|
||||||
public static function init();
|
|
||||||
|
|
||||||
public static function name();
|
|
||||||
|
|
||||||
public static function workerFunctions();
|
public static function workerFunctions();
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
class RippingCluster_Worker_PluginFactory extends RippingCluster_PluginFactory {
|
class RippingCluster_Worker_PluginFactory extends RippingCluster_PluginFactory {
|
||||||
|
|
||||||
const PLUGIN_DIR = 'RippingCluster/Worker/Plugin/';
|
const PLUGIN_DIR = 'RippingCluster/Worker/Plugin/';
|
||||||
const PREFIX = 'RippingCluster_Worker_Plugin_';
|
const PLUGIN_PREFIX = 'RippingCluster_Worker_Plugin_';
|
||||||
|
const PLUGIN_INTERFACE = 'RippingCluster_Worker_IPlugin';
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
@@ -12,15 +13,15 @@ class RippingCluster_Worker_PluginFactory extends RippingCluster_PluginFactory {
|
|||||||
public static function scan() {
|
public static function scan() {
|
||||||
$candidatePlugins = parent::findPlugins(self::PLUGIN_DIR);
|
$candidatePlugins = parent::findPlugins(self::PLUGIN_DIR);
|
||||||
|
|
||||||
parent::loadPlugins($candidatePlugins, self::PREFIX);
|
parent::loadPlugins($candidatePlugins, self::PLUGIN_PREFIX, self::PLUGIN_INTERFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPluginWorkerFunctions($plugin) {
|
public static function getPluginWorkerFunctions($plugin) {
|
||||||
if ( ! isset(parent::$validPlugins[$plugin])) {
|
if ( ! self::isValidPlugin($plugin)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return call_user_func(array(parent::$validPlugins[$plugin], 'workerFunctions'));
|
return call_user_func(array(self::classname($plugin), 'workerFunctions'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user