Xml.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Gedmo\Uploadable\Mapping\Driver;
  3. use Gedmo\Mapping\Driver\Xml as BaseXml,
  4. Gedmo\Exception\InvalidMappingException,
  5. Gedmo\Uploadable\Mapping\Validator;
  6. /**
  7. * This is a xml mapping driver for Uploadable
  8. * behavioral extension. Used for extraction of extended
  9. * metadata from xml specificaly for Uploadable
  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.Uploadable.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->uploadable)) {
  35. $xmlUploadable = $xml->uploadable;
  36. $config['uploadable'] = true;
  37. $config['allowOverwrite'] = $this->_isAttributeSet($xmlUploadable, 'allow-overwrite') ?
  38. (bool) $this->_getAttribute($xmlUploadable, 'allow-overwrite') : false;
  39. $config['appendNumber'] = $this->_isAttributeSet($xmlUploadable, 'append-number') ?
  40. (bool) $this->_getAttribute($xmlUploadable, 'append-number') : false;
  41. $config['path'] = $this->_isAttributeSet($xmlUploadable, 'path') ?
  42. $this->_getAttribute($xml->{'uploadable'}, 'path') : '';
  43. $config['pathMethod'] = $this->_isAttributeSet($xmlUploadable, 'path-method') ?
  44. $this->_getAttribute($xml->{'uploadable'}, 'path-method') : '';
  45. $config['callback'] = $this->_isAttributeSet($xmlUploadable, 'callback') ?
  46. $this->_getAttribute($xml->{'uploadable'}, 'callback') : '';
  47. $config['fileInfoProperty'] = $this->_getAttribute($xml->{'uploadable'}, 'file-info-property');
  48. $config['fileMimeTypeField'] = false;
  49. $config['filePathField'] = false;
  50. $config['fileSizeField'] = false;
  51. $config['filenameGenerator'] = $this->_isAttributeSet($xmlUploadable, 'filename-generator') ?
  52. $this->_getAttribute($xml->{'uploadable'}, 'filename-generator') :
  53. Validator::FILENAME_GENERATOR_NONE;
  54. if (isset($xmlDoctrine->field)) {
  55. foreach ($xmlDoctrine->field as $mapping) {
  56. $mappingDoctrine = $mapping;
  57. $mapping = $mapping->children(self::GEDMO_NAMESPACE_URI);
  58. $field = $this->_getAttribute($mappingDoctrine, 'name');
  59. if (isset($mapping->{'uploadable-file-mime-type'})) {
  60. $config['fileMimeTypeField'] = $field;
  61. } else if (isset($mapping->{'uploadable-file-size'})) {
  62. $config['fileSizeField'] = $field;
  63. } else if (isset($mapping->{'uploadable-file-path'})) {
  64. $config['filePathField'] = $field;
  65. }
  66. }
  67. }
  68. Validator::validateConfiguration($meta, $config);
  69. }
  70. }
  71. }
  72. }