Beispiel #1
0
 public function __construct(ContainerInterface $container, array $resources, array $menu_config, array $dashboard_config, $admin_cache_path, $admin_expired_file)
 {
     $this->container = $container;
     $container->get('sf.admin.compiler')->set(\Symforce\AdminBundle\Compiler\Loader\Compiler::STAT_ADMIN);
     $this->sf_domain = $container->getParameter('sf.admin.domain');
     $this->form_factory = $container->get('sf.form.factory');
     $this->form_factory->setGenerator($this);
     // echo "\n",__FILE__, ":", __LINE__, "\n";  exit;
     $this->trans_sf_node = $this->getTransNodeByPath($this->sf_domain, 'sf');
     $this->trans_sf_node->set('admin.brand', $this->container->getParameter('sf.admin.brand'));
     if ($this->container->hasParameter('sf.admin.title')) {
         $this->trans_sf_node->set('admin.title', $this->container->getParameter('sf.admin.title'));
     }
     $doctrine = $container->get('doctrine');
     $reader = $container->get('annotation_reader');
     $admin_maps = array();
     foreach ($resources as $bundle_name => $bundle_classes) {
         foreach ($bundle_classes as $class_name) {
             $om = $doctrine->getManagerForClass($class_name);
             if (!$om) {
                 continue;
             }
             $meta = $om->getClassMetadata($class_name);
             foreach ($meta->fieldMappings as $property_name => &$config) {
                 if ('uuid' === $config['type']) {
                     $this->setDoctrineConfig($class_name, 'uuid', $property_name);
                 }
             }
             $cache = new \Symforce\AdminBundle\Compiler\Generator\AnnotationCache($reader, $meta);
             $this->as_cache[$class_name] = $cache;
             if (!isset($cache->class_annotations['Symforce\\AdminBundle\\Compiler\\Annotation\\Entity'])) {
                 continue;
             }
             $object = new \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity($cache, $bundle_name, $meta, $this);
             $this->admin_generators[$class_name] = $object;
             $admin_name = $object->name;
             if (isset($this->admin_alias[$admin_name])) {
                 $_object = $this->admin_generators[$this->admin_alias[$admin_name]];
                 throw new \Exception(sprintf("`%s:%s` with `%s:%s` has same name `%s` ", $object->getClassName(), $object->getFileName(), $_object->getClassName(), $_object->getFileName(), $admin_name));
             }
             $this->admin_alias[$admin_name] = $class_name;
             $admin_maps[$class_name] = $object->_compile_class_name;
             $this->doctrine_config[$class_name]['id'] = $object->property_id_name;
         }
     }
     foreach ($this->admin_generators as $admin) {
         $admin->lazyInitialize();
     }
     $this->sortAdmin();
     foreach ($this->admin_generators as $class_name => $object) {
         $object->compile();
     }
     foreach ($this->trans_sf_values as $group => $values) {
         foreach ($values as $name => $value) {
             if ($value->isNull()) {
                 if (preg_match('/\\.label$/', $name)) {
                     $_value = str_replace('.label', '', $name);
                     $_value = $this->humanize($_value);
                 } else {
                     $_value = $this->humanize($name);
                 }
                 $value->setValue($_value);
             }
             if ($value->isChanged()) {
                 $tr = $this->getTransGenerator($value->getDomain());
                 $tr->set($value->getPath(), $value->getValue());
             }
         }
     }
     foreach ($this->cached_generators as $it) {
         $it->flush($this);
     }
     // $route_generator        = new Generator\RouteGenerator() ;
     $dashboard_generator = new Generator\DashboardGenerator();
     $menu_generator = new Generator\MenuGenerator();
     // \Dev::dump($this->column_config);
     $this->addLoaderCache('entity_alias', $this->admin_alias);
     $this->addLoaderCache('sf_admin_tree', $this->sf_admin_tree);
     $this->addLoaderCache('admin_maps', $admin_maps);
     $this->addLoaderCache('admin_unmaps', $this->admin_unmaps);
     $this->addLoaderCache('doctrine_config', $this->getDoctrineConfig());
     $this->addLoaderCache('role_hierarchy', $this->compileHierarchyRoles());
     $this->addLoaderCache('menu', $menu_generator->buildMenuTree($this, $menu_config), true);
     $this->addLoaderCache('dashboard', $dashboard_generator->buildDashboardGroups($this, $dashboard_config), true);
     // $this->addLoaderCache('route', $route_generator->getRouteCollection($this) , true );
     foreach ($this->loader_cache[1] as $key => $serialize_loader_cache) {
         $this->loader_cache[1][$key] = serialize($serialize_loader_cache);
     }
     \Dev::write_file($admin_cache_path, '<' . '?php return ' . var_export($this->loader_cache, 1) . ';');
     $this->generateExpireCheckCache($admin_expired_file);
     $locale = $this->container->getParameter('locale');
     $tr_cache = array();
     foreach ($this->trans_generators as $it) {
         $it->flush($this, $locale, $tr_cache);
     }
     register_shutdown_function(function ($ca) {
         foreach ($ca as $filename => $data) {
             \Dev::write_file($filename, $data);
         }
     }, $tr_cache);
     $container->get('sf.admin.compiler')->set(\Symforce\AdminBundle\Compiler\Loader\Compiler::STAT_OK);
 }