2009-02-17 11:01:34 +03:00
|
|
|
<?php
|
2009-05-05 21:20:55 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
2009-02-17 11:01:34 +03:00
|
|
|
|
|
|
|
namespace Doctrine\ORM\Mapping\Driver;
|
|
|
|
|
2009-10-05 08:11:29 +04:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
2009-09-29 19:54:16 +04:00
|
|
|
Doctrine\ORM\Mapping\MappingException;
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* The YamlDriver reads the mapping metadata from yaml schema files.
|
2008-02-04 00:29:57 +03:00
|
|
|
*
|
2010-01-28 15:46:12 +03:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision$
|
|
|
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2008-02-04 00:29:57 +03:00
|
|
|
*/
|
2009-06-06 01:40:47 +04:00
|
|
|
class YamlDriver extends AbstractFileDriver
|
2008-02-04 00:29:57 +03:00
|
|
|
{
|
2010-01-28 15:46:12 +03:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2010-01-28 22:38:16 +03:00
|
|
|
protected $_fileExtension = '.dcm.yml';
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2010-01-28 15:46:12 +03:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-10-05 08:11:29 +04:00
|
|
|
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
2009-02-17 11:01:34 +03:00
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$element = $this->getElement($className);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
if ($element['type'] == 'entity') {
|
2009-08-25 01:05:55 +04:00
|
|
|
$metadata->setCustomRepositoryClass(
|
2009-10-04 23:35:47 +04:00
|
|
|
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
|
2009-08-25 01:05:55 +04:00
|
|
|
);
|
|
|
|
} else if ($element['type'] == 'mappedSuperclass') {
|
|
|
|
$metadata->isMappedSuperclass = true;
|
|
|
|
} else {
|
2010-03-26 21:29:20 +03:00
|
|
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate root level properties
|
|
|
|
if (isset($element['table'])) {
|
2010-03-29 17:20:41 +04:00
|
|
|
$metadata->table['name'] = $element['table'];
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($element['schema'])) {
|
2010-03-29 17:20:41 +04:00
|
|
|
$metadata->table['schema'] = $element['schema'];
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($element['inheritanceType'])) {
|
2009-09-30 08:35:43 +04:00
|
|
|
$metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate discriminatorColumn
|
|
|
|
if (isset($element['discriminatorColumn'])) {
|
|
|
|
$discrColumn = $element['discriminatorColumn'];
|
|
|
|
$metadata->setDiscriminatorColumn(array(
|
|
|
|
'name' => $discrColumn['name'],
|
|
|
|
'type' => $discrColumn['type'],
|
|
|
|
'length' => $discrColumn['length']
|
|
|
|
));
|
|
|
|
}
|
2009-08-24 22:33:59 +04:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate discriminatorMap
|
|
|
|
if (isset($element['discriminatorMap'])) {
|
|
|
|
$metadata->setDiscriminatorMap($element['discriminatorMap']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate changeTrackingPolicy
|
|
|
|
if (isset($element['changeTrackingPolicy'])) {
|
2009-09-13 03:17:49 +04:00
|
|
|
$metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_'
|
2009-09-30 08:35:43 +04:00
|
|
|
. strtoupper($element['changeTrackingPolicy'])));
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate indexes
|
|
|
|
if (isset($element['indexes'])) {
|
2009-10-07 02:38:34 +04:00
|
|
|
foreach ($element['indexes'] as $name => $index) {
|
|
|
|
if ( ! isset($index['name'])) {
|
|
|
|
$index['name'] = $name;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-07 02:38:34 +04:00
|
|
|
if (is_string($index['columns'])) {
|
|
|
|
$columns = explode(',', $index['columns']);
|
|
|
|
} else {
|
|
|
|
$columns = $index['columns'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
$metadata->table['indexes'][$index['name']] = array(
|
2009-10-07 02:38:34 +04:00
|
|
|
'columns' => $columns
|
2009-09-04 22:35:40 +04:00
|
|
|
);
|
2009-08-24 22:33:59 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-08-24 22:33:59 +04:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate uniqueConstraints
|
|
|
|
if (isset($element['uniqueConstraints'])) {
|
2010-01-06 16:23:56 +03:00
|
|
|
foreach ($element['uniqueConstraints'] as $name => $unique) {
|
|
|
|
if ( ! isset($unique['name'])) {
|
|
|
|
$unique['name'] = $name;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2010-01-06 16:23:56 +03:00
|
|
|
if (is_string($unique['columns'])) {
|
2009-10-07 02:38:34 +04:00
|
|
|
$columns = explode(',', $unique['columns']);
|
|
|
|
} else {
|
|
|
|
$columns = $unique['columns'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2010-03-29 17:20:41 +04:00
|
|
|
$metadata->table['uniqueConstraints'][$unique['name']] = array(
|
2010-01-06 16:23:56 +03:00
|
|
|
'columns' => $columns
|
|
|
|
);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2009-10-04 23:35:47 +04:00
|
|
|
if (isset($element['id'])) {
|
|
|
|
// Evaluate identifier settings
|
|
|
|
foreach ($element['id'] as $name => $idElement) {
|
2010-05-01 05:28:18 +04:00
|
|
|
if (!isset($idElement['type'])) {
|
|
|
|
throw MappingException::propertyTypeIsRequired($className, $name);
|
|
|
|
}
|
|
|
|
|
2009-10-04 23:35:47 +04:00
|
|
|
$mapping = array(
|
|
|
|
'id' => true,
|
|
|
|
'fieldName' => $name,
|
|
|
|
'type' => $idElement['type']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-04 23:35:47 +04:00
|
|
|
if (isset($idElement['column'])) {
|
|
|
|
$mapping['columnName'] = $idElement['column'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-04 23:35:47 +04:00
|
|
|
$metadata->mapField($mapping);
|
|
|
|
|
|
|
|
if (isset($idElement['generator'])) {
|
|
|
|
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
|
|
|
|
. strtoupper($idElement['generator']['strategy'])));
|
|
|
|
}
|
2010-05-01 05:28:18 +04:00
|
|
|
// Check for SequenceGenerator/TableGenerator definition
|
|
|
|
if (isset($idElement['sequenceGenerator'])) {
|
|
|
|
$metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']);
|
|
|
|
} else if (isset($idElement['tableGenerator'])) {
|
|
|
|
throw MappingException::tableIdGeneratorNotImplemented($className);
|
|
|
|
}
|
2009-10-04 23:35:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate fields
|
|
|
|
if (isset($element['fields'])) {
|
|
|
|
foreach ($element['fields'] as $name => $fieldMapping) {
|
2010-02-03 00:17:00 +03:00
|
|
|
if (!isset($fieldMapping['type'])) {
|
|
|
|
throw MappingException::propertyTypeIsRequired($className, $name);
|
|
|
|
}
|
|
|
|
|
2009-10-07 08:07:23 +04:00
|
|
|
$e = explode('(', $fieldMapping['type']);
|
|
|
|
$fieldMapping['type'] = $e[0];
|
|
|
|
if (isset($e[1])) {
|
|
|
|
$fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1);
|
|
|
|
}
|
2009-06-06 01:40:47 +04:00
|
|
|
$mapping = array(
|
|
|
|
'fieldName' => $name,
|
2009-08-25 01:05:55 +04:00
|
|
|
'type' => $fieldMapping['type']
|
2009-06-06 01:40:47 +04:00
|
|
|
);
|
2009-10-07 08:07:23 +04:00
|
|
|
if (isset($fieldMapping['id'])) {
|
|
|
|
$mapping['id'] = true;
|
|
|
|
if (isset($fieldMapping['generator']['strategy'])) {
|
|
|
|
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
|
|
|
|
. strtoupper($fieldMapping['generator']['strategy'])));
|
|
|
|
}
|
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($fieldMapping['column'])) {
|
|
|
|
$mapping['columnName'] = $fieldMapping['column'];
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($fieldMapping['length'])) {
|
|
|
|
$mapping['length'] = $fieldMapping['length'];
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['precision'])) {
|
|
|
|
$mapping['precision'] = $fieldMapping['precision'];
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['scale'])) {
|
|
|
|
$mapping['scale'] = $fieldMapping['scale'];
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-09-08 22:12:01 +04:00
|
|
|
if (isset($fieldMapping['unique'])) {
|
2009-10-04 23:35:47 +04:00
|
|
|
$mapping['unique'] = (bool)$fieldMapping['unique'];
|
2009-09-08 22:12:01 +04:00
|
|
|
}
|
2009-09-04 22:35:40 +04:00
|
|
|
if (isset($fieldMapping['options'])) {
|
|
|
|
$mapping['options'] = $fieldMapping['options'];
|
|
|
|
}
|
2009-12-19 16:52:36 +03:00
|
|
|
if (isset($fieldMapping['nullable'])) {
|
|
|
|
$mapping['nullable'] = $fieldMapping['nullable'];
|
2009-10-04 23:35:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
|
|
|
$metadata->setVersionMapping($mapping);
|
|
|
|
}
|
2010-01-21 01:35:18 +03:00
|
|
|
if (isset($fieldMapping['columnDefinition'])) {
|
|
|
|
$mapping['columnDefinition'] = $fieldMapping['columnDefinition'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$metadata->mapField($mapping);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate oneToOne relationships
|
|
|
|
if (isset($element['oneToOne'])) {
|
|
|
|
foreach ($element['oneToOne'] as $name => $oneToOneElement) {
|
|
|
|
$mapping = array(
|
|
|
|
'fieldName' => $name,
|
|
|
|
'targetEntity' => $oneToOneElement['targetEntity']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-12 16:54:14 +04:00
|
|
|
if (isset($oneToOneElement['fetch'])) {
|
|
|
|
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToOneElement['fetch']);
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($oneToOneElement['mappedBy'])) {
|
|
|
|
$mapping['mappedBy'] = $oneToOneElement['mappedBy'];
|
|
|
|
} else {
|
2010-04-10 02:00:36 +04:00
|
|
|
if (isset($oneToOneElement['inversedBy'])) {
|
|
|
|
$mapping['inversedBy'] = $oneToOneElement['inversedBy'];
|
|
|
|
}
|
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
$joinColumns = array();
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($oneToOneElement['joinColumn'])) {
|
|
|
|
$joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement['joinColumn']);
|
|
|
|
} else if (isset($oneToOneElement['joinColumns'])) {
|
|
|
|
foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) {
|
2009-06-06 01:40:47 +04:00
|
|
|
if (!isset($joinColumnElement['name'])) {
|
|
|
|
$joinColumnElement['name'] = $name;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
|
|
|
|
}
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
$mapping['joinColumns'] = $joinColumns;
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($oneToOneElement['cascade'])) {
|
2010-01-22 18:10:13 +03:00
|
|
|
$mapping['cascade'] = $oneToOneElement['cascade'];
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$metadata->mapOneToOne($mapping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate oneToMany relationships
|
|
|
|
if (isset($element['oneToMany'])) {
|
|
|
|
foreach ($element['oneToMany'] as $name => $oneToManyElement) {
|
|
|
|
$mapping = array(
|
|
|
|
'fieldName' => $name,
|
|
|
|
'targetEntity' => $oneToManyElement['targetEntity'],
|
|
|
|
'mappedBy' => $oneToManyElement['mappedBy']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-12 16:54:14 +04:00
|
|
|
if (isset($oneToManyElement['fetch'])) {
|
|
|
|
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToManyElement['fetch']);
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($oneToManyElement['cascade'])) {
|
2010-01-22 18:10:13 +03:00
|
|
|
$mapping['cascade'] = $oneToManyElement['cascade'];
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2010-02-14 22:38:22 +03:00
|
|
|
|
|
|
|
if (isset($oneToManyElement['orderBy'])) {
|
|
|
|
$mapping['orderBy'] = $oneToManyElement['orderBy'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$metadata->mapOneToMany($mapping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate manyToOne relationships
|
|
|
|
if (isset($element['manyToOne'])) {
|
|
|
|
foreach ($element['manyToOne'] as $name => $manyToOneElement) {
|
|
|
|
$mapping = array(
|
2010-03-15 22:29:07 +03:00
|
|
|
'fieldName' => $name,
|
2009-08-25 01:05:55 +04:00
|
|
|
'targetEntity' => $manyToOneElement['targetEntity']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-12 16:54:14 +04:00
|
|
|
if (isset($manyToOneElement['fetch'])) {
|
|
|
|
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneElement['fetch']);
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2010-04-10 02:00:36 +04:00
|
|
|
if (isset($manyToOneElement['inversedBy'])) {
|
|
|
|
$mapping['inversedBy'] = $manyToOneElement['inversedBy'];
|
|
|
|
}
|
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$joinColumns = array();
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($manyToOneElement['joinColumn'])) {
|
|
|
|
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']);
|
|
|
|
} else if (isset($manyToOneElement['joinColumns'])) {
|
|
|
|
foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) {
|
|
|
|
if (!isset($joinColumnElement['name'])) {
|
|
|
|
$joinColumnElement['name'] = $name;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$mapping['joinColumns'] = $joinColumns;
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($manyToOneElement['cascade'])) {
|
2010-01-22 18:10:13 +03:00
|
|
|
$mapping['cascade'] = $manyToOneElement['cascade'];
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$metadata->mapManyToOne($mapping);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
// Evaluate manyToMany relationships
|
|
|
|
if (isset($element['manyToMany'])) {
|
|
|
|
foreach ($element['manyToMany'] as $name => $manyToManyElement) {
|
|
|
|
$mapping = array(
|
|
|
|
'fieldName' => $name,
|
|
|
|
'targetEntity' => $manyToManyElement['targetEntity']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-10-12 16:54:14 +04:00
|
|
|
if (isset($manyToManyElement['fetch'])) {
|
|
|
|
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToManyElement['fetch']);
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($manyToManyElement['mappedBy'])) {
|
|
|
|
$mapping['mappedBy'] = $manyToManyElement['mappedBy'];
|
|
|
|
} else if (isset($manyToManyElement['joinTable'])) {
|
2010-04-10 02:00:36 +04:00
|
|
|
if (isset($manyToManyElement['inversedBy'])) {
|
|
|
|
$mapping['inversedBy'] = $manyToManyElement['inversedBy'];
|
|
|
|
}
|
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$joinTableElement = $manyToManyElement['joinTable'];
|
|
|
|
$joinTable = array(
|
|
|
|
'name' => $joinTableElement['name']
|
2009-06-06 01:40:47 +04:00
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($joinTableElement['schema'])) {
|
|
|
|
$joinTable['schema'] = $joinTableElement['schema'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
|
|
|
|
if (!isset($joinColumnElement['name'])) {
|
|
|
|
$joinColumnElement['name'] = $name;
|
2009-02-17 11:01:34 +03:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) {
|
|
|
|
if (!isset($joinColumnElement['name'])) {
|
|
|
|
$joinColumnElement['name'] = $name;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$mapping['joinTable'] = $joinTable;
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
if (isset($manyToManyElement['cascade'])) {
|
2010-01-22 18:10:13 +03:00
|
|
|
$mapping['cascade'] = $manyToManyElement['cascade'];
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
if (isset($manyToManyElement['orderBy'])) {
|
|
|
|
$mapping['orderBy'] = $manyToManyElement['orderBy'];
|
|
|
|
}
|
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
$metadata->mapManyToMany($mapping);
|
2009-02-17 11:01:34 +03:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-06-06 01:40:47 +04:00
|
|
|
|
2009-08-25 13:14:08 +04:00
|
|
|
// Evaluate lifeCycleCallbacks
|
|
|
|
if (isset($element['lifecycleCallbacks'])) {
|
2010-03-15 22:29:07 +03:00
|
|
|
foreach ($element['lifecycleCallbacks'] as $type => $methods) {
|
|
|
|
foreach ($methods as $method) {
|
2010-04-10 02:00:36 +04:00
|
|
|
$metadata->addLifecycleCallback($method, constant('Doctrine\ORM\Events::' . $type));
|
2010-03-15 22:29:07 +03:00
|
|
|
}
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2009-02-17 11:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
/**
|
|
|
|
* Constructs a joinColumn mapping array based on the information
|
2009-06-06 01:58:05 +04:00
|
|
|
* found in the given join column element.
|
2010-03-15 22:29:07 +03:00
|
|
|
*
|
2009-06-06 01:58:05 +04:00
|
|
|
* @param $joinColumnElement The array join column element
|
2009-06-06 01:40:47 +04:00
|
|
|
* @return array The mapping array.
|
|
|
|
*/
|
|
|
|
private function _getJoinColumnMapping($joinColumnElement)
|
2008-02-04 00:29:57 +03:00
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$joinColumn = array(
|
|
|
|
'name' => $joinColumnElement['name'],
|
|
|
|
'referencedColumnName' => $joinColumnElement['referencedColumnName']
|
|
|
|
);
|
2010-03-15 22:29:07 +03:00
|
|
|
|
|
|
|
if (isset($joinColumnElement['fieldName'])) {
|
|
|
|
$joinColumn['fieldName'] = (string) $joinColumnElement['fieldName'];
|
|
|
|
}
|
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
if (isset($joinColumnElement['unique'])) {
|
|
|
|
$joinColumn['unique'] = (bool) $joinColumnElement['unique'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
if (isset($joinColumnElement['nullable'])) {
|
|
|
|
$joinColumn['nullable'] = (bool) $joinColumnElement['nullable'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
if (isset($joinColumnElement['onDelete'])) {
|
|
|
|
$joinColumn['onDelete'] = $joinColumnElement['onDelete'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
if (isset($joinColumnElement['onUpdate'])) {
|
|
|
|
$joinColumn['onUpdate'] = $joinColumnElement['onUpdate'];
|
|
|
|
}
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
if (isset($joinColumnElement['columnDefinition'])) {
|
|
|
|
$joinColumn['columnDefinition'] = $joinColumnElement['columnDefinition'];
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
return $joinColumn;
|
|
|
|
}
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2009-06-06 01:40:47 +04:00
|
|
|
/**
|
2010-01-28 15:46:12 +03:00
|
|
|
* {@inheritdoc}
|
2009-06-06 01:40:47 +04:00
|
|
|
*/
|
|
|
|
protected function _loadMappingFile($file)
|
|
|
|
{
|
2010-03-17 02:03:29 +03:00
|
|
|
return \Symfony\Components\Yaml\Yaml::load($file);
|
2009-02-17 11:01:34 +03:00
|
|
|
}
|
2008-02-04 00:29:57 +03:00
|
|
|
}
|