コード例 #1
0
 public function setPageObject($object, $admin_name, $property_value)
 {
     $this->page_objects[$admin_name] = $object;
     $admin = $this->loader->getAdminByName($admin_name);
     $property_id = $admin->getPropertyIdName();
     $value = (string) $admin->getReflectionProperty($property_id)->getValue($object);
     if ($value === $property_value) {
         return;
     }
     $property_slug = $admin->getPropertySlugName();
     if (!empty($property_slug)) {
         $value = (string) $admin->getReflectionProperty($property_slug)->getValue($object);
         if ($value === $property_value) {
             return;
         }
     }
     throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
 }
コード例 #2
0
 /** 
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function getRouteCollection()
 {
     if (null === $this->route_page_collection) {
         $cache_expired = $this->loadFromCache();
         if (!$cache_expired) {
             return $this->route_page_collection;
         }
         //\Dev::dump($cache_expired); exit;
         $this->loader->getService('sf.admin.compiler')->set(\Symforce\AdminBundle\Compiler\Loader\Compiler::STAT_ROUTE);
         $this->config = array();
         if ($this->loader->hasConfig('web_page_class')) {
             $this->config = $this->loader->getConfig('web_page_class');
         }
         $this->route_page_collection = new \Symfony\Component\Routing\RouteCollection();
         $route_admin_collection = new \Symfony\Component\Routing\RouteCollection();
         $class = $this->getCompileClass();
         if ($this->config) {
             foreach ($this->config as $admin_class => $page_class) {
                 $page_generator = $this->getPageGeneratorByClass($admin_class);
                 $admin_name = $page_generator->getAdminName();
                 $controller = strtolower($page_generator->getController());
                 if ($page_generator->isOwnController()) {
                     if (isset($this->controler_owner[$controller])) {
                         throw new \Exception(sprintf("`%s` owner duplicate (%s,%s)", $controller, $admin_class, $this->controler_owner[$controller]));
                     }
                     $this->controler_owner[$controller] = $admin_name;
                 }
                 if (!isset($this->controler_owners[$controller])) {
                     $this->controler_owners[$controller] = array();
                 }
                 $this->controler_owners[$controller][] = $admin_name;
             }
         }
         foreach ($this->page_generators as $page_generator) {
             $page_generator->generate();
         }
         foreach ($this->page_generators as $page_generator) {
             $page_generator->fixAlias();
         }
         foreach ($this->other_controler_actions as $admin_name => $action_list) {
             foreach ($action_list as $action_name => $fn) {
                 $admin_action = $admin_name . ':' . $action_name;
                 if (!isset($this->page_actions_map[$admin_action])) {
                     throw new \Exception(sprintf("%s not loaded for %s", $fn, $admin_action));
                 }
             }
         }
         $default_controller = new \ReflectionClass(\Symforce\AdminBundle\Compiler\MetaType\Admin\Page::PAGE_CONTROLLER_CLASS);
         foreach ($this->page_generators as $page_generator) {
             $admin_name = $page_generator->getAdminName();
             $admin_action = $admin_name . ':index';
             if (!isset($this->page_actions_map[$admin_action]) && !isset($this->page_action_alias[$admin_action])) {
                 $annot = new \Symforce\AdminBundle\Compiler\Annotation\Route(array('admin' => $admin_name, 'action' => 'index', 'template' => 'SymforceAdminBundle:WebPage:index.html.twig'));
                 $page_generator->addRoute($default_controller->getMethod('defaultIndexAction'), $annot);
             }
             $admin_action = $admin_name . ':view';
             if (!isset($this->page_actions_map[$admin_action]) && !isset($this->page_action_alias[$admin_action])) {
                 $annot = new \Symforce\AdminBundle\Compiler\Annotation\Route(array('admin' => $admin_name, 'action' => 'view', 'entity' => true, 'template' => 'SymforceAdminBundle:WebPage:view.html.twig'));
                 $page_generator->addRoute($default_controller->getMethod('defaultViewAction'), $annot);
             }
         }
         $class->addProperty('route', $this->page_route_map);
         $class->addProperty('alias', $this->page_action_alias);
         $class->addProperty('cache', $this->page_dispatch_map);
         // add admin route
         foreach ($this->loader->getAdminMaps() as $admin_class => $admin_cache_calss) {
             $admin = $this->loader->getAdminByClass($admin_class);
             $this->route_page_collection->addResource(new \Symfony\Component\Config\Resource\FileResource($admin->getReflectionClass()->getFileName()));
             $this->admin_route_generators[$admin->getName()] = new \Symforce\AdminBundle\Compiler\Generator\RouteAdminGenerator($this, $admin);
         }
         foreach ($this->admin_route_generators as $admin_name => $admin_route_generator) {
             $admin_route_generator->generate($route_admin_collection);
         }
         $route_admin_collection->addPrefix('/admin/object');
         $this->route_page_collection->addCollection($route_admin_collection);
         $class->writeCache();
         $this->loader->getService('sf.admin.compiler')->set(\Symforce\AdminBundle\Compiler\Loader\Compiler::STAT_OK);
         $content_cache = array(time(), array_keys($this->route_file_resources), $this->route_page_collection);
         $content = '<' . '?php return unserialize(' . var_export(serialize($content_cache), 1) . ');';
         \Dev::write_file($this->route_cache_path, $content);
     }
     return $this->route_page_collection;
 }