Xml.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\Xml as BaseXml,
  4. Gedmo\Exception\InvalidMappingException,
  5. Gedmo\SoftDeleteable\Mapping\Validator;
  6. /**
  7. * This is a xml mapping driver for SoftDeleteable
  8. * behavioral extension. Used for extraction of extended
  9. * metadata from xml specificaly for SoftDeleteable
  10. * extension.
  11. *
  12. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  13. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  14. * @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
  15. * @package Gedmo.Timestampable.Mapping.Driver
  16. * @subpackage Xml
  17. * @link http://www.gediminasm.org
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. class Xml extends BaseXml
  21. {
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function readExtendedMetadata($meta, array &$config)
  26. {
  27. /**
  28. * @var \SimpleXmlElement $xml
  29. */
  30. $xml = $this->_getMapping($meta->name);
  31. $xmlDoctrine = $xml;
  32. $xml = $xml->children(self::GEDMO_NAMESPACE_URI);
  33. if ($xmlDoctrine->getName() == 'entity' || $xmlDoctrine->getName() == 'mapped-superclass') {
  34. if (isset($xml->{'soft-deleteable'})) {
  35. $field = $this->_getAttribute($xml->{'soft-deleteable'}, 'field-name');
  36. if (!$field) {
  37. throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
  38. }
  39. Validator::validateField($meta, $field);
  40. $config['softDeleteable'] = true;
  41. $config['fieldName'] = $field;
  42. }
  43. }
  44. }
  45. }