Explorar el Código

[Tree] MaterializedPath: More minor fixes.

comfortablynumb hace 13 años
padre
commit
c0312ea243

+ 2 - 2
lib/Gedmo/Tree/Document/MongoDB/Repository/AbstractTreeRepository.php

@@ -40,7 +40,7 @@ abstract class AbstractTreeRepository extends DocumentRepository
         }
 
         $this->listener = $treeListener;
-        if (!$this->validates()) {
+        if (!$this->validate()) {
             throw new \Gedmo\Exception\InvalidMappingException('This repository cannot be used for tree type: ' . $treeListener->getStrategy($em, $class->name)->getName());
         }
     }
@@ -51,5 +51,5 @@ abstract class AbstractTreeRepository extends DocumentRepository
      *
      * @return bool
      */
-    abstract protected function validates();
+    abstract protected function validate();
 }

+ 1 - 1
lib/Gedmo/Tree/Document/MongoDB/Repository/MaterializedPathRepository.php

@@ -62,7 +62,7 @@ class MaterializedPathRepository extends AbstractTreeRepository
     /**
      * {@inheritdoc}
      */
-    protected function validates()
+    protected function validate()
     {
         return $this->listener->getStrategy($this->dm, $this->getClassMetadata()->name)->getName() === Strategy::MATERIALIZED_PATH;
     }

+ 2 - 2
lib/Gedmo/Tree/Entity/Repository/AbstractTreeRepository.php

@@ -39,7 +39,7 @@ abstract class AbstractTreeRepository extends EntityRepository
         }
 
         $this->listener = $treeListener;
-        if (!$this->validates()) {
+        if (!$this->validate()) {
             throw new \Gedmo\Exception\InvalidMappingException('This repository cannot be used for tree type: ' . $treeListener->getStrategy($em, $class->name)->getName());
         }
     }
@@ -50,5 +50,5 @@ abstract class AbstractTreeRepository extends EntityRepository
      *
      * @return bool
      */
-    abstract protected function validates();
+    abstract protected function validate();
 }

+ 1 - 1
lib/Gedmo/Tree/Entity/Repository/ClosureTreeRepository.php

@@ -283,7 +283,7 @@ class ClosureTreeRepository extends AbstractTreeRepository
     /**
      * {@inheritdoc}
      */
-    protected function validates()
+    protected function validate()
     {
         return $this->listener->getStrategy($this->_em, $this->getClassMetadata()->name)->getName() === Strategy::CLOSURE;
     }

+ 1 - 1
lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

@@ -826,7 +826,7 @@ class NestedTreeRepository extends AbstractTreeRepository
     /**
      * {@inheritdoc}
      */
-    protected function validates()
+    protected function validate()
     {
         return $this->listener->getStrategy($this->_em, $this->getClassMetadata()->name)->getName() === Strategy::NESTED;
     }

+ 8 - 6
lib/Gedmo/Tree/Strategy.php

@@ -2,6 +2,8 @@
 
 namespace Gedmo\Tree;
 
