class SimpleXMLElement

SimpleXMLElement class.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of SimpleXMLElement

1 file declares its use of SimpleXMLElement
XmlFileLoader.php in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
1 string reference to 'SimpleXMLElement'
UpdateCoreTest::testServiceUnavailable in drupal/core/modules/update/lib/Drupal/update/Tests/UpdateCoreTest.php
Tests the Update Manager module when the update server returns 503 errors.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/SimpleXMLElement.php, line 19

Namespace

Symfony\Component\DependencyInjection
View source
class SimpleXMLElement extends \SimpleXMLElement {

  /**
   * Converts an attribute as a php type.
   *
   * @param string $name
   *
   * @return mixed
   */
  public function getAttributeAsPhp($name) {
    return self::phpize($this[$name]);
  }

  /**
   * Returns arguments as valid php types.
   *
   * @param string  $name
   * @param Boolean $lowercase
   *
   * @return mixed
   */
  public function getArgumentsAsPhp($name, $lowercase = true) {
    $arguments = array();
    foreach ($this->{$name} as $arg) {
      if (isset($arg['name'])) {
        $arg['key'] = (string) $arg['name'];
      }
      $key = isset($arg['key']) ? (string) $arg['key'] : (!$arguments ? 0 : max(array_keys($arguments)) + 1);

      // 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 (isset($arg['index'])) {
        $key = 'index_' . $arg['index'];
      }
      switch ($arg['type']) {
        case 'service':
          $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
          if (isset($arg['on-invalid']) && 'ignore' == $arg['on-invalid']) {
            $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
          }
          elseif (isset($arg['on-invalid']) && 'null' == $arg['on-invalid']) {
            $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
          }
          if (isset($arg['strict'])) {
            $strict = self::phpize($arg['strict']);
          }
          else {
            $strict = true;
          }
          $arguments[$key] = new Reference((string) $arg['id'], $invalidBehavior, $strict);
          break;
        case 'collection':
          $arguments[$key] = $arg
            ->getArgumentsAsPhp($name, false);
          break;
        case 'string':
          $arguments[$key] = (string) $arg;
          break;
        case 'constant':
          $arguments[$key] = constant((string) $arg);
          break;
        default:
          $arguments[$key] = self::phpize($arg);
      }
    }
    return $arguments;
  }

  /**
   * Converts an xml value to a php type.
   *
   * @param mixed $value
   *
   * @return mixed
   */
  public static function phpize($value) {
    $value = (string) $value;
    $lowercaseValue = strtolower($value);
    switch (true) {
      case 'null' === $lowercaseValue:
        return null;
      case ctype_digit($value):
        $raw = $value;
        $cast = intval($value);
        return '0' == $value[0] ? octdec($value) : ((string) $raw == (string) $cast ? $cast : $raw);
      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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpleXMLElement::getArgumentsAsPhp public function Returns arguments as valid php types. Overrides SimpleXMLElement::getArgumentsAsPhp 1
SimpleXMLElement::getAttributeAsPhp public function Converts an attribute as a php type. Overrides SimpleXMLElement::getAttributeAsPhp 1
SimpleXMLElement::phpize public static function Converts an xml value to a php type. Overrides SimpleXMLElement::phpize 1