diff --git a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php new file mode 100644 index 000000000..9adbbb062 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php @@ -0,0 +1,101 @@ +count() === 0) { + throw new ConfigurationError; + } + } + return self::$config; + } + + /** + * Create a transport from config + * + * @param Zend_Config $config + * + * @return LocalCommandFile|RemoteCommandFile + * @throws ConfigurationError + */ + public static function fromConfig(Zend_Config $config) + { + switch (strtolower($config->transport)) { + case 'remote': + $transport = new RemoteCommandFile(); + break; + case 'local': + case '': // Casting null to string is the empty string + $transport = new LocalCommandFile(); + break; + default: + throw new ConfigurationError; + } + unset($config->transport); + foreach ($config as $key => $value) { + $method = 'set' . ucfirst($key); + if (! method_exists($transport, $method)) { + throw new ConfigurationError; + } + $transport->$method($value); + } + return $transport; + } + + /** + * Create a transport by name + * + * @param string $name + * + * @return LocalCommandFile|RemoteCommandFile + * @throws ConfigurationError + */ + public static function create($name) + { + $config = self::getConfig()->get($name); + if ($config === null) { + throw new ConfigurationError; + } + return self::fromConfig($config); + } + + /** + * Create a transport by the first section of the configuration + * + * @return LocalCommandFile|RemoteCommandFile + */ + public static function first() + { + $config = self::getConfig()->current(); + return self::fromConfig($config); + } +}