Xml.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class Xml extends BaseXml
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function readExtendedMetadata($meta, array &$config)
  23. {
  24. /**
  25. * @var \SimpleXmlElement $xml
  26. */
  27. $xml = $this->_getMapping($meta->name);
  28. $xmlDoctrine = $xml;
  29. $xml = $xml->children(self::GEDMO_NAMESPACE_URI);
  30. if ($xmlDoctrine->getName() == 'entity' || $xmlDoctrine->getName() == 'mapped-superclass') {
  31. if (isset($xml->{'soft-deleteable'})) {
  32. $field = $this->_getAttribute($xml->{'soft-deleteable'}, 'field-name');
  33. if (!$field) {
  34. throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
  35. }
  36. Validator::validateField($meta, $field);
  37. $config['softDeleteable'] = true;
  38. $config['fieldName'] = $field;
  39. $config['timeAware'] = false;
  40. if($this->_isAttributeSet($xml->{'soft-deleteable'}, 'time-aware')) {
  41. if (!is_bool($this->_getAttribute($xml->{'soft-deleteable'}, 'time-aware'))) {
  42. throw new InvalidMappingException("timeAware must be boolean. ".gettype($this->_getAttribute($xml->{'soft-deleteable'}, 'time-aware'))." provided.");
  43. }
  44. $config['timeAware'] = $this->_getAttribute($xml->{'soft-deleteable'}, 'time-aware');
  45. }
  46. }
  47. }
  48. }
  49. }