Пример #1
0
 /**
  * Provides a magic factory method to instantiate new objects with
  * shorter syntax than would otherwise be required by the Zend Framework
  * naming conventions. For more information, see Zend_Gdata_App::__call().
  *
  * This overrides the default behavior of __call() so that query classes
  * do not need to have their domain manually set when created with
  * a magic factory method.
  *
  * @see Zend_Gdata_App::__call()
  * @param string $method The method name being called
  * @param array $args The arguments passed to the call
  * @throws \Zend\GData\App\Exception
  */
 public function __call($method, $args)
 {
     if (preg_match('/^new(\\w+Query)/', $method, $matches)) {
         $class = $matches[1];
         $foundClassName = null;
         foreach ($this->_registeredPackages as $name) {
             try {
                 // Autoloading disabled on next line for compatibility
                 // with magic factories. See ZF-6660.
                 if (!class_exists($name . '\\' . $class, false)) {
                     @\Zend\Loader::loadClass($name . '\\' . $class);
                 }
                 $foundClassName = $name . '\\' . $class;
                 break;
             } catch (\Zend\Exception $e) {
                 // package wasn't here- continue searching
             }
         }
         if ($foundClassName != null) {
             $reflectionObj = new \ReflectionClass($foundClassName);
             // Prepend the domain to the query
             $args = array_merge(array($this->getDomain()), $args);
             return $reflectionObj->newInstanceArgs($args);
         } else {
             throw new App\Exception("Unable to find '{$class}' in registered packages");
         }
     } else {
         return parent::__call($method, $args);
     }
 }