Factory.php
720 Bytes
<?php
namespace Hood\Utils\Rpc;
class Factory
{
private static $type = null;
/**
* 返回一个rpc
* @param $url
* @param string $type
* @return Httpc|Yar
*/
public static function getInstance($url, $type='yar')
{
if (strtolower($type) == 'yar') {
self::$type = 'yar';
return new Yar($url);
} else {
self::$type = 'httpc';
return new Httpc($url);
}
}
public static function loop($callback=null, $errorCallback=null)
{
if (self::$type == 'yar') {
Yar::loop($callback, $errorCallback);
} else {
Httpc::loop($callback, $errorCallback);
}
}
}