Beispiel #1
0
 /**
  * Note that the following features are not supported:
  *  * strings with escaped quotes are not supported "foo\"bar";
  *  * string concatenation ("foo" "bar").
  */
 private function phpize($value)
 {
     // trim on the right as comments removal keep whitespaces
     $value = rtrim($value);
     $lowercaseValue = strtolower($value);
     switch (true) {
         case defined($value):
             return constant($value);
         case 'yes' === $lowercaseValue || 'on' === $lowercaseValue:
             return true;
         case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue:
             return false;
         case isset($value[1]) && ("'" === $value[0] && "'" === $value[strlen($value) - 1] || '"' === $value[0] && '"' === $value[strlen($value) - 1]):
             // quoted string
             return substr($value, 1, -1);
         default:
             return XmlUtils::phpize($value);
     }
 }
 /**
  * Returns arguments as valid php types.
  *
  * @param \DOMElement $node
  * @param string      $name
  * @param bool        $lowercase
  *
  * @return mixed
  */
 private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
 {
     $arguments = array();
     foreach ($this->getChildren($node, $name) as $arg) {
         if ($arg->hasAttribute('name')) {
             $arg->setAttribute('key', $arg->getAttribute('name'));
         }
         if (!$arg->hasAttribute('key')) {
             $key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
         } else {
             $key = $arg->getAttribute('key');
         }
         // parameter keys are case insensitive
         if ('parameter' == $name && $lowercase) {
             $key = strtolower($key);
         }
         // this is used by DefinitionDecorator to overwrite a specific
         // argument of the parent definition
         if ($arg->hasAttribute('index')) {
             $key = 'index_' . $arg->getAttribute('index');
         }
         switch ($arg->getAttribute('type')) {
             case 'service':
                 $onInvalid = $arg->getAttribute('on-invalid');
                 $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
                 if ('ignore' == $onInvalid) {
                     $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
                 } elseif ('null' == $onInvalid) {
                     $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
                 }
                 if ($strict = $arg->getAttribute('strict')) {
                     $strict = XmlUtils::phpize($strict);
                 } else {
                     $strict = true;
                 }
                 $arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior, $strict);
                 break;
             case 'expression':
                 $arguments[$key] = new Expression($arg->nodeValue);
                 break;
             case 'collection':
                 $arguments[$key] = $this->getArgumentsAsPhp($arg, $name, false);
                 break;
             case 'string':
                 $arguments[$key] = $arg->nodeValue;
                 break;
             case 'constant':
                 $arguments[$key] = constant($arg->nodeValue);
                 break;
             default:
                 $arguments[$key] = XmlUtils::phpize($arg->nodeValue);
         }
     }
     return $arguments;
 }
Beispiel #3
0
 /**
  * Parses a collection of "option" XML nodes.
  *
  * @param \SimpleXMLElement $nodes The XML nodes
  *
  * @return array The options
  */
 protected function parseOptions(\SimpleXMLElement $nodes)
 {
     $options = array();
     foreach ($nodes as $node) {
         if (count($node) > 0) {
             if (count($node->value) > 0) {
                 $value = $this->parseValues($node->value);
             } elseif (count($node->constraint) > 0) {
                 $value = $this->parseConstraints($node->constraint);
             } else {
                 $value = array();
             }
         } else {
             $value = XmlUtils::phpize($node);
             if (is_string($value)) {
                 $value = trim($value);
             }
         }
         $options[(string) $node['name']] = $value;
     }
     return $options;
 }
Beispiel #4
0
 /**
  * @dataProvider getDataForPhpize
  */
 public function testPhpize($expected, $value)
 {
     $this->assertSame($expected, XmlUtils::phpize($value));
 }
 /**
  * Converts an xml value to a PHP type.
  *
  * @param mixed $value
  *
  * @return mixed
  */
 public static function phpize($value)
 {
     return XmlUtils::phpize($value);
 }
