123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace Gedmo\Uploadable\Mapping\Driver;
- use Gedmo\Mapping\Driver\AnnotationDriverInterface,
- Doctrine\Common\Persistence\Mapping\ClassMetadata,
- Gedmo\Exception\InvalidMappingException,
- Gedmo\Uploadable\Mapping\Validator;
- /**
- * This is an annotation mapping driver for Uploadable
- * behavioral extension. Used for extraction of extended
- * metadata from Annotations specificaly for SoftDeleteable
- * extension.
- *
- * @author Gustavo Falco <comfortablynumb84@gmail.com>
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Uploadable.Mapping.Driver
- * @subpackage Annotation
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- class Annotation implements AnnotationDriverInterface
- {
- /**
- * Annotation to define that this object is loggable
- */
- const UPLOADABLE = 'Gedmo\\Mapping\\Annotation\\Uploadable';
- const UPLOADABLE_FILE_MIME_TYPE = 'Gedmo\\Mapping\\Annotation\\UploadableFileMimeType';
- const UPLOADABLE_FILE_PATH = 'Gedmo\\Mapping\\Annotation\\UploadableFilePath';
- const UPLOADABLE_FILE_SIZE = 'Gedmo\\Mapping\\Annotation\\UploadableFileSize';
- /**
- * Annotation reader instance
- *
- * @var object
- */
- private $reader;
- /**
- * original driver if it is available
- */
- protected $_originalDriver = null;
- /**
- * {@inheritDoc}
- */
- public function setAnnotationReader($reader)
- {
- $this->reader = $reader;
- }
- /**
- * {@inheritDoc}
- */
- public function validateFullMetadata(ClassMetadata $meta, array $config)
- {
- // Nothing here for now
- }
- /**
- * {@inheritDoc}
- */
- public function readExtendedMetadata($meta, array &$config)
- {
- $class = $meta->getReflectionClass();
-
- if (!$class) {
- // based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
- // this happens when running annotation driver in combination with
- // static reflection services. This is not the nicest fix
- $class = new \ReflectionClass($meta->name);
- }
- // class annotations
- if ($annot = $this->reader->getClassAnnotation($class, self::UPLOADABLE)) {
- $config['uploadable'] = true;
- $config['allowOverwrite'] = $annot->allowOverwrite;
- $config['appendNumber'] = $annot->appendNumber;
- $config['path'] = $annot->path;
- $config['pathMethod'] = $annot->pathMethod;
- $config['fileMimeTypeField'] = false;
- $config['filePathField'] = false;
- $config['fileSizeField'] = false;
- $config['fileInfoProperty'] = $annot->fileInfoProperty;
- foreach ($class->getProperties() as $prop) {
- if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_MIME_TYPE)) {
- $config['fileMimeTypeField'] = $prop->getName();
- }
- if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_PATH)) {
- $config['filePathField'] = $prop->getName();
- }
- if ($this->reader->getPropertyAnnotation($prop, self::UPLOADABLE_FILE_SIZE)) {
- $config['fileSizeField'] = $prop->getName();
- }
- }
- Validator::validateConfiguration($meta, $config);
- }
- /*
- // Code in case we need to identify entities which are not Uploadables, but have associations
- // with other Uploadable entities
- } else {
- // We need to check if this class has a relation with Uploadable entities
- $associations = $meta->getAssociationMappings();
- foreach ($associations as $field => $association) {
- $refl = new \ReflectionClass($association['targetEntity']);
- if ($annot = $this->reader->getClassAnnotation($refl, self::UPLOADABLE)) {
- $config['hasUploadables'] = true;
- if (!isset($config['uploadables'])) {
- $config['uploadables'] = array();
- }
- $config['uploadables'][] = array(
- 'class' => $association['targetEntity'],
- 'property' => $association['fieldName']
- );
- }
- }
- }*/
- $this->validateFullMetadata($meta, $config);
- }
- /**
- * Passes in the mapping read by original driver
- *
- * @param $driver
- * @return void
- */
- public function setOriginalDriver($driver)
- {
- $this->_originalDriver = $driver;
- }
- }
|