Sen descrición

XmlResourceCaster.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\VarDumper\Caster;
  11. use Symfony\Component\VarDumper\Cloner\Stub;
  12. /**
  13. * Casts XML resources to array representation.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. *
  17. * @final since Symfony 4.4
  18. */
  19. class XmlResourceCaster
  20. {
  21. private const XML_ERRORS = [
  22. \XML_ERROR_NONE => 'XML_ERROR_NONE',
  23. \XML_ERROR_NO_MEMORY => 'XML_ERROR_NO_MEMORY',
  24. \XML_ERROR_SYNTAX => 'XML_ERROR_SYNTAX',
  25. \XML_ERROR_NO_ELEMENTS => 'XML_ERROR_NO_ELEMENTS',
  26. \XML_ERROR_INVALID_TOKEN => 'XML_ERROR_INVALID_TOKEN',
  27. \XML_ERROR_UNCLOSED_TOKEN => 'XML_ERROR_UNCLOSED_TOKEN',
  28. \XML_ERROR_PARTIAL_CHAR => 'XML_ERROR_PARTIAL_CHAR',
  29. \XML_ERROR_TAG_MISMATCH => 'XML_ERROR_TAG_MISMATCH',
  30. \XML_ERROR_DUPLICATE_ATTRIBUTE => 'XML_ERROR_DUPLICATE_ATTRIBUTE',
  31. \XML_ERROR_JUNK_AFTER_DOC_ELEMENT => 'XML_ERROR_JUNK_AFTER_DOC_ELEMENT',
  32. \XML_ERROR_PARAM_ENTITY_REF => 'XML_ERROR_PARAM_ENTITY_REF',
  33. \XML_ERROR_UNDEFINED_ENTITY => 'XML_ERROR_UNDEFINED_ENTITY',
  34. \XML_ERROR_RECURSIVE_ENTITY_REF => 'XML_ERROR_RECURSIVE_ENTITY_REF',
  35. \XML_ERROR_ASYNC_ENTITY => 'XML_ERROR_ASYNC_ENTITY',
  36. \XML_ERROR_BAD_CHAR_REF => 'XML_ERROR_BAD_CHAR_REF',
  37. \XML_ERROR_BINARY_ENTITY_REF => 'XML_ERROR_BINARY_ENTITY_REF',
  38. \XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF => 'XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF',
  39. \XML_ERROR_MISPLACED_XML_PI => 'XML_ERROR_MISPLACED_XML_PI',
  40. \XML_ERROR_UNKNOWN_ENCODING => 'XML_ERROR_UNKNOWN_ENCODING',
  41. \XML_ERROR_INCORRECT_ENCODING => 'XML_ERROR_INCORRECT_ENCODING',
  42. \XML_ERROR_UNCLOSED_CDATA_SECTION => 'XML_ERROR_UNCLOSED_CDATA_SECTION',
  43. \XML_ERROR_EXTERNAL_ENTITY_HANDLING => 'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
  44. ];
  45. public static function castXml($h, array $a, Stub $stub, $isNested)
  46. {
  47. $a['current_byte_index'] = xml_get_current_byte_index($h);
  48. $a['current_column_number'] = xml_get_current_column_number($h);
  49. $a['current_line_number'] = xml_get_current_line_number($h);
  50. $a['error_code'] = xml_get_error_code($h);
  51. if (isset(self::XML_ERRORS[$a['error_code']])) {
  52. $a['error_code'] = new ConstStub(self::XML_ERRORS[$a['error_code']], $a['error_code']);
  53. }
  54. return $a;
  55. }
  56. }