Xml.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\Xml as BaseXml;
  4. use Gedmo\Exception\InvalidMappingException;
  5. use 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 specifically 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 (in_array($xmlDoctrine->getName(), array('mapped-superclass', 'entity', 'document', 'embedded-document'))) {
  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. $config['timeAware'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'time-aware');
  42. }
  43. $config['hardDelete'] = true;
  44. if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'hard-delete')) {
  45. $config['hardDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'hard-delete');
  46. }
  47. }
  48. }
  49. }
  50. }