Ws.php
709 Bytes
<?php
class Q_Ws {
private static $_driver;
private static $_config = array();
private static $_ws;
public static function factory($driver = 'httpcws', array $config = array('section' => 'servers')) {
if (empty($driver) || !array_key_exists('section', $config)) {
throw new Q_Exception(__CLASS__ . 'Ws driver be empty or Config not "section" key.');
}
$class = 'Q_Ws_Adapter_' . ucfirst($driver);
if (!class_exists($class)) {
throw new Q_Exception(__CLASS__ . ' Not ' . $class . ' Class. ');
}
$deff_config = array_diff($config, self::$_config);
if (self::$_driver == $driver || empty($deff_config)) {
return self::$_ws;
}
return self::$_ws = new $class($config);
}
}