Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[example] optimized example and documentation, to share reader, referes

  • Loading branch information...
commit 8e72a1503709e95800f21f1ab1bc46e9c753945e 1 parent ce333ae
Gediminas Morkevicius authored
43  doc/annotations.md
Source Rendered
@@ -111,17 +111,42 @@ $config->setQueryCacheImpl($cache);
111 111
 
112 112
 // create event manager and hook prefered extension listeners
113 113
 $evm = new Doctrine\Common\EventManager();
114  
-// gedmo extension listeners
115  
-$evm->addEventSubscriber(new Gedmo\Sluggable\SluggableListener);
116  
-$evm->addEventSubscriber(new Gedmo\Tree\TreeListener);
117  
-$evm->addEventSubscriber(new Gedmo\Loggable\LoggableListener);
118  
-$evm->addEventSubscriber(new Gedmo\Timestampable\TimestampableListener);
119  
-$translatable = new Gedmo\Translatable\TranslatableListener;
  114
+// gedmo extension listeners, remove which are not used
  115
+
  116
+// sluggable
  117
+$sluggableListener = new Gedmo\Sluggable\SluggableListener;
  118
+// you should set the used annotation reader to listener, to avoid creating new one for mapping drivers
  119
+$sluggableListener->setAnnotationReader($cachedAnnotationReader);
  120
+$evm->addEventSubscriber($sluggableListener);
  121
+
  122
+// tree
  123
+$treeListener = new Gedmo\Tree\TreeListener;
  124
+$treeListener->setAnnotationReader($cachedAnnotationReader);
  125
+$evm->addEventSubscriber($treeListener);
  126
+
  127
+// loggable, not used in example
  128
+$loggableListener = new Gedmo\Loggable\LoggableListener;
  129
+$loggableListener->setAnnotationReader($cachedAnnotationReader);
  130
+$evm->addEventSubscriber($loggableListener);
  131
+
  132
+// timestampable
  133
+$timestampableListener = new Gedmo\Timestampable\TimestampableListener;
  134
+$timestampableListener->setAnnotationReader($cachedAnnotationReader);
  135
+$evm->addEventSubscriber($timestampableListener);
  136
+
  137
+// translatable
  138
+$translatableListener = new Gedmo\Translatable\TranslatableListener;
120 139
 // current translation locale should be set from session or hook later into the listener
121 140
 // most important, before entity manager is flushed
122  
-$translatable->setTranslatableLocale('en');
123  
-$translatable->setDefaultLocale('en');
124  
-$evm->addEventSubscriber($translatable);
  141
+$translatableListener->setTranslatableLocale('en');
  142
+$translatableListener->setDefaultLocale('en');
  143
+$translatableListener->setAnnotationReader($cachedAnnotationReader);
  144
+$evm->addEventSubscriber($translatableListener);
  145
+
  146
+// sortable, not used in example
  147
+$sortableListener = new Gedmo\Sortable\SortableListener;
  148
+$sortableListener->setAnnotationReader($cachedAnnotationReader);
  149
+$evm->addEventSubscriber($sortableListener);
125 150
 
126 151
 // mysql set names UTF-8 if required
127 152
 $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
41  example/em.php
@@ -96,16 +96,41 @@
96 96
 // Third, create event manager and hook prefered extension listeners
97 97
 $evm = new Doctrine\Common\EventManager();
98 98
 // gedmo extension listeners
99  
-$evm->addEventSubscriber(new Gedmo\Sluggable\SluggableListener);
100  
-$evm->addEventSubscriber(new Gedmo\Tree\TreeListener);
101  
-$evm->addEventSubscriber(new Gedmo\Loggable\LoggableListener);
102  
-$evm->addEventSubscriber(new Gedmo\Timestampable\TimestampableListener);
103  
-$translatable = new Gedmo\Translatable\TranslatableListener;
  99
+
  100
+// sluggable
  101
+$sluggableListener = new Gedmo\Sluggable\SluggableListener;
  102
+// you should set the used annotation reader to listener, to avoid creating new one for mapping drivers
  103
+$sluggableListener->setAnnotationReader($cachedAnnotationReader);
  104
+$evm->addEventSubscriber($sluggableListener);
  105
+
  106
+// tree
  107
+$treeListener = new Gedmo\Tree\TreeListener;
  108
+$treeListener->setAnnotationReader($cachedAnnotationReader);
  109
+$evm->addEventSubscriber($treeListener);
  110
+
  111
+// loggable, not used in example
  112
+//$loggableListener = new Gedmo\Loggable\LoggableListener;
  113
+//$loggableListener->setAnnotationReader($cachedAnnotationReader);
  114
+//$evm->addEventSubscriber($loggableListener);
  115
+
  116
+// timestampable
  117
+$timestampableListener = new Gedmo\Timestampable\TimestampableListener;
  118
+$timestampableListener->setAnnotationReader($cachedAnnotationReader);
  119
+$evm->addEventSubscriber($timestampableListener);
  120
+
  121
+// translatable
  122
+$translatableListener = new Gedmo\Translatable\TranslatableListener;
104 123
 // current translation locale should be set from session or hook later into the listener
105 124
 // most important, before entity manager is flushed
106  
-$translatable->setTranslatableLocale('en');
107  
-$translatable->setDefaultLocale('en');
108  
-$evm->addEventSubscriber($translatable);
  125
+$translatableListener->setTranslatableLocale('en');
  126
+$translatableListener->setDefaultLocale('en');
  127
+$translatableListener->setAnnotationReader($cachedAnnotationReader);
  128
+$evm->addEventSubscriber($translatableListener);
  129
+
  130
+// sortable, not used in example
  131
+//$sortableListener = new Gedmo\Sortable\SortableListener;
  132
+//$sortableListener->setAnnotationReader($cachedAnnotationReader);
  133
+//$evm->addEventSubscriber($sortableListener);
109 134
 
110 135
 // mysql set names UTF-8 if required
111 136
 $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());

0 notes on commit 8e72a15

Please sign in to comment.
Something went wrong with that request. Please try again.