Ejemplo n.º 1
0
 private function validateContextObjectType($contextName, ContextInterface $context)
 {
     // Check that the context name matches the name being requested.
     if ($contextName != $context->getContextName()) {
         $e = new ContextNotProvidedException('Context name does not match.');
         $this->logger->debug($e->getMessage(), array('ContextHandler', 'validateContextObjectType'));
         throw $e;
     }
     // Check that the object in the context is the correct type.
     try {
         $objectReflection = new ReflectionClass($context->getEntity());
         $interfaceReflection = new ReflectionClass($this->availableContexts[$contextName]);
         if ($interfaceReflection->isInterface() && $objectReflection->implementsInterface($this->availableContexts[$contextName]) || $objectReflection->isSubclassOf($this->availableContexts[$contextName]) || $objectReflection->getName() == $this->availableContexts[$contextName]) {
             return TRUE;
         }
     } catch (ReflectionException $e) {
         $e = new ContextNotProvidedException($e->getMessage(), NULL, $e);
         $this->logger->debug($e->getMessage(), array('ContextHandler', 'validateContextObjectType'));
         throw $e;
     }
     // Incorrect context type returned
     $e = new ContextNotProvidedException('Provider returned incorrect type: "' . get_class($context->getEntity()) . '".  Expecting: "' . $this->availableContexts[$contextName] . '".');
     $this->logger->debug($e->getMessage(), array('ContextHandler', 'validateContextObjectType'));
     throw $e;
 }
Ejemplo n.º 2
0
 public function setContext(ContextInterface $context)
 {
     $this->values[$context->getContextName()] = $context;
 }