4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection;
14 @trigger_error('The '.__NAMESPACE__.'\SimpleXMLElement class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
16 use Symfony\Component\Config\Util\XmlUtils;
17 use Symfony\Component\ExpressionLanguage\Expression;
20 * SimpleXMLElement class.
22 * @author Fabien Potencier <fabien@symfony.com>
24 * @deprecated since version 2.5, to be removed in 3.0.
26 class SimpleXMLElement extends \SimpleXMLElement
29 * Converts an attribute as a PHP type.
35 public function getAttributeAsPhp($name)
37 return self::phpize($this[$name]);
41 * Returns arguments as valid PHP types.
44 * @param bool $lowercase
48 public function getArgumentsAsPhp($name, $lowercase = true)
51 foreach ($this->$name as $arg) {
52 if (isset($arg['name'])) {
53 $arg['key'] = (string) $arg['name'];
55 $key = isset($arg['key']) ? (string) $arg['key'] : (!$arguments ? 0 : max(array_keys($arguments)) + 1);
57 // parameter keys are case insensitive
58 if ('parameter' == $name && $lowercase) {
59 $key = strtolower($key);
62 // this is used by DefinitionDecorator to overwrite a specific
63 // argument of the parent definition
64 if (isset($arg['index'])) {
65 $key = 'index_'.$arg['index'];
68 switch ($arg['type']) {
70 $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
71 if (isset($arg['on-invalid']) && 'ignore' == $arg['on-invalid']) {
72 $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
73 } elseif (isset($arg['on-invalid']) && 'null' == $arg['on-invalid']) {
74 $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
77 if (isset($arg['strict'])) {
78 $strict = self::phpize($arg['strict']);
83 $arguments[$key] = new Reference((string) $arg['id'], $invalidBehavior, $strict);
86 $arguments[$key] = new Expression((string) $arg);
89 $arguments[$key] = $arg->getArgumentsAsPhp($name, false);
92 $arguments[$key] = (string) $arg;
95 $arguments[$key] = constant((string) $arg);
98 $arguments[$key] = self::phpize($arg);
106 * Converts an xml value to a PHP type.
108 * @param mixed $value
112 public static function phpize($value)
114 return XmlUtils::phpize($value);