/** * @param string $class * @param object $instance * @param array $params * @param array $setters * @param bool $isSingleton */ private function build($class, $instance, array $params, array $setters, $isSingleton) { $params = $this->makeParamRef($params); foreach ($setters as &$methodPrams) { $methodPrams = $this->makeParamRef($methodPrams); } $dependencyFactory = new DependencyFactory($instance, $params, $setters, $this, $isSingleton); list(, , $definition) = $this->config->fetch($class); // @PostConstruct $postConstructMethod = $definition['PostConstruct']; $dependencyFactory->setPostConstruct($postConstructMethod); // aop ? if (isset($instance->rayAopBind)) { $interceptors = $this->buildInterceptor($instance); $dependencyFactory->setInterceptors($interceptors); } $index = (string) $dependencyFactory; $this->dependencyContainer[$index] = $dependencyFactory; $diLog = $dependencyFactory->getDependencyLog(); if ($diLog) { $this->errorLog('ray/di.depends ' . $diLog); } $aopLog = $dependencyFactory->getInterceptorLog(); if ($aopLog) { $this->errorLog('ray/di.aspect ' . $aopLog); } }
/** * Set param by type bound * * @param string $typeHint * @param string $bindingToType * @param string $target * * @return mixed */ private function typeBound($typeHint, $bindingToType, $target) { list(, , $definition) = $this->config->fetch($typeHint); $in = isset($definition[Definition::SCOPE]) ? $definition[Definition::SCOPE] : Scope::PROTOTYPE; $param = $this->getInstanceWithContainer($in, $bindingToType, $target); return $param; }
/** * @param string $class * @param bool $isSingleton * @param string $interface * * @return BoundDefinition */ private function getBoundDefinition($class, $isSingleton, $interface, \ArrayObject $configDefinition = null) { $boundDefinition = new BoundDefinition(); list($boundDefinition->params, $boundDefinition->setter, $definition) = $this->config->fetch($class); $boundDefinition->isSingleton = $isSingleton || strcasecmp(Scope::SINGLETON, $definition[Definition::SCOPE]) === 0; $hasDirectBinding = isset($this->module->bindings[$class]); /** @var $definition Definition */ if ($definition->hasDefinition() || $hasDirectBinding) { list($boundDefinition->params, $boundDefinition->setter) = $this->bindModule($boundDefinition->setter, $definition); } $boundDefinition->class = $class; $boundDefinition->interface = $interface; $boundDefinition->postConstruct = $definition[Definition::POST_CONSTRUCT]; $boundDefinition->preDestroy = $definition[Definition::PRE_DESTROY]; $boundDefinition->inject = $configDefinition[Definition::INJECT]; return $boundDefinition; }