PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/src/Symfony/Component/DependencyInjection/SimpleXMLElement.php

https://github.com/casoetan/ServerGroveLiveChat
PHP | 99 lines | 71 code | 12 blank | 16 comment | 14 complexity | c50926e685be59442537b3ca517b3cc1 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection;
  11. /**
  12. * SimpleXMLElement class.
  13. *
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. */
  16. class SimpleXMLElement extends \SimpleXMLElement
  17. {
  18. public function getAttributeAsPhp($name)
  19. {
  20. return self::phpize($this[$name]);
  21. }
  22. public function getArgumentsAsPhp($name)
  23. {
  24. $arguments = array();
  25. foreach ($this->$name as $arg) {
  26. $key = isset($arg['key']) ? (string) $arg['key'] : (!$arguments ? 0 : max(array_keys($arguments)) + 1);
  27. // parameter keys are case insensitive
  28. if ('parameter' == $name) {
  29. $key = strtolower($key);
  30. }
  31. // this is used by DefinitionDecorator to overwrite a specific
  32. // argument of the parent definition
  33. if (isset($arg['index'])) {
  34. $key = 'index_'.$arg['index'];
  35. }
  36. switch ($arg['type']) {
  37. case 'service':
  38. $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
  39. if (isset($arg['on-invalid']) && 'ignore' == $arg['on-invalid']) {
  40. $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
  41. } elseif (isset($arg['on-invalid']) && 'null' == $arg['on-invalid']) {
  42. $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
  43. }
  44. if (isset($arg['strict'])) {
  45. $strict = self::phpize($arg['strict']);
  46. } else {
  47. $strict = true;
  48. }
  49. $arguments[$key] = new Reference((string) $arg['id'], $invalidBehavior, $strict);
  50. break;
  51. case 'collection':
  52. $arguments[$key] = $arg->getArgumentsAsPhp($name);
  53. break;
  54. case 'string':
  55. $arguments[$key] = (string) $arg;
  56. break;
  57. case 'constant':
  58. $arguments[$key] = constant((string) $arg);
  59. break;
  60. default:
  61. $arguments[$key] = self::phpize($arg);
  62. }
  63. }
  64. return $arguments;
  65. }
  66. static public function phpize($value)
  67. {
  68. $value = (string) $value;
  69. $lowercaseValue = strtolower($value);
  70. switch (true) {
  71. case 'null' === $lowercaseValue:
  72. return null;
  73. case ctype_digit($value):
  74. return '0' == $value[0] ? octdec($value) : intval($value);
  75. case 'true' === $lowercaseValue:
  76. return true;
  77. case 'false' === $lowercaseValue:
  78. return false;
  79. case is_numeric($value):
  80. return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
  81. case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
  82. return floatval(str_replace(',', '', $value));
  83. default:
  84. return $value;
  85. }
  86. }
  87. }