示例#1
0
 public function __construct($requests, $config = array())
 {
     $collection = array();
     $objs = array();
     $urls = array();
     foreach ($requests as $request) {
         if (is_subclass($request, 'Request')) {
             $objs[] = $request;
             continue;
         }
         if (filter_var($request, FILTER_VALIDATE_URL) === FALSE) {
             throw new \Exception('Invalid request URL');
         } else {
             $urls[] = $request;
         }
     }
     if (!(empty($urls) || empty($objs))) {
         throw new \Exception('Cannot mix data types when instantiating RequestCollection');
     }
     if (!empty($urls)) {
         $collection = array_map(function ($url) {
             $method = empty($config['method']) ? 'GetRequest' : ucfirst(strtolower($config['method'])) . 'Request';
             $request = new $method($url, $config['data']);
             if (isset($config['async']) && $config['async'] === TRUE) {
                 $request = new AsynRequest($request);
             }
             return $request;
         }, $urls);
     }
     if (!empty($objs)) {
         $collection = $objs;
     }
     return parent::__construct($collection);
 }
示例#2
0
function is_assignable($type, $value)
{
    if (is_null($value)) {
        return true;
    }
    assert_not_null($type, 'Function is_assignable: $type must not be null');
    if (!is_string($type)) {
        show_error('is_assignable', '$type must be a string');
    }
    if (is_array_type($type)) {
        //		$array_type = get_array_component_type($type);
        return get_qualified_type($value) == $type;
    }
    switch (strtolower($type)) {
        case 'string':
            if (is_string($value)) {
                return true;
            }
            break;
        case 'int':
            if (is_int($value)) {
                return true;
            }
            break;
        case 'boolean':
            if (is_bool($value)) {
                return true;
            }
            break;
        case 'array':
            if (is_array($value)) {
                return true;
            }
            break;
        case 'float':
            if (is_float($value)) {
                return true;
            }
            break;
        default:
            if (is_object($value) && is_subclass(get_class($value), $type)) {
                return true;
            }
            break;
    }
    return false;
}
 function checkCommand(&$command)
 {
     return $this->commandClass == null || is_subclass(get_class($command), $this->commandClass);
 }
示例#4
0
 function &getServicesOfType($class)
 {
     global $appContext;
     $services = array();
     foreach ($appContext->servicePoints as $sname => $sp) {
         $className = $sp->getClassName();
         if (is_subclass($className, $class)) {
             $instance =& $sp->instance();
             $services[$sname] =& $instance;
         }
     }
     return $services;
 }
示例#5
0
 function supports($class)
 {
     if (is_subclass($class, 'Post')) {
         return true;
     }
 }