/**
  * Store a file content.
  *
  * @param  UploadContext $context
  * @param $content
  * @param  array         $metadataMap
  * @return UploadedFile
  */
 public function store(UploadContext $context, $content, array $metadataMap = array())
 {
     $name = $this->namingStrategy->getName($context);
     $directory = $this->storageStrategy->getDirectory($context, $name);
     $path = $directory . '/' . $name;
     $adapter = $this->filesystem->getAdapter();
     if ($adapter instanceof MetadataSupporter) {
         $adapter->setMetadata($path, $this->resolveMetadataMap($context, $metadataMap));
     }
     $this->filesystem->write($path, $content);
     $file = $this->filesystem->get($path);
     return new UploadedFile($this, $file);
 }
 /**
  * {@inheritdoc}
  */
 public function joinColumnName($propertyName)
 {
     $defaultName = $this->defaultNamer->joinColumnName($propertyName);
     /**
      * @var NamingStrategy $concurrentNamer
      */
     foreach ($this->concurrentNamers as $concurrentNamer) {
         if (($newProposal = $concurrentNamer->joinColumnName($propertyName)) != $defaultName) {
             return $newProposal;
         }
     }
     return $defaultName;
 }
 protected function _validateAndCompleteManyToManyMapping(array $mapping)
 {
     $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
     if ($mapping['isOwningSide']) {
         // owning side MUST have a join table
         if (!isset($mapping['joinTable']['name'])) {
             $mapping['joinTable']['name'] = $this->namingStrategy->joinTableName($mapping['sourceEntity'], $mapping['targetEntity'], $mapping['fieldName']);
         }
         if (!isset($mapping['joinTable']['joinColumns'])) {
             $mapping['joinTable']['joinColumns'] = array(array('name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity']), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE'));
         }
         if (!isset($mapping['joinTable']['inverseJoinColumns'])) {
             $mapping['joinTable']['inverseJoinColumns'] = array(array('name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity']), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE'));
         }
         $mapping['joinTableColumns'] = array();
         foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
             if (empty($joinColumn['name'])) {
                 $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']);
             }
             if (empty($joinColumn['referencedColumnName'])) {
                 $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
             }
             if ($joinColumn['name'][0] === '`') {
                 $joinColumn['name'] = trim($joinColumn['name'], '`');
                 $joinColumn['quoted'] = true;
             }
             if ($joinColumn['referencedColumnName'][0] === '`') {
                 $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
                 $joinColumn['quoted'] = true;
             }
             if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') {
                 $mapping['isOnDeleteCascade'] = true;
             }
             $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
             $mapping['joinTableColumns'][] = $joinColumn['name'];
         }
         foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
             if (empty($inverseJoinColumn['name'])) {
                 $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName']);
             }
             if (empty($inverseJoinColumn['referencedColumnName'])) {
                 $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
             }
             if ($inverseJoinColumn['name'][0] === '`') {
                 $inverseJoinColumn['name'] = trim($inverseJoinColumn['name'], '`');
                 $inverseJoinColumn['quoted'] = true;
             }
             if ($inverseJoinColumn['referencedColumnName'][0] === '`') {
                 $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`');
                 $inverseJoinColumn['quoted'] = true;
             }
             if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') {
                 $mapping['isOnDeleteCascade'] = true;
             }
             $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
             $mapping['joinTableColumns'][] = $inverseJoinColumn['name'];
         }
     }
     $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
     if (isset($mapping['orderBy'])) {
         if (!is_array($mapping['orderBy'])) {
             throw new InvalidArgumentException("'orderBy' is expected to be an array, not " . gettype($mapping['orderBy']));
         }
     }
     return $mapping;
 }
 /**
  * Inline the embeddable class
  *
  * @param string $property
  * @param ClassMetadataInfo $embeddable
  */
 public function inlineEmbeddable($property, ClassMetadataInfo $embeddable)
 {
     foreach ($embeddable->fieldMappings as $fieldMapping) {
         $fieldMapping['originalClass'] = isset($fieldMapping['originalClass']) ? $fieldMapping['originalClass'] : $embeddable->name;
         $fieldMapping['declaredField'] = isset($fieldMapping['declaredField']) ? $property . '.' . $fieldMapping['declaredField'] : $property;
         $fieldMapping['originalField'] = isset($fieldMapping['originalField']) ? $fieldMapping['originalField'] : $fieldMapping['fieldName'];
         $fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName'];
         if (!empty($this->embeddedClasses[$property]['columnPrefix'])) {
             $fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName'];
         } elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) {
             $fieldMapping['columnName'] = $this->namingStrategy->embeddedFieldToColumnName($property, $fieldMapping['columnName'], $this->reflClass->name, $embeddable->reflClass->name);
         }
         $this->mapField($fieldMapping);
     }
 }
예제 #5
0
 /**
  * @dataProvider dataJoinKeyColumnName
  *
  * @param NamingStrategy $strategy
  * @param string $expected
  * @param string $propertyEntityName
  * @param string $referencedColumnName
  * @param string $propertyName
  */
 public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null)
 {
     $this->assertEquals($expected, $strategy->joinKeyColumnName($propertyEntityName, $referencedColumnName, $propertyName));
 }
예제 #6
0
 /**
  * @return string
  */
 public function getReferenceColumn()
 {
     return $this->referenceColumn ?: $this->namingStrategy->referenceColumnName();
 }