/** * {@inheritdoc} */ public function getInstance($class) { // module activation $this->module->activate($this); if ($this->boundInstance->hasBound($class, $this->module)) { return $this->boundInstance->getBound(); } // get bound config $definition = $this->boundInstance->getDefinition(); // be all parameters ready $params = $this->boundInstance->bindConstruct($class, $definition->params, $this->module); $refClass = new \ReflectionClass($definition->class); if ($refClass->isInterface()) { return $this->getInstance($definition->class); } // weave aspect $module = $this->module; $bind = $module($definition->class, new $this->bind()); /* @var $bind \Ray\Aop\Bind */ $hasBinding = $bind->hasBinding(); $instance = $hasBinding ? $this->compiler->noBindNewInstance($definition->class, $params, $bind) : $refClass->newInstanceArgs($params); // do not call constructor twice. ever. unset($definition->setter['__construct']); // call setter methods foreach ($definition->setter as $method => $value) { call_user_func_array([$instance, $method], $value); } // attach interceptors if ($hasBinding) { $instance->rayAopBind = $bind; } // logger inject info if ($this->logger) { $this->logger->log($definition, $params, $definition->setter, $instance, $bind); } // object life cycle, store singleton instance. $this->postInject($instance, $definition); return $instance; }
/** * Install module * * @param AbstractModule $module * * @return void */ public function install(AbstractModule $module) { $module->activate($this->dependencyInjector); $this->pointcuts = new ArrayObject(array_merge((array) $module->pointcuts, (array) $this->pointcuts)); $this->bindings = $this->mergeBindings($module); if ($module->modules) { $this->modules = array_merge($this->modules, $module->modules); } }