DoctrineExtensions.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Gedmo;
  3. use Doctrine\Common\Annotations\AnnotationRegistry;
  4. use Doctrine\ORM\Mapping\Driver as DriverORM;
  5. use Doctrine\ODM\MongoDB\Mapping\Driver as DriverMongodbODM;
  6. use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
  7. use Doctrine\Common\Annotations\Reader;
  8. use Doctrine\Common\Annotations\CachedReader;
  9. use Doctrine\Common\Annotations\AnnotationReader;
  10. use Doctrine\Common\Cache\ArrayCache;
  11. /**
  12. * Version class allows to checking the dependencies required
  13. * and the current version of doctrine extensions
  14. *
  15. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  16. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  17. */
  18. final class DoctrineExtensions
  19. {
  20. /**
  21. * Current version of extensions
  22. */
  23. const VERSION = '2.3.6';
  24. /**
  25. * Hooks all extensions metadata mapping drivers
  26. * into given $driverChain of drivers for ORM
  27. *
  28. * @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $driverChain
  29. * @param \Doctrine\Common\Annotations\Reader $reader
  30. */
  31. public static function registerMappingIntoDriverChainORM(MappingDriverChain $driverChain, Reader $reader = null)
  32. {
  33. self::registerAnnotations();
  34. if (!$reader) {
  35. $reader = new CachedReader(new AnnotationReader, new ArrayCache);
  36. }
  37. $annotationDriver = new DriverORM\AnnotationDriver($reader, array(
  38. __DIR__.'/Translatable/Entity',
  39. __DIR__.'/Loggable/Entity',
  40. __DIR__.'/Tree/Entity',
  41. ));
  42. $driverChain->addDriver($annotationDriver, 'Gedmo');
  43. }
  44. /**
  45. * Hooks only superclass metadata mapping drivers
  46. * into given $driverChain of drivers for ORM
  47. *
  48. * @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $driverChain
  49. * @param \Doctrine\Common\Annotations\Reader $reader
  50. */
  51. public static function registerAbstractMappingIntoDriverChainORM(MappingDriverChain $driverChain, Reader $reader = null)
  52. {
  53. self::registerAnnotations();
  54. if (!$reader) {
  55. $reader = new CachedReader(new AnnotationReader, new ArrayCache);
  56. }
  57. $annotationDriver = new DriverORM\AnnotationDriver($reader, array(
  58. __DIR__.'/Translatable/Entity/MappedSuperclass',
  59. __DIR__.'/Loggable/Entity/MappedSuperclass',
  60. __DIR__.'/Tree/Entity/MappedSuperclass',
  61. ));
  62. $driverChain->addDriver($annotationDriver, 'Gedmo');
  63. }
  64. /**
  65. * Hooks all extensions metadata mapping drivers
  66. * into given $driverChain of drivers for ODM MongoDB
  67. *
  68. * @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $driverChain
  69. * @param \Doctrine\Common\Annotations\Reader $reader
  70. */
  71. public static function registerMappingIntoDriverChainMongodbODM(MappingDriverChain $driverChain, Reader $reader = null)
  72. {
  73. self::registerAnnotations();
  74. if (!$reader) {
  75. $reader = new CachedReader(new AnnotationReader, new ArrayCache);
  76. }
  77. $annotationDriver = new DriverMongodbODM\AnnotationDriver($reader, array(
  78. __DIR__.'/Translatable/Document',
  79. __DIR__.'/Loggable/Document',
  80. ));
  81. $driverChain->addDriver($annotationDriver, 'Gedmo');
  82. }
  83. /**
  84. * Hooks only superclass metadata mapping drivers
  85. * into given $driverChain of drivers for ODM MongoDB
  86. *
  87. * @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $driverChain
  88. * @param \Doctrine\Common\Annotations\Reader $reader
  89. */
  90. public static function registerAbstractMappingIntoDriverChainMongodbODM(MappingDriverChain $driverChain, Reader $reader = null)
  91. {
  92. self::registerAnnotations();
  93. if (!$reader) {
  94. $reader = new CachedReader(new AnnotationReader, new ArrayCache);
  95. }
  96. $annotationDriver = new DriverMongodbODM\AnnotationDriver($reader, array(
  97. __DIR__.'/Translatable/Document/MappedSuperclass',
  98. __DIR__.'/Loggable/Document/MappedSuperclass',
  99. ));
  100. $driverChain->addDriver($annotationDriver, 'Gedmo');
  101. }
  102. /**
  103. * Includes all extension annotations once
  104. */
  105. public static function registerAnnotations()
  106. {
  107. AnnotationRegistry::registerFile(__DIR__.'/Mapping/Annotation/All.php');
  108. }
  109. }