public function addRoute(\ReflectionMethod $m, \Symforce\AdminBundle\Compiler\Annotation\Route $annot, array $as = null)
 {
     $this->err_msg = sprintf("%s->%s(@%s): ", $m->getDeclaringClass()->getName(), $m->getName(), self::ROUTE_ANNOT_CLASS);
     $admin_name = null;
     if ($annot->admin) {
         if (!preg_match('/^\\w+$/', $annot->admin)) {
             throw new \Exception(sprintf("%s admin `%s` invalid ", $this->err_msg, $annot->admin));
         }
         $admin_name = $annot->admin;
     } else {
         $admin_name = $this->page_loader->getControlerOwnerName($m);
     }
     $action_name = null;
     if ($annot->action) {
         if (!preg_match('/^\\w+$/', $annot->action)) {
             throw new \Exception(sprintf("%s admin `%s` invalid ", $this->err_msg, $annot->action));
         }
         $action_name = $annot->action;
     } else {
         $action_name = $annot->action ?: strtolower(preg_replace('/Action$/', '', $m->getName()));
     }
     if ($admin_name !== $this->admin_name) {
         $this->page_loader->addOtherControlerAction($admin_name, $action_name, $m);
         return;
     }
     $this->page_loader->addPageAction($admin_name, $action_name, $m);
     $controller_name = basename(str_replace('\\', '/', $m->getDeclaringClass()->getName()));
     if (!$annot->name) {
         $annot->name = $admin_name . '.' . $action_name;
     }
     if ($annot->alias) {
         if (!preg_match('/^(.+?)\\s*\\:\\s*(.+)$/', $annot->alias, $ms)) {
             throw new \Exception(sprintf("%s alias `%s` invalid ", $this->err_msg, $annot->alias));
         }
         $admin_alias = $ms[1];
         $action_alias = $ms[2];
         if (!$this->loader->hasAdminName($admin_alias)) {
             throw new \Exception(sprintf("%s admin name `%s` not exists in alias `%s`", $this->err_msg, $admin_alias, $annot->alias));
         }
         $page_generator_alias = $this->page_loader->getPageGeneratorByName($admin_alias);
         $page_generator_alias->addAlias($action_alias, $admin_name, $action_name, $m);
     }
     if (!$annot->template) {
         $annot->template = $this->admin->getBundleName() . ':' . preg_replace('/Controller$/', '', $controller_name) . ':' . $admin_name . '.' . $action_name . '.html.twig';
     }
     $requirement_keys = array();
     if (!$annot->path) {
         if ('index' === $action_name && !$annot->entity) {
             $annot->path = '/' . $this->route_path . '/';
         } else {
             if ('view' === $action_name && null === $annot->entity) {
                 $annot->entity = true;
             }
             if ($annot->entity) {
                 $annot->path = '/' . $this->route_path . '/' . $action_name . '/{' . $this->eneity_id_name . '}';
                 $requirement_keys[$this->eneity_id_name] = true;
             } else {
                 $annot->path = '/' . $this->route_path . '/' . $action_name . '/';
             }
         }
     } else {
         $annot->path = '/' . ltrim($annot->path, '/');
         if (preg_match_all('/\\{(.+?)\\}/', $annot->path, $ms)) {
             foreach ($ms[1] as $requirement_key) {
                 if (isset($requirement_keys[$requirement_key])) {
                     throw new \Exception(sprintf("%s : `%s` duplicate in path `%s`", $this->err_msg, $annot->path, $requirement_key));
                 }
                 $requirement_keys[$requirement_key] = true;
             }
         }
         if (isset($requirement_keys['entity_id'])) {
             $annot->path = str_replace('{entity_id}', '{' . $this->eneity_id_name . '}', $annot->path);
             $annot->entity = true;
             $requirement_keys[$this->eneity_id_name] = true;
             unset($requirement_keys['entity_id']);
         }
         if (isset($requirement_keys[$this->eneity_id_name])) {
             $annot->entity = true;
         }
     }
     $generator = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter();
     $dispatcher = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter();
     $dispatcher_args = array();
     $entity_object_name = '$' . $this->admin_name;
     $generator->write('function(\\Symfony\\Component\\PropertyAccess\\PropertyAccessorInterface $accessor,');
     if ($annot->entity) {
         $generator->write(sprintf('%s %s, ', '\\' . $this->admin_class, $entity_object_name));
     } else {
         if ($this->page_parent_entity) {
             $entity_object_name = '$' . $this->parent_admin->getName();
             $generator->write(sprintf('%s %s, ', '\\' . $this->parent_admin->getClassName(), $entity_object_name));
         }
     }
     $generator->writeln('array $options = array() ){')->indent();
     $dispatcher->writeln('function(\\Symfony\\Component\\PropertyAccess\\PropertyAccessorInterface $accessor, \\' . $m->getDeclaringClass()->getName() . ' $controller, \\Symfony\\Component\\HttpFoundation\\Request $request){')->indent();
     $dispatcher->writeln(sprintf('$controller->setPageAdmin("%s");', $this->admin_name));
     $requirements = array();
     $requirements_entitys = array();
     $route_config = array('_controller' => $m->getDeclaringClass()->getName() . '::dispatchAction', '_sf_web_page' => $admin_name . ':' . $action_name);
     $path = $this->getRoutePath($requirements_entitys, $requirements, $requirement_keys, $generator, $dispatcher, $annot->entity, $annot->path);
     $defaults = array();
     if ($annot->defaults) {
         $defaults = $annot->defaults;
     }
     foreach ($requirements_entitys as $requirement_key) {
         if (isset($requirement_keys[$requirement_key])) {
             unset($requirement_keys[$requirement_key]);
         }
     }
     if ($annot->requirements) {
         foreach ($annot->requirements as $requirement_key => $value) {
             if (isset($requirements[$requirement_key])) {
                 throw new \Exception(sprintf("%s `%s` duplicate requirements:%s ", $this->err_msg, $path, $requirement_key));
             }
             $requirements[$requirement_key] = $value;
         }
     }
     $add_default = function ($i, $name, $value) use(&$dispatcher_args, $generator) {
         $dispatcher_args[$i] = sprintf('$request->get("%s", %s)', $name, var_export($value, 1));
         $generator->writeln(sprintf(' if( !isset($options["%s"]) ) $options["%s"] = %s;', $name, $name, var_export($value, 1)));
     };
     foreach ($m->getParameters() as $i => $p) {
         $requirement_key = $p->getName();
         if (isset($requirement_keys[$requirement_key])) {
             if (isset($defaults[$requirement_key])) {
                 $add_default($i, $requirement_key, $defaults[$requirement_key]);
                 unset($defaults[$requirement_key]);
             } else {
                 if ($p->isDefaultValueAvailable()) {
                     $add_default($i, $requirement_key, $p->getDefaultValue());
                 } else {
                     $dispatcher_args[$i] = sprintf('$request->get("%s")', $p->getName());
                 }
             }
             unset($requirement_keys[$requirement_key]);
         } else {
             if (!$p->isDefaultValueAvailable()) {
                 // check if is request
                 if ($p->getClass()) {
                     $requirement_class = $p->getClass()->name;
                     if ('Symfony\\Component\\HttpFoundation\\Request' === $requirement_class) {
                         $dispatcher_args[$i] = '$request';
                     } else {
                         if (isset($requirements_entitys[$requirement_class])) {
                             $dispatcher_args[$i] = '$' . $this->loader->getNameByClass($requirement_class);
                         } else {
                             if ($this->loader->hasSuperAdminClass($requirement_class)) {
                                 $super_class = $this->loader->getSuperAdminClass($requirement_class);
                                 $dispatcher_args[$i] = '$controller->getAdminByClass(' . var_export($super_class, 1) . ')';
                             } else {
                                 throw new \Exception(sprintf("%s parameter:(%s %s) not defined on path:%s", $this->err_msg, $requirement_class, $requirement_key, $annot->path));
                             }
                         }
                     }
                 } else {
                     if (isset($defaults[$requirement_key])) {
                         $add_default($i, $requirement_key, $defaults[$requirement_key]);
                         unset($defaults[$requirement_key]);
                     } else {
                         throw new \Exception(sprintf("`%s` no value", $requirement_key));
                     }
                 }
             } else {
                 // maybe need add to other place
                 $dispatcher_args[$i] = var_export($p->getDefaultValue(), 1);
             }
         }
     }
     if (!empty($defaults)) {
         throw new \Exception(sprintf("%s defaults:%s not defined on path:%s", $this->err_msg, json_encode($defaults), $annot->path));
     }
     if (!empty($requirement_keys)) {
         throw new \Exception(sprintf("%s path option `{%s}` not defined on path:%s", $this->err_msg, json_encode($requirement_keys), $annot->path));
     }
     $this->action_cache[$action_name] = $annot;
     $route = new \Symfony\Component\Routing\Route($path, $route_config, $requirements);
     $this->page_loader->addPageRoute($admin_name, $action_name, $route, $m, $annot);
     $page_class = $this->page_loader->getCompileClass();
     $writer = $page_class->getLazyWriter();
     $generator->writeln('return $options;');
     $dispatcher->writeln(sprintf('return $controller->%s(%s);', $m->getName(), join(', ', $dispatcher_args)));
     $writer->write(sprintf('$this->cache["%s:%s"]["generator"] = ', $admin_name, $action_name))->indent()->write($generator->getContent())->writeln('}')->outdent()->writeln(";");
     $writer->write(sprintf('$this->cache["%s:%s"]["dispatcher"] = ', $admin_name, $action_name))->indent()->write($dispatcher->getContent())->writeln('}')->outdent()->writeln(";");
     return true;
 }