function let(UserContext $userContext, EntityManager $em, ClassMetadata $classMetadata, EventManager $eventManager, TreeListener $treeListener, Nested $strategy)
 {
     $classMetadata->name = 'category';
     $userContext->getCurrentLocaleCode()->willReturn('en_US');
     $em->getEventManager()->willReturn($eventManager);
     $eventManager->getListeners()->willReturn([[$treeListener]]);
     $treeListener->getStrategy(Argument::cetera())->willReturn($strategy);
     $treeListener->getConfiguration(Argument::cetera())->willReturn(['parent' => 'parent', 'left' => 'left']);
     $this->beConstructedWith($userContext, $em, $classMetadata);
 }
 function let(EntityManager $em, Connection $connection, Statement $statement, ClassMetadata $classMetadata, EventManager $eventManager, TreeListener $treeListener, Nested $strategy, \ReflectionProperty $property)
 {
     $connection->prepare(Argument::any())->willReturn($statement);
     $em->getClassMetadata(Argument::any())->willReturn($classMetadata);
     $classMetadata->name = 'channel';
     $classMetadata->getReflectionProperty(Argument::any())->willReturn($property);
     $em->getConnection()->willReturn($connection);
     $em->getEventManager()->willReturn($eventManager);
     $em->getClassMetadata()->willReturn($classMetadata);
     $strategy->getName()->willReturn(Strategy::NESTED);
     $strategy->setNodePosition(Argument::cetera())->willReturn(null);
     $treeListener->getStrategy(Argument::cetera())->willReturn($strategy);
     $configuration = ['parent' => 'parent', 'left' => 'left'];
     $treeListener->getConfiguration(Argument::cetera())->willReturn($configuration);
     $eventManager->getListeners()->willReturn([[$treeListener]]);
     $this->beConstructedWith($em, $classMetadata);
 }
 /**
  * {@inheritdoc}
  */
 public function persistAsNextSiblingOf(MenuItemInterface $node, MenuItemInterface $sibling)
 {
     $wrapped = new EntityWrapper($node, $this->_em);
     $meta = $this->getClassMetadata();
     $config = $this->treeListener->getConfiguration($this->_em, $meta->name);
     $wrappedSibling = new EntityWrapper($sibling, $this->_em);
     $newParent = $wrappedSibling->getPropertyValue($config['parent']);
     if (null === $newParent && isset($config['root'])) {
         throw new UnexpectedValueException('Cannot persist sibling for a root node, tree operation is not possible');
     }
     $node->sibling = $sibling;
     $sibling = $newParent;
     $wrapped->setPropertyValue($config['parent'], $sibling);
     $wrapped->setPropertyValue($config['left'], 0);
     $oid = spl_object_hash($node);
     $this->treeListener->getStrategy($this->_em, $meta->name)->setNodePosition($oid, 'NextSibling');
     $this->_em->persist($node);
     return $this;
 }
Beispiel #4
0
 /**
  * @param ObjectManager $om
  * @param TreeListener $listener
  * @param string $class
  * @return Strategy
  */
 private function getClassStrategy(ObjectManager $om, TreeListener $listener, $class)
 {
     if (array_key_exists($class, $this->classStrategies)) {
         return $this->classStrategies[$class];
     }
     $this->classStrategies[$class] = null;
     $classParents = array_merge(array($class), class_parents($class));
     foreach ($classParents as $parent) {
         try {
             $this->classStrategies[$class] = $listener->getStrategy($om, $parent);
             break;
         } catch (\Exception $e) {
             // we don't like to throw exception because there might be a strategy for class parents
         }
     }
     return $this->classStrategies[$class];
 }