當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。