菜谱项目

XmlResourceCaster.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. class XmlResourceCaster
  18. {
  19. private static $xmlErrors = array(
  20. XML_ERROR_NONE => 'XML_ERROR_NONE',
  21. XML_ERROR_NO_MEMORY => 'XML_ERROR_NO_MEMORY',
  22. XML_ERROR_SYNTAX => 'XML_ERROR_SYNTAX',
  23. XML_ERROR_NO_ELEMENTS => 'XML_ERROR_NO_ELEMENTS',
  24. XML_ERROR_INVALID_TOKEN => 'XML_ERROR_INVALID_TOKEN',
  25. XML_ERROR_UNCLOSED_TOKEN => 'XML_ERROR_UNCLOSED_TOKEN',
  26. XML_ERROR_PARTIAL_CHAR => 'XML_ERROR_PARTIAL_CHAR',
  27. XML_ERROR_TAG_MISMATCH => 'XML_ERROR_TAG_MISMATCH',
  28. XML_ERROR_DUPLICATE_ATTRIBUTE => 'XML_ERROR_DUPLICATE_ATTRIBUTE',
  29. XML_ERROR_JUNK_AFTER_DOC_ELEMENT => 'XML_ERROR_JUNK_AFTER_DOC_ELEMENT',
  30. XML_ERROR_PARAM_ENTITY_REF => 'XML_ERROR_PARAM_ENTITY_REF',
  31. XML_ERROR_UNDEFINED_ENTITY => 'XML_ERROR_UNDEFINED_ENTITY',
  32. XML_ERROR_RECURSIVE_ENTITY_REF => 'XML_ERROR_RECURSIVE_ENTITY_REF',
  33. XML_ERROR_ASYNC_ENTITY => 'XML_ERROR_ASYNC_ENTITY',
  34. XML_ERROR_BAD_CHAR_REF => 'XML_ERROR_BAD_CHAR_REF',
  35. XML_ERROR_BINARY_ENTITY_REF => 'XML_ERROR_BINARY_ENTITY_REF',
  36. XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF => 'XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF',
  37. XML_ERROR_MISPLACED_XML_PI => 'XML_ERROR_MISPLACED_XML_PI',
  38. XML_ERROR_UNKNOWN_ENCODING => 'XML_ERROR_UNKNOWN_ENCODING',
  39. XML_ERROR_INCORRECT_ENCODING => 'XML_ERROR_INCORRECT_ENCODING',
  40. XML_ERROR_UNCLOSED_CDATA_SECTION => 'XML_ERROR_UNCLOSED_CDATA_SECTION',
  41. XML_ERROR_EXTERNAL_ENTITY_HANDLING => 'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
  42. );
  43. public static function castXml($h, array $a, Stub $stub, $isNested)
  44. {
  45. $a['current_byte_index'] = xml_get_current_byte_index($h);
  46. $a['current_column_number'] = xml_get_current_column_number($h);
  47. $a['current_line_number'] = xml_get_current_line_number($h);
  48. $a['error_code'] = xml_get_error_code($h);
  49. if (isset(self::$xmlErrors[$a['error_code']])) {
  50. $a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']);
  51. }
  52. return $a;
  53. }
  54. }