2010-01-04 14:26:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Components\DependencyInjection;
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-01-04 14:26:20 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2010-04-07 01:51:29 +01:00
|
|
|
/**
|
|
|
|
* SimpleXMLElement class.
|
|
|
|
*
|
|
|
|
* @package Symfony
|
|
|
|
* @subpackage Components_DependencyInjection
|
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
2010-01-04 14:26:20 +00:00
|
|
|
class SimpleXMLElement extends \SimpleXMLElement
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getAttributeAsPhp($name)
|
2010-01-04 14:26:20 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return self::phpize($this[$name]);
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getArgumentsAsPhp($name)
|
|
|
|
{
|
|
|
|
$arguments = array();
|
|
|
|
foreach ($this->$name as $arg)
|
|
|
|
{
|
|
|
|
$key = isset($arg['key']) ? (string) $arg['key'] : (!$arguments ? 0 : max(array_keys($arguments)) + 1);
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
// parameter keys are case insensitive
|
|
|
|
if ('parameter' == $name)
|
|
|
|
{
|
|
|
|
$key = strtolower($key);
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
switch ($arg['type'])
|
|
|
|
{
|
|
|
|
case 'service':
|
|
|
|
$invalidBehavior = Container::EXCEPTION_ON_INVALID_REFERENCE;
|
|
|
|
if (isset($arg['on-invalid']) && 'ignore' == $arg['on-invalid'])
|
|
|
|
{
|
|
|
|
$invalidBehavior = Container::IGNORE_ON_INVALID_REFERENCE;
|
|
|
|
}
|
|
|
|
elseif (isset($arg['on-invalid']) && 'null' == $arg['on-invalid'])
|
|
|
|
{
|
|
|
|
$invalidBehavior = Container::NULL_ON_INVALID_REFERENCE;
|
|
|
|
}
|
|
|
|
$arguments[$key] = new Reference((string) $arg['id'], $invalidBehavior);
|
|
|
|
break;
|
|
|
|
case 'collection':
|
|
|
|
$arguments[$key] = $arg->getArgumentsAsPhp($name);
|
|
|
|
break;
|
|
|
|
case 'string':
|
|
|
|
$arguments[$key] = (string) $arg;
|
|
|
|
break;
|
|
|
|
case 'constant':
|
|
|
|
$arguments[$key] = constant((string) $arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$arguments[$key] = self::phpize($arg);
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
return $arguments;
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
static public function phpize($value)
|
2010-01-04 14:26:20 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$value = (string) $value;
|
|
|
|
$lowercaseValue = strtolower($value);
|
|
|
|
|
|
|
|
switch (true)
|
|
|
|
{
|
|
|
|
case 'null' === $lowercaseValue:
|
|
|
|
return null;
|
|
|
|
case ctype_digit($value):
|
|
|
|
return '0' == $value[0] ? octdec($value) : intval($value);
|
|
|
|
case 'true' === $lowercaseValue:
|
|
|
|
return true;
|
|
|
|
case 'false' === $lowercaseValue:
|
|
|
|
return false;
|
|
|
|
case is_numeric($value):
|
|
|
|
return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
|
|
|
|
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
|
|
|
|
return floatval(str_replace(',', '', $value));
|
|
|
|
default:
|
|
|
|
return $value;
|
|
|
|
}
|
2010-01-04 14:26:20 +00:00
|
|
|
}
|
|
|
|
}
|