+use Gedmo\Mapping\Event\AdapterInterface;
+
 interface Strategy
 {
     /**
@@ -47,20 +49,20 @@ interface Strategy
      *
      * @param object $om - object manager
      * @param object $object - node
-     * @param object $ea - event adapter
+     * @param AdapterInterface $ea - event adapter
      * @return void
      */
-    function processScheduledInsertion($om, $object, $ea);
+    function processScheduledInsertion($om, $object, AdapterInterface $ea);
 
     /**
      * Operations on tree node updates
      *
      * @param object $om - object manager
      * @param object $object - node
-     * @param object $ea - event adapter
+     * @param AdapterInterface $ea - event adapter
      * @return void
      */
-    function processScheduledUpdate($om, $object, $ea);
+    function processScheduledUpdate($om, $object, AdapterInterface $ea);
 
     /**
      * Operations on tree node delete
@@ -94,10 +96,10 @@ interface Strategy
      *
      * @param object $om - object manager
      * @param object $object - node
-     * @param object $ea - event adapter
+     * @param AdapterInterface $ea - event adapter
      * @return void
      */
-    function processPostPersist($om, $object, $ea);
+    function processPostPersist($om, $object, AdapterInterface $ea);
 
     /**
      * Operations on the end of flush process

+ 7 - 6
lib/Gedmo/Tree/Strategy/AbstractMaterializedPath.php

@@ -8,6 +8,7 @@ use Gedmo\Tree\TreeListener;
 use Doctrine\ORM\Mapping\ClassMetadataInfo;
 use Doctrine\ORM\Query;
 use Doctrine\Common\Persistence\ObjectManager;
+use Gedmo\Mapping\Event\AdapterInterface;
 
 /**
  * This strategy makes tree using materialized path strategy
@@ -55,7 +56,7 @@ abstract class AbstractMaterializedPath implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledInsertion($om, $node, $ea)
+    public function processScheduledInsertion($om, $node, AdapterInterface $ea)
     {
         $meta = $om->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($om, $meta->name);
@@ -70,7 +71,7 @@ abstract class AbstractMaterializedPath implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledUpdate($om, $node, $ea)
+    public function processScheduledUpdate($om, $node, AdapterInterface $ea)
     {
         $meta = $om->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($om, $meta->name);
@@ -87,14 +88,14 @@ abstract class AbstractMaterializedPath implements Strategy
             }
 
             $this->updateNode($om, $node, $ea);
-            $this->updateNodesChildren($om, $node, $ea, $originalPath);
+            $this->updateChildren($om, $node, $ea, $originalPath);
         }
     }
 
     /**
      * {@inheritdoc}
      */
-    public function processPostPersist($om, $node, $ea)
+    public function processPostPersist($om, $node, AdapterInterface $ea)
     {
         foreach ($this->scheduledForPathProcess as $node) {
             $this->updateNode($om, $node, $ea);
@@ -148,7 +149,7 @@ abstract class AbstractMaterializedPath implements Strategy
      * @param object $ea - event adapter
      * @return void
      */
-    public function updateNode(ObjectManager $om, $node, $ea)
+    public function updateNode(ObjectManager $om, $node, AdapterInterface $ea)
     {
         $oid = spl_object_hash($node);
         $meta = $om->getClassMetadata(get_class($node));
@@ -200,7 +201,7 @@ abstract class AbstractMaterializedPath implements Strategy
      * @param string $originalPath - original path of object
      * @return void
      */
-    public function updateNodesChildren(ObjectManager $om, $node, $ea, $originalPath)
+    public function updateChildren(ObjectManager $om, $node, AdapterInterface $ea, $originalPath)
     {
         $meta = $om->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($om, $meta->name);

+ 4 - 3
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -10,6 +10,7 @@ use Doctrine\ORM\Proxy\Proxy;
 use Gedmo\Tree\TreeListener;
 use Doctrine\ORM\Version;
 use Gedmo\Tool\Wrapper\AbstractWrapper;
+use Gedmo\Mapping\Event\AdapterInterface;
 
 /**
  * This strategy makes tree act like
@@ -165,7 +166,7 @@ class Closure implements Strategy
      /**
      * {@inheritdoc}
      */
-    public function processScheduledInsertion($em, $node, $ea)
+    public function processScheduledInsertion($em, $node, AdapterInterface $ea)
     {}
 
     /**
@@ -186,7 +187,7 @@ class Closure implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processPostPersist($em, $entity, $ea)
+    public function processPostPersist($em, $entity, AdapterInterface $ea)
     {
         $uow = $em->getUnitOfWork();
 
@@ -241,7 +242,7 @@ class Closure implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledUpdate($em, $node, $ea)
+    public function processScheduledUpdate($em, $node, AdapterInterface $ea)
     {
         $meta = $em->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($em, $meta->name);

+ 4 - 3
lib/Gedmo/Tree/Strategy/ORM/Nested.php

@@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManager;
 use Gedmo\Tree\TreeListener;
 use Doctrine\ORM\Mapping\ClassMetadataInfo;
 use Doctrine\ORM\Query;
+use Gedmo\Mapping\Event\AdapterInterface;
 
 /**
  * This strategy makes tree act like
@@ -128,7 +129,7 @@ class Nested implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledInsertion($em, $node, $ea)
+    public function processScheduledInsertion($em, $node, AdapterInterface $ea)
     {
         $meta = $em->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($em, $meta->name);
@@ -146,7 +147,7 @@ class Nested implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledUpdate($em, $node, $ea)
+    public function processScheduledUpdate($em, $node, AdapterInterface $ea)
     {
         $meta = $em->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($em, $meta->name);
@@ -182,7 +183,7 @@ class Nested implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processPostPersist($em, $node, $ea)
+    public function processPostPersist($em, $node, AdapterInterface $ea)
     {
         $meta = $em->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($em, $meta->name);

+ 2 - 8
lib/Gedmo/Tree/TreeListener.php

@@ -68,16 +68,10 @@ class TreeListener extends MappedEventSubscriber
             if ($om instanceof \Doctrine\ORM\EntityManager) {
                 $managerName = 'ORM';
             } elseif ($om instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
-                $managerName = 'ODM';
+                $managerName = 'ODM\\MongoDB';
             }
             if (!isset($this->strategyInstances[$config['strategy']])) {
-                $strategyClass = $this->getNamespace().'\\Strategy\\'.$managerName;
-
-                if ($managerName === 'ODM') {
-                    $strategyClass .= '\\MongoDB';
-                }
-
-                $strategyClass .= '\\'.ucfirst($config['strategy']);
+                $strategyClass = $this->getNamespace().'\\Strategy\\'.$managerName.'\\'.ucfirst($config['strategy']);
                 
                 if (!class_exists($strategyClass)) {
                     throw new \Gedmo\Exception\InvalidArgumentException($managerName." TreeListener does not support tree type: {$config['strategy']}");

+ 0 - 1
tests/Gedmo/Tree/MaterializedPathRepositoryTest.php

@@ -4,7 +4,6 @@ namespace Gedmo\Tree;
 
 use Doctrine\Common\EventManager;
 use Tool\BaseTestCaseMongoODM;
-use Doctrine\Common\Util\Debug;
 use Tree\Fixture\RootCategory;
 
 /**