Esempio n. 1
0
 /**
  * Loads a service from any namespace.
  *
  * This method is intend to load services. Its possible to pass a string with just a name of a service
  * to this method or you pass an array with namespace like this -> array('namespace', 'service').
  *
  * @param string|array $service Just the name of the service if a Doozr default service or
  *                              as an array with additional namespace like: array('namespace', 'service')
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return Doozr_Base_Service_Interface An/the instance of the requested service
  * @static
  */
 public static function load($service)
 {
     // Get arguments generic way rip off 1st this is the service name
     $arguments = array_slice(func_get_args(), 1);
     $fullQualifiedService = self::getFullQualifiedService($service);
     $className = $fullQualifiedService['namespace'] . '_' . ucfirst($fullQualifiedService['name']) . '_Service';
     // Instantiated?
     self::$instance === null ? self::init() : null;
     // Load file
     self::getService($fullQualifiedService['name'], $fullQualifiedService['namespace']);
     // Generate map from annotations in source of current service main entry
     self::$map->reset()->generate($className);
     // Store map
     self::$registry->getContainer()->addToMap(self::$map);
     // Create instance ...
     /* @var $instance Doozr_Base_Service_Interface */
     $instance = self::$registry->getContainer()->build($className, $arguments);
     // Decide which identifier to use
     $identifier = strtolower($fullQualifiedService['alias'] !== null ? $fullQualifiedService['alias'] : $fullQualifiedService['name']);
     // Register service and put the UUID as reference into response
     $instance->setUuid(self::registerService($identifier, $instance));
     return $instance;
 }