Exemplo n.º 1
0
 private function createLinkUrl(LinkMetadata $link, $object)
 {
     $language = new ExpressionLanguage();
     $compiledParams = array();
     foreach ($link->getParams() as $key => $expr) {
         $compiledParams[$key] = $language->evaluate($expr, array('object' => $object));
     }
     return $this->router->generate($link->getRoute(), $compiledParams, true);
 }
Exemplo n.º 2
0
 private function createLinkNode(LinkMetadata $link, XmlSerializationVisitor $visitor, $object)
 {
     $language = new ExpressionLanguage();
     $compiledParams = array();
     foreach ($link->getParams() as $key => $expr) {
         $compiledParams[$key] = $language->evaluate($expr, array('object' => $object));
     }
     $linkNode = $visitor->getDocument()->createElement('link');
     $linkNode->setAttribute('id', $link->getName());
     $linkNode->setAttribute('rel', $link->getEntity());
     $linkNode->setAttribute('href', $this->router->generate($link->getRoute(), $compiledParams, true));
     return $linkNode;
 }
 /**
  * Ensure that dynamic settings are correctly reset,
  * so that services that rely on those are correctly updated
  */
 private function resetDynamicSettings()
 {
     // Ensure to reset services that need to be.
     foreach ($this->resettableServiceIds as $serviceId) {
         if (!$this->container->initialized($serviceId)) {
             continue;
         }
         $this->container->set($serviceId, null);
     }
     // Update services that can be updated.
     foreach ($this->updatableServices as $serviceId => $methodCalls) {
         if (!$this->container->initialized($serviceId)) {
             continue;
         }
         $service = $this->container->get($serviceId);
         foreach ($methodCalls as $callConfig) {
             list($method, $expression) = $callConfig;
             $argument = $this->expressionLanguage->evaluate($expression, ['container' => $this->container]);
             call_user_func_array([$service, $method], [$argument]);
         }
     }
 }
 private function validateExpressionResult($className, Expression $expression, $allowsNull, ExpressionLanguage $expressionLanguage)
 {
     try {
         $result = $expressionLanguage->evaluate($expression, array('container' => $this->containerBuilder));
     } catch (\Exception $exception) {
         throw new InvalidExpressionException($expression, $exception);
     }
     if ($result === null) {
         if ($allowsNull) {
             return;
         }
         throw new TypeHintMismatchException(sprintf('Argument for type-hint "%s" is an expression that evaluates to null, which is not allowed', $className));
     }
     if (!is_object($result)) {
         throw new TypeHintMismatchException(sprintf('Argument for type-hint "%s" is an expression that evaluates to a non-object', $className));
     }
     $resultingClass = get_class($result);
     $this->validateClass($className, $resultingClass);
 }