Permalink
Browse files

[mapping] create single file to autoload annotations and possibility …

…to map abstract classes only
  • Loading branch information...
1 parent 122769f commit 18d219ddf60b3a9860a67ef80cace5e68951ae71 @l3pp4rd committed Jan 28, 2012
@@ -0,0 +1,130 @@
+<?php
+
+namespace Gedmo;
+
+use Doctrine\Common\Annotations\AnnotationRegistry;
+use Doctrine\ORM\Mapping\Driver as DriverORM;
+use Doctrine\ODM\MongoDB\Mapping\Driver as DriverMongodbODM;
+use Doctrine\Common\Annotations\Reader;
+use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\Common\Annotations\AnnotationReader;
+use Doctrine\Common\Cache\ArrayCache;
+
+/**
+ * Version class allows to checking the dependencies required
+ * and the current version of doctrine extensions
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @subpackage DoctrineExtensions
+ * @package Gedmo
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+final class DoctrineExtensions
+{
+ /**
+ * Current version of extensions
+ */
+ const VERSION = '2.3.0-DEV';
+
+ /**
+ * Flag if annotations were included into registry
+ * allready
+ *
+ * @var boolean
+ */
+ private static $autoloaded = false;
+
+ /**
+ * Hooks all extensions metadata mapping drivers
+ * into given $driverChain of drivers for ORM
+ *
+ * @param \Doctrine\ORM\Mapping\Driver\DriverChain $driverChain
+ * @param \Doctrine\Common\Annotations\Reader $reader
+ */
+ public static function registerMappingIntoDriverChainORM(DriverORM\DriverChain $driverChain, Reader $reader = null)
+ {
+ self::registerAnnotations();
+ if (!$reader) {
+ $reader = new CachedReader(new AnnotationReader, new ArrayCache);
+ }
+ $annotationDriver = new DriverORM\AnnotationDriver($reader, array(
+ __DIR__.'/Translatable/Entity',
+ __DIR__.'/Loggable/Entity',
+ __DIR__.'/Tree/Entity',
+ ));
+ $driverChain->addDriver($annotationDriver, 'Gedmo');
+ }
+
+ /**
+ * Hooks only superclass metadata mapping drivers
+ * into given $driverChain of drivers for ORM
+ *
+ * @param \Doctrine\ORM\Mapping\Driver\DriverChain $chain
+ * @param \Doctrine\Common\Annotations\Reader $reader
+ */
+ public static function registerAbstractMappingIntoDriverChainORM(DriverORM\DriverChain $driverChain, Reader $reader = null)
+ {
+ self::registerAnnotations();
+ if (!$reader) {
+ $reader = new CachedReader(new AnnotationReader, new ArrayCache);
+ }
+ $annotationDriver = new DriverORM\AnnotationDriver($reader, array(
+ __DIR__.'/Translatable/Entity/MappedSuperclass',
+ __DIR__.'/Loggable/Entity/MappedSuperclass',
+ __DIR__.'/Tree/Entity/MappedSuperclass',
+ ));
+ $driverChain->addDriver($annotationDriver, 'Gedmo');
+ }
+
+ /**
+ * Hooks all extensions metadata mapping drivers
+ * into given $driverChain of drivers for ODM MongoDB
+ *
+ * @param \Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain $driverChain
+ * @param \Doctrine\Common\Annotations\Reader $reader
+ */
+ public static function registerMappingIntoDriverChainMongodbODM(DriverMongodbODM\DriverChain $driverChain, Reader $reader = null)
+ {
+ self::registerAnnotations();
+ if (!$reader) {
+ $reader = new CachedReader(new AnnotationReader, new ArrayCache);
+ }
+ $annotationDriver = new DriverMongodbODM\AnnotationDriver($reader, array(
+ __DIR__.'/Translatable/Document',
+ __DIR__.'/Loggable/Document',
+ ));
+ $driverChain->addDriver($annotationDriver, 'Gedmo');
+ }
+
+ /**
+ * Hooks only superclass metadata mapping drivers
+ * into given $driverChain of drivers for ODM MongoDB
+ *
+ * @param \Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain $driverChain
+ * @param \Doctrine\Common\Annotations\Reader $reader
+ */
+ public static function registerAbstractMappingIntoDriverChainMongodbODM(DriverMongodbODM\DriverChain $driverChain, Reader $reader = null)
+ {
+ self::registerAnnotations();
+ if (!$reader) {
+ $reader = new CachedReader(new AnnotationReader, new ArrayCache);
+ }
+ $annotationDriver = new DriverMongodbODM\AnnotationDriver($reader, array(
+ __DIR__.'/Translatable/Document/MappedSuperclass',
+ __DIR__.'/Loggable/Document/MappedSuperclass',
+ ));
+ $driverChain->addDriver($annotationDriver, 'Gedmo');
+ }
+
+ /**
+ * Includes all extension annotations once
+ */
+ public static function registerAnnotations()
+ {
+ if (!self::$autoloaded) {
+ AnnotationRegistry::registerFile(__DIR__.'/Mapping/Annotation/All.php');
+ self::$autoloaded = true;
+ }
+ }
+}
@@ -1,19 +0,0 @@
-<?php
-
-namespace Gedmo\Exception;
-
-use Gedmo\Exception;
-
-/**
- * DependentComponentNotFoundException
- *
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Exception
- * @subpackage DependentComponentNotFoundException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class DependentComponentNotFoundException
- extends \RuntimeException
- implements Exception
-{}
@@ -1,19 +0,0 @@
-<?php
-
-namespace Gedmo\Exception;
-
-use Gedmo\Exception;
-
-/**
- * IncompatibleComponentVersionException
- *
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Exception
- * @subpackage IncompatibleComponentVersionException
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-class IncompatibleComponentVersionException
- extends \RuntimeException
- implements Exception
-{}
@@ -0,0 +1,31 @@
+<?php
+
+/**
+* Contains all annotations for extensions
+* NOTE: should be included with require_once
+*
+* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+* @package Gedmo.Mapping.Annotation
+* @link http://www.gediminasm.org
+* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+*/
+
+include __DIR__.'/Language.php';
+include __DIR__.'/Locale.php';
+include __DIR__.'/Loggable.php';
+include __DIR__.'/Slug.php';
+include __DIR__.'/SlugHandler.php';
+include __DIR__.'/SlugHandlerOption.php';
+include __DIR__.'/SortableGroup.php';
+include __DIR__.'/SortablePosition.php';
+include __DIR__.'/Timestampable.php';
+include __DIR__.'/Translatable.php';
+include __DIR__.'/TranslationEntity.php';
+include __DIR__.'/Tree.php';
+include __DIR__.'/TreeClosure.php';
+include __DIR__.'/TreeLeft.php';
+include __DIR__.'/TreeLevel.php';
+include __DIR__.'/TreeParent.php';
+include __DIR__.'/TreeRight.php';
+include __DIR__.'/TreeRoot.php';
+include __DIR__.'/Versioned.php';
@@ -82,7 +82,11 @@ public function getExtensionMetadata($meta)
if ($cmf->hasMetadataFor($parentClass)) {
$class = $this->objectManager->getClassMetadata($parentClass);
$this->driver->readExtendedMetadata($class, $config);
- if (!$class->isInheritanceTypeNone() && !$class->parentClasses && $config) {
+ $isBaseInheritanceLevel = !$class->isInheritanceTypeNone()
+ && !$class->parentClasses
+ && $config
+ ;
+ if ($isBaseInheritanceLevel) {
$useObjectName = $class->name;
}
}
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
-
- <mapped-superclass name="Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation">
- <id name="id" type="integer">
- <generator strategy="AUTO"/>
- </id>
-
- <field name="locale" type="string" length="8" />
- <field name="field" type="string" length="32" />
- <field name="content" type="text" nullable="true" />
- </mapped-superclass>
-
-</doctrine-mapping>
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
-
- <mapped-superclass name="Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation">
- <id name="id" type="integer">
- <generator strategy="AUTO"/>
- </id>
-
- <field name="locale" type="string" length="8" />
- <field name="field" type="string" length="32" />
- <field name="objectClass" column="object_class" type="string" length="255" />
- <field name="foreignKey" column="foreign_key" type="string" length="64" />
- <field name="content" type="text" nullable="true" />
- </mapped-superclass>
-
-</doctrine-mapping>
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
-
- <entity name="Gedmo\Translatable\Entity\Translation" repository-class="Gedmo\Translatable\Entity\Repository\TranslationRepository" table="ext_translations">
- <unique-constraints>
- <unique-constraint name="lookup_unique_idx" columns="locale,object_class,foreign_key,field" />
- </unique-constraints>
-
- <indexes>
- <index name="translations_lookup_idx" columns="locale,object_class,foreign_key" />
- </indexes>
- </entity>
-
-</doctrine-mapping>
@@ -1,21 +1,18 @@
<?php
-namespace Gedmo\Tree\Entity;
+namespace Gedmo\Tree\Entity\MappedSuperclass;
-use Doctrine\ORM\Mapping\Column;
-use Doctrine\ORM\Mapping\MappedSuperclass;
-use Doctrine\ORM\Mapping\Id;
-use Doctrine\ORM\Mapping\GeneratedValue;
+use Doctrine\ORM\Mapping as ORM;
/**
- * @MappedSuperclass
+ * @ORM\MappedSuperclass
*/
abstract class AbstractClosure
{
/**
- * @Id
- * @GeneratedValue
- * @Column(type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue
+ * @ORM\Column(type="integer")
*/
private $id;
@@ -32,7 +29,7 @@
protected $descendant;
/**
- * @Column(type="integer")
+ * @ORM\Column(type="integer")
*/
private $depth;
View
@@ -1,24 +0,0 @@
-<?php
-
-namespace Gedmo;
-
-use Gedmo\Exception\DependentComponentNotFoundException;
-use Gedmo\Exception\IncompatibleComponentVersionException;
-
-/**
- * Version class allows to checking the dependencies required
- * and the current version of doctrine extensions
- *
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @subpackage Version
- * @package Gedmo
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-final class Version
-{
- /**
- * Current version of extensions
- */
- const VERSION = '2.3.0-DEV';
-}
@@ -2,7 +2,7 @@
namespace Mapping\Fixture;
-use Gedmo\Tree\Entity\AbstractClosure;
+use Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -43,27 +43,6 @@ protected function setUp()
$this->populate();
}
- protected function getMetadataDriverImplementation()
- {
- $translatableRefl = new \ReflectionClass('Gedmo\Translatable\TranslatableListener');
- $mapping = dirname($translatableRefl->getFileName()).'/Mapping/Metadata';
-
- $annotationDriver = new AnnotationDriver($_ENV['annotation_reader']);
- $xmlDriverSuperclass = new SimplifiedXmlDriver(array(
- $mapping.'/abstract' => 'Gedmo\Translatable\Entity\MappedSuperclass'
- ));
- $xmlDriver = new SimplifiedXmlDriver(array(
- $mapping.'/translation' => 'Gedmo\Translatable\Entity'
- ));
-
- $chain = new DriverChain;
- $chain->addDriver($annotationDriver, 'Translatable\Fixture');
- $chain->addDriver($xmlDriverSuperclass, 'Gedmo\Translatable\Entity\MappedSuperclass');
- $chain->addDriver($xmlDriver, 'Gedmo\Translatable\Entity');
-
- return $chain;
- }
-
public function testFixtureGeneratedTranslations()
{
$repo = $this->em->getRepository(self::TRANSLATION);
@@ -2,7 +2,7 @@
namespace Tree\Fixture\Closure;
-use Gedmo\Tree\Entity\AbstractClosure;
+use Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -2,7 +2,7 @@
namespace Tree\Fixture\Closure;
-use Gedmo\Tree\Entity\AbstractClosure;
+use Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure;
use Doctrine\ORM\Mapping as ORM;
/**
Oops, something went wrong.

0 comments on commit 18d219d

Please sign in to comment.