Beispiel #6
0
 /**
  * Transforms an XML attribute's value in a PHP value.
  *
  * @param \SimpleXMLElement $array
  * @param string            $key
  * @param string            $type
  *
  * @return bool|string|null
  */
 private function phpize(\SimpleXMLElement $array, string $key, string $type)
 {
     if (!isset($array[$key])) {
         return;
     }
     switch ($type) {
         case 'string':
             return (string) $array[$key];
         case 'bool':
             return (bool) XmlUtils::phpize($array[$key]);
     }
 }
Beispiel #7
0
 /**
  * Returns arguments as valid php types.
  *
  * @param \DOMElement $node
  * @param string      $name
  * @param bool        $lowercase
  *
  * @return mixed
  */
 private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
 {
     $arguments = [];
     foreach ($this->getChildren($node, $name) as $arg) {
         if ($arg->hasAttribute('name')) {
             $arg->setAttribute('key', $arg->getAttribute('name'));
         }
         if (!$arg->hasAttribute('key')) {
             $key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
         } else {
             $key = $arg->getAttribute('key');
         }
         // parameter keys are case insensitive
         if ('parameter' == $name && $lowercase) {
             $key = strtolower($key);
         }
         // this is used by DefinitionDecorator to overwrite a specific
         // argument of the parent definition
         if ($arg->hasAttribute('index')) {
             $key = 'index_' . $arg->getAttribute('index');
         }
         switch ($arg->getAttribute('type')) {
             case 'service':
                 $arguments[$key] = $this->containerConfiguration->createReferenceFor($arg->getAttribute('id'), $arg->getAttribute('container') ?: null);
                 break;
             case 'expression':
                 $arguments[$key] = new Expression($arg->nodeValue);
                 break;
             case 'collection':
                 $arguments[$key] = $this->getArgumentsAsPhp($arg, $name, false);
                 break;
             case 'string':
                 $arguments[$key] = $arg->nodeValue;
                 break;
             case 'constant':
                 $arguments[$key] = constant($arg->nodeValue);
                 break;
             default:
                 $arguments[$key] = XmlUtils::phpize($arg->nodeValue);
         }
     }
     return $arguments;
 }
Beispiel #8
0
 public function getReferenceByParameters($parameters)
 {
     $viewReference = array();
     $arguments = array();
     foreach ($parameters as $key => $value) {
         $arguments[$key] = '@' . $key . '="' . $value . '"';
     }
     if ($xmlReference = $this->readCache()->xpath("//viewReference[" . implode(' and ', $arguments) . "]")) {
         $viewReference['id'] = XmlUtils::phpize($xmlReference[0]['id']);
         $viewReference['locale'] = XmlUtils::phpize($xmlReference[0]['locale']);
         $viewReference['entityId'] = XmlUtils::phpize($xmlReference[0]['entityId']);
         $viewReference['entityNamespace'] = XmlUtils::phpize($xmlReference[0]['entityNamespace']);
         $viewReference['url'] = XmlUtils::phpize($xmlReference[0]['url']);
         $viewReference['viewId'] = XmlUtils::phpize($xmlReference[0]['viewId']);
         $viewReference['viewNamespace'] = XmlUtils::phpize($xmlReference[0]['viewNamespace']);
         $viewReference['patternId'] = XmlUtils::phpize($xmlReference[0]['patternId']);
         $viewReference['name'] = XmlUtils::phpize($xmlReference[0]['name']);
     } else {
         $viewReference = null;
     }
     return $viewReference;
 }
 /**
  * Converts an attribute as a PHP type.
  *
  * @param SimpleXMLElement $xml
  * @param $name
  * @return mixed
  */
 public function getAttributeAsPhp(SimpleXMLElement $xml, $name)
 {
     return XmlUtils::phpize($xml[$name]);
 }
Beispiel #10
0
 /**
  * Converts an xml value to a PHP type.
  *
  * @param mixed $value
  *
  * @return mixed
  */
 public static function phpize($value)
 {
     return \Symfony\Component\Config\Util\XmlUtils::phpize($value);
 }
Beispiel #11
0
 protected function parseOptionNode(\DOMNodeList $nodes, $path)
 {
     $options = array();
     foreach ($nodes as $node) {
         $options[$this->readAttribute($node, 'name', sprintf('in "%s"', $path))] = XmlUtils::phpize($node->nodeValue);
     }
     return $options;
 }