Yaml.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * @package Gedmo.SoftDeleteable.Mapping.Driver
  16. * @subpackage Yaml
  17. * @link http://www.gediminasm.org
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. class Yaml extends File implements Driver
  21. {
  22. /**
  23. * File extension
  24. * @var string
  25. */
  26. protected $_extension = '.dcm.yml';
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function readExtendedMetadata($meta, array &$config)
  31. {
  32. $mapping = $this->_getMapping($meta->name);
  33. if (isset($mapping['gedmo'])) {
  34. $classMapping = $mapping['gedmo'];
  35. if (isset($classMapping['soft_deleteable'])) {
  36. $config['softDeleteable'] = true;
  37. if (!isset($classMapping['soft_deleteable']['field_name'])) {
  38. throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
  39. }
  40. $fieldName = $classMapping['soft_deleteable']['field_name'];
  41. Validator::validateField($meta, $fieldName);
  42. $config['fieldName'] = $fieldName;
  43. }
  44. }
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. protected function _loadMappingFile($file)
  50. {
  51. return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
  52. }
  53. }