Last active
July 3, 2019 22:16
-
-
Save Solution/5389050 to your computer and use it in GitHub Desktop.
Gedmo extension for Kdyby\Doctrine and some changes in Gedmo\DoctrineExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
nette: | |
services: | |
doctrine.default.metadataDriver: | |
setup: | |
- Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(@self) | |
factories: | |
doctrine: | |
host: localhost | |
user: | |
password: | |
dbname: | |
metadata: | |
App: annotations(%libsDir%/App) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Gedmo; | |
use Doctrine\Common\Annotations\AnnotationRegistry; | |
use Doctrine\ORM\Mapping\Driver as DriverMappingORM; | |
use Doctrine\Common\Persistence\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 <[email protected]> | |
* @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 | |
* already | |
* | |
* @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\MappingDriverChain $driverChain, Reader $reader = null) | |
{ | |
self::registerAnnotations(); | |
if (!$reader) { | |
$reader = new CachedReader(new AnnotationReader, new ArrayCache); | |
} | |
$annotationDriver = new DriverMappingORM\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\MappingDriverChain $driverChain, Reader $reader = null) | |
{ | |
self::registerAnnotations(); | |
if (!$reader) { | |
$reader = new CachedReader(new AnnotationReader, new ArrayCache); | |
} | |
$annotationDriver = new DriverMappingORM\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\MappingDriverChain $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\MappingDriverChain $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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* User: Patrik Tomášik([email protected]) | |
* Date: 15.4.13 | |
* Time: 14:08 | |
* Package: EfineCMS | |
*/ | |
namespace Gedmo\DI\Extension; | |
use Nette\Config\CompilerExtension; | |
class GedmoExtension extends CompilerExtension | |
{ | |
public function loadConfiguration() | |
{ | |
$builder = $this->getContainerBuilder(); | |
// sluggable | |
$builder->addDefinition($this->prefix('sluggable')) | |
->setClass('Gedmo\Sluggable\SluggableListener') | |
->addSetup('setAnnotationReader', array('@Doctrine\Common\Annotations\Reader')) | |
->addTag('kdyby.subscriber'); | |
// tree | |
$builder->addDefinition($this->prefix('treeable')) | |
->setClass('Gedmo\Tree\TreeListener') | |
->addSetup('setAnnotationReader', array('@Doctrine\Common\Annotations\Reader')) | |
->addTag('kdyby.subscriber'); | |
// blameable | |
$builder->addDefinition($this->prefix('blameable')) | |
->setClass('Gedmo\Blameable\BlameableListener') | |
->addSetup('setAnnotationReader', array('@Doctrine\Common\Annotations\Reader')) | |
->addTag('kdyby.subscriber'); | |
// timestampable | |
$builder->addDefinition($this->prefix('timestampable')) | |
->setClass('Gedmo\Timestampable\TimestampableListener') | |
->addSetup('setAnnotationReader', array('@Doctrine\Common\Annotations\Reader')) | |
->addTag('kdyby.subscriber'); | |
// translatable | |
$builder->addDefinition($this->prefix('translatable')) | |
->setClass('Gedmo\Translatable\TranslatableListener') | |
->addSetup('setAnnotationReader', array('@Doctrine\Common\Annotations\Reader')) | |
->addSetup('setTranslatableLocale', array('cz')) | |
->addSetup('setDefaultLocale', array('cz')) | |
->addTag('kdyby.subscriber'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment