Example #1
0
 public function __construct(\Symforce\AdminBundle\Compiler\Generator\AnnotationCache $cache, $bundle_name, ClassMetadata $meta, Generator $gen)
 {
     $this->cache = $cache;
     $this->bundle_name = $bundle_name;
     $this->class_name = $cache->class_name;
     $this->reflection = $meta->getReflectionClass();
     $this->generator = $gen;
     $this->orm_metadata = $meta;
     if ($meta->isIdentifierComposite) {
         // @TODO add Composite route handle
     } else {
         $this->property_id_name = $meta->getSingleIdentifierFieldName();
     }
     $this->setMyPropertie($cache->class_annotations['Symforce\\AdminBundle\\Compiler\\Annotation\\Entity']);
     if (!$this->name) {
         $this->name = strtolower(preg_replace('/\\W/', '_', $this->class_name));
     }
     $this->template = $this->name . '.admin.html.twig';
     $this->_template_path = $this->generator->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template;
     if (null === $this->_final_template) {
         $tempalte = $this->bundle_name . ':' . basename(str_replace('\\', '\\/', $this->class_name)) . ':admin.macro.html.twig';
         try {
             $this->generator->loadTwigTemplatePath($tempalte);
             $this->_final_template = $tempalte;
         } catch (\InvalidArgumentException $e) {
         }
     }
     $compile_class_name = ucfirst($this->camelize($this->name));
     $this->_compile_class_name = 'Symforce\\AdminCache\\' . $compile_class_name . '\\Admin' . $compile_class_name;
     if (null === $this->tr_domain) {
         $this->tr_domain = $this->bundle_name;
     }
     $this->sf_domain = $gen->getSymforceDomain();
     if (isset($cache->class_annotations[self::ANNOT_TREE_CLASS])) {
         // not work for yml/xml,  because the private stof_doctrine_extensions.listener.tree service
         $tree_annot_len = strlen(self::ANNOT_TREE_CLASS);
         $this->tree = array();
         foreach ($cache->propertie_annotations as $property_name => $as) {
             foreach ($as as $annot_class => &$value) {
                 if (0 === strpos($annot_class, self::ANNOT_TREE_CLASS)) {
                     $tree_config_key = strtolower(substr($annot_class, $tree_annot_len));
                     $this->tree[$tree_config_key] = $property_name;
                 }
             }
         }
         if (!isset($this->tree['parent'])) {
             $this->throwError("missing @%sParent", self::ANNOT_TREE_CLASS);
         }
         if (!isset($this->tree['root'])) {
             $this->throwError("missing @%sRoot", self::ANNOT_TREE_CLASS);
         }
     }
     if (isset($cache->class_annotations[self::ANNOT_TOSTR_CLASS])) {
         \Dev::dump($cache->class_annotations[self::ANNOT_TOSTR_CLASS]);
         exit;
     }
     if (isset($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS])) {
         \Dev::dump($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS]);
         exit;
     }
     foreach ($cache->propertie_annotations as $property_name => $as) {
         if (isset($as[self::ANNOT_SLUG_CLASS])) {
             if ($this->property_slug_name) {
                 $this->throwError("slug property duplicate(%s, %s)", $this->property_slug_name, $property_name);
             }
             $this->property_slug_name = $property_name;
             $this->property_slug_unique = $meta->isUniqueField($property_name);
             $this->property_slug_nullable = $meta->isNullable($property_name);
         }
         if (isset($as[self::ANNOT_TOSTR_CLASS])) {
             if ($this->property_value_name) {
                 $this->throwError("@ToString(%s) is conflict with @ToString(%s)", $property_name, $this->property_value_name);
             }
             $this->property_value_name = $property_name;
         }
         if (isset($as[self::ANNOT_TREE_LEAF_CLASS])) {
             if (!$this->tree) {
                 $this->throwError("use @%s(%s) without @%s", self::ANNOT_TREE_LEAF_CLASS, $property_name, self::ANNOT_TREE_CLASS);
             }
             if (isset($this->tree['leaf'])) {
                 $this->throwError("@ToString(%s) is conflict with %s", self::ANNOT_TREE_LEAF_CLASS, $property_name, $this->tree['leaf']);
             }
             $this->tree['leaf'] = $property_name;
         }
         if (isset($as[Page::PAGE_ANNOT_CLASS])) {
             if ($this->page) {
                 $this->throwError("page property duplicate(%s, %s)", $this->page->pege_property, $property_name);
             }
             $this->page = new Page($this, $property_name, $as[Page::PAGE_ANNOT_CLASS]);
         }
         if (isset($as[Owner::OWNER_ANNOT_CLASS])) {
             if ($this->owner) {
                 $this->throwError("owner property duplicate(%s, %s)", $this->owner->owner_property, $property_name);
             }
             $this->owner = new Owner($this, $property_name, $as[Owner::OWNER_ANNOT_CLASS]);
         }
     }
     if (isset($cache->class_annotations[self::ANNOT_WORKFLOW_CLASS])) {
         $this->workflow = new Workflow($this, $cache->class_annotations[self::ANNOT_WORKFLOW_CLASS]);
     }
     if (!$this->form) {
         $this->form = new Form($this);
     }
     $this->form->bootstrap();
     $this->action_collection = new ActionCollection($this);
     $this->_route_assoc = new RouteAssoc($this);
     if (null !== $this->position) {
         if ($this->dashboard && null === $this->dashboard->position) {
             $this->dashboard->position = $this->position;
         }
         if ($this->menu && null === $this->menu->position) {
             $this->menu->position = $this->position;
         }
     }
 }