当前位置: 首页>>代码示例>>PHP>>正文


PHP Registry::getContainer方法代码示例

本文整理汇总了PHP中Doctrine\Bundle\DoctrineBundle\Registry::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::getContainer方法的具体用法?PHP Registry::getContainer怎么用?PHP Registry::getContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Bundle\DoctrineBundle\Registry的用法示例。


在下文中一共展示了Registry::getContainer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onPreSetData

 /**
  * onPreSetData
  *
  * @param FormEvent $event
  */
 public function onPreSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data || null === $data->getId()) {
         return;
     }
     $rootNode = $this->nodeProvider->getRootNode();
     $repository = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNode');
     $allTree = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNodeClosure')->createQueryBuilder('c')->select('d.id')->innerJoin('c.descendant', 'd')->where('c.ancestor = :id')->setParameter('id', $rootNode->getId())->getQuery()->getResult();
     $treeArray = array();
     foreach ($allTree as $tree) {
         $treeArray[] = $tree['id'];
     }
     $descendants = $this->registry->getRepository('Erichard\\DmsBundle\\Entity\\DocumentNodeClosure')->createQueryBuilder('c')->select('d.id')->innerJoin('c.descendant', 'd')->where('c.ancestor = :id')->setParameter('id', $data->getId())->getQuery()->getArrayResult();
     $descendants = array_map(function ($descendant) {
         return $descendant['id'];
     }, $descendants);
     $tree = $repository->getNodesHierarchyQueryBuilder(null, false, array('childSort' => array('field' => 'name', 'dir' => 'asc')), true);
     if (count($descendants) > 0) {
         $tree->andWhere('node.id NOT IN (:node_id)')->setParameter('node_id', $descendants);
     }
     $realTreeArray = array();
     foreach ($tree->getQuery()->getArrayResult() as $node) {
         if (in_array($node[0]['descendant']['id'], $treeArray)) {
             $realTreeArray[] = $node;
         }
     }
     $tree = $repository->buildTree($realTreeArray);
     // On met en place notre itérator en vue de retirer la profondeur de nos éléments
     $iterator = new \RecursiveIteratorIterator(new GedmoTreeIterator($tree), \RecursiveIteratorIterator::SELF_FIRST);
     $choices = array();
     foreach ($iterator as $node) {
         $nodeName = $node['name'];
         if ($node['id'] == $rootNode->getId()) {
             $nodeName = $this->registry->getContainer()->get('translator')->trans('home', array(), 'ErichardDmsBundle');
         }
         $depth = $iterator->getDepth();
         $choices[$node['id']] = str_repeat("   ", $depth) . $nodeName;
     }
     $form->add($this->factory->createNamedBuilder('parent', 'choice', $data->getParent(), array('label' => 'move_node', 'required' => true, 'choices' => $choices, 'auto_initialize' => false))->addModelTransformer(new NodeToIdTransformer($this->registry))->getForm());
 }
开发者ID:DavidG04,项目名称:ErichardDmsBundle,代码行数:47,代码来源:NodeType.php


注:本文中的Doctrine\Bundle\DoctrineBundle\Registry::getContainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。