Yaml.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\File,
  4. Gedmo\Mapping\Driver,
  5. Gedmo\Exception\InvalidMappingException,
  6. Gedmo\SoftDeleteable\Mapping\Validator;
  7. /**
  8. * This is a yaml mapping driver for Timestampable
  9. * behavioral extension. Used for extraction of extended
  10. * metadata from yaml specificaly for Timestampable
  11. * extension.
  12. *
  13. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  14. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class Yaml extends File implements Driver
  18. {
  19. /**
  20. * File extension
  21. * @var string
  22. */
  23. protected $_extension = '.dcm.yml';
  24. /**
  25. * {@inheritDoc}
  26. */
  27. public function readExtendedMetadata($meta, array &$config)
  28. {
  29. $mapping = $this->_getMapping($meta->name);
  30. if (isset($mapping['gedmo'])) {
  31. $classMapping = $mapping['gedmo'];
  32. if (isset($classMapping['soft_deleteable'])) {
  33. $config['softDeleteable'] = true;
  34. if (!isset($classMapping['soft_deleteable']['field_name'])) {
  35. throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
  36. }
  37. $fieldName = $classMapping['soft_deleteable']['field_name'];
  38. Validator::validateField($meta, $fieldName);
  39. $config['fieldName'] = $fieldName;
  40. $config['timeAware'] = false;
  41. if(isset($classMapping['soft_deleteable']['time_aware'])) {
  42. if (!is_bool($classMapping['soft_deleteable']['time_aware'])) {
  43. throw new InvalidMappingException("timeAware must be boolean. ".gettype($classMapping['soft_deleteable']['time_aware'])." provided.");
  44. }
  45. $config['timeAware'] = $classMapping['soft_deleteable']['time_aware'];
  46. }
  47. }
  48. }
  49. }
  50. /**
  51. * {@inheritDoc}
  52. */
  53. protected function _loadMappingFile($file)
  54. {
  55. return \Symfony\Component\Yaml\Yaml::parse($file);
  56. }
  57. }