/** * Short description of method getImpToDelegateTo * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource resource * @param array params * @return \core_kernel_persistence_ResourceInterface */ public function getImpToDelegateTo(\core_kernel_classes_Resource $resource, $params = array()) { if (!isset(self::$ressourcesDelegatedTo[$resource->getUri()]) || PersistenceProxy::isForcedMode()) { $impls = $this->getAvailableImpl($params); foreach ($impls as $implName => $enable) { // If the implementation is enabled && the resource exists in this context if ($enable && $this->isValidContext($implName, $resource)) { $implClass = self::$implClasses[$implName]; $reflectionMethod = new \ReflectionMethod($implClass, 'singleton'); $delegate = $reflectionMethod->invoke(null); if (PersistenceProxy::isForcedMode()) { return $delegate; } self::$ressourcesDelegatedTo[$resource->getUri()] = $delegate; break; } } } return self::$ressourcesDelegatedTo[$resource->getUri()]; }
/** * Retrieve the inplementation to delegate * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource resource * @param array params * @return \core_kernel_persistence_ResourceInterface */ public function getImpToDelegateTo(core_kernel_classes_Resource $resource, $params = array()) { $returnValue = null; if (!isset(self::$ressourcesDelegatedTo[$resource->getUri()]) || PersistenceProxy::isForcedMode()) { $impls = $this->getAvailableImpl($params); foreach ($impls as $implName => $enable) { // If the implementation is enabled && the resource exists in this context if ($enable && $this->isValidContext($implName, $resource)) { $implClass = self::$implClasses[$implName]; $reflectionMethod = new \ReflectionMethod($implClass, 'singleton'); $delegate = $reflectionMethod->invoke(null); if (PersistenceProxy::isForcedMode()) { return $delegate; } self::$ressourcesDelegatedTo[$resource->getUri()] = $delegate; break; } } } if (isset(self::$ressourcesDelegatedTo[$resource->getUri()])) { $returnValue = self::$ressourcesDelegatedTo[$resource->getUri()]; } else { $errorMessage = "The resource with uri {$resource->getUri()} does not exist in the available implementation(s): "; $i = 0; foreach ($this->getAvailableImpl() as $name => $valid) { if ($valid) { if ($i > 0) { $errorMessage .= ", "; } $errorMessage .= $name; } $i++; } throw new \core_kernel_persistence_Exception($errorMessage); } return $returnValue; }