예제 #1
0
 /**
  * This method is used to run all dependency checks on both modules and services and lock
  * down the application so no more modules/services can be added. Hooks are also ran.
  *
  * @param $hooks array The hooks you want to run on modules.
  * @return this
  */
 public function forge($hooks = null)
 {
     //set hooks
     if ($hooks && is_array($hooks)) {
         $this->setHooks($hooks);
     }
     //resolve all services
     foreach ($this->_modules as $moduleClassName => $module) {
         //run module dependency check for errors
         $this->_moduleDependencyErrorCheck($moduleClassName);
         //register all services for module
         foreach ($module->services as $serviceClassName => $service) {
             if (isset($this->_serviceModuleMap[$serviceClassName])) {
                 $errorMsg = 'Service "' . $serviceClassName . '" has already been defined.';
                 throw new Exception($errorMsg);
             } else {
                 $this->_serviceDependencyGraph->addResource($serviceClassName);
                 $this->_serviceDependencyGraph->addDependencies($serviceClassName, $service->dependencies);
                 $this->_serviceModuleMap[$serviceClassName] = $moduleClassName;
             }
         }
     }
     $moduleHooks = $this->getHooks();
     foreach ($moduleHooks as $hook) {
         //run each module's hook method
         foreach ($this->_modules as $moduleClassName => $module) {
             $module->invoke($hook);
         }
     }
     $this->_forged = true;
     return $this;
 }
예제 #2
0
 /**
  * Registers a new service into ulfberht.
  * @param string $className The class name you would like to register
  * @param string $constructorType The constructor type
  * @return void
  */
 private function _registerService($className, $constructorType)
 {
     if (!class_exists($className)) {
         $errorMsg = sprintf(self::ERROR_CLASS_NOT_FOUND, $className);
         throw new ulfberhtException($errorMsg);
     } elseif ($this->has($className)) {
         $errorMsg = sprintf(self::ERROR_CLASS_ALREADY_DEFINED, $className);
         throw new ulfberhtException($errorMsg);
     }
     $this->_services[$className] = new serviceWrapper($className, $constructorType);
     $this->_serviceDependencyGraph->addResource($className);
     $this->_serviceDependencyGraph->addDependencies($className, $this->_services[$className]->dependencies);
 }