public function compile(array &$config)
 {
     $_config = $this->getPluginConfig();
     if ($_config) {
         $config[] = $_config;
     }
     $_module_path = sprintf('%s/../www/source/plugin/%s/%s.inc.php', $this->_plugin_manager->getContainer()->getParameter('kernel.root_dir'), $this->_plugin_manager->getPluginEntity()->identifier, $this->getIdentifier());
     $writer = new \CG\Generator\Writer();
     $writer->write('<')->writeln('?php')->writeln("if(!defined('IN_DISCUZ')) exit('Access Denied');");
     $writer->writeln(sprintf('\\Dev::getContainer()->get(%s)->dispatch();', json_encode($this->getServiceId())));
     \Dev::write_file($_module_path, $writer->getContent());
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bbs_parameters_file = $this->getContainer()->getParameter('kernel.root_dir') . '/config/parameters_bbs.yml';
     if (!file_exists($bbs_parameters_file)) {
         $parameters = array('parameters' => array());
         $output->writeln("generate parameters from discuz config files");
         $root_dir = $this->getContainer()->getParameter('sf.web_root_dir');
         $file = sprintf('%s/config/config_global.php', $root_dir);
         include $file;
         $parameters['parameters']['sf.bbs.memory_prefix'] = $_config['memory']['prefix'];
         $parameters['parameters']['sf.bbs.cookiepre'] = $_config['cookie']['cookiepre'];
         $parameters['parameters']['sf.bbs.security_authkey'] = $_config['security']['authkey'];
         $parameters['parameters']['sf.bbs.remote_appkey'] = $_config['remote']['appkey'];
         $file = sprintf('%s/config/config_ucenter.php', $root_dir);
         $const = $this->getDefineConst($file);
         $parameters['parameters']['sf.bbs.uc_key'] = $const['UC_KEY'];
         $file = sprintf('%s/uc_server/data/config.inc.php', $root_dir);
         $const = $this->getDefineConst($file);
         $parameters['parameters']['sf.bbs.ucs_found_pw'] = $const['UC_FOUNDERPW'];
         $parameters['parameters']['sf.bbs.ucs_found_salt'] = $const['UC_FOUNDERSALT'];
         $parameters['parameters']['sf.bbs.ucs_key'] = $const['UC_KEY'];
         $parameters['parameters']['sf.bbs.ucs_site_id'] = $const['UC_SITEID'];
         $parameters['parameters']['sf.bbs.ucs_mykey'] = $const['UC_MYKEY'];
         $data = \Symfony\Component\Yaml\Yaml::dump($parameters);
         \Dev::write_file($bbs_parameters_file, $data);
     } else {
         $output->writeln(sprintf("generate parameters from %s", $bbs_parameters_file));
         $parameters = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($bbs_parameters_file));
     }
     $parameters_file = $this->getContainer()->getParameter('kernel.root_dir') . '/config/parameters.yml';
     $_parameters = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($parameters_file));
     foreach ($parameters['parameters'] as $key => $value) {
         $_parameters['parameters'][$key] = $value;
     }
     $_data = \Symfony\Component\Yaml\Yaml::dump($_parameters);
     \Dev::write_file($parameters_file, $_data);
 }
예제 #3
0
 public function writeCache()
 {
     static $_psr4_map = null;
     if (null === $_psr4_map) {
         $_psr4_file = dirname((new \ReflectionClass('Composer\\Autoload\\ClassLoader'))->getFileName()) . '/autoload_psr4.php';
         if (!file_exists($_psr4_file)) {
             throw new \Exception(sprintf("psr4 file(%s) not exits!", $_psr4_file));
         }
         $_psr4_map = (include $_psr4_file);
     }
     $_class_file = null;
     foreach ($_psr4_map as $_namespace => $_namespace_dir) {
         if (!empty($_namespace_dir)) {
             $_pos = strpos($this->getName(), $_namespace);
             if (0 === $_pos) {
                 $_class_file = $_namespace_dir[0] . '/' . str_replace('\\', '/', substr($this->getName(), strlen($_namespace))) . '.php';
             }
         }
     }
     if (!$_class_file) {
         throw new \Exception(sprintf("can not resolve file for class(%s) by psr4 rule!", $this->getName()));
     }
     $shortName = pathinfo($_class_file, \PATHINFO_FILENAME);
     $namespace = $this->getNamespace();
     $writer = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter();
     $writer->writeln("<?php\n");
     if (!empty($namespace)) {
         $writer->writeln("namespace " . $namespace . ";\n");
     }
     $imports = $this->getUseStatements();
     foreach ($imports as $alias => $use) {
         $_alias = substr($use, -1 - strlen($alias));
         if ($_alias == '\\' . $alias) {
             $writer->writeln(sprintf("use %s ;", $use));
         } else {
             $writer->writeln(sprintf("use %s as %s ;", $use, $alias));
         }
     }
     $writer->writeln('')->writeln('/**')->writeln(' * This code has been auto-generated by the SymforceAdminBundule')->writeln(' * Manual changes to it will be lost.')->writeln(' */');
     if ($this->isAbstract()) {
         $writer->write('abstract ');
     } else {
         if ($this->isFinal()) {
             $writer->write('final ');
         }
     }
     $writer->write('class ' . $shortName);
     if ($this->getParentClassName()) {
         $writer->write(' extends ' . $this->getParentClassName());
     }
     $writer->writeln(' {')->indent();
     $lazy_writer = $this->getLazyWriter();
     foreach ($this->getProperties() as $property) {
         $property->writeCache($lazy_writer, $writer);
     }
     foreach ($this->lazy_properties as $name => $value) {
         $writer->writeln("\npublic \${$name} = " . $this->propertyEncode($value) . " ;");
         // $lazy_writer->writeln( '$this->' . $name . ' = ' .  . ' ; ' );
     }
     if ($this->hasMethod('__wakeup')) {
         $lazy_writer->writeln($this->getMethod('__wakeup')->getBody());
         $this->getMethod('__wakeup')->setBody($lazy_writer->getContent());
     } else {
         $this->setMethod(\CG\Generator\PhpMethod::create('__wakeup')->setFinal(true)->setVisibility('protected')->setBody($lazy_writer->getContent()));
     }
     foreach ($this->getMethods() as $method) {
         if ($method instanceof PhpMethod) {
             $method->flushLazyCode();
             $_body = $method->getWriter()->getContent();
         } else {
             $_body = $method->getBody();
         }
         $writer->write("\n");
         if ($method->getDocblock()) {
             $writer->writeln($method->getDocblock());
         }
         if ($method->isFinal()) {
             $writer->write('final ');
         }
         $writer->write($method->getVisibility())->write(' function ')->write($method->getName());
         $ps = $method->getParameters();
         if (empty($ps)) {
             $writer->write('()');
         } else {
             $writer->writeln('(')->indent();
             foreach ($method->getParameters() as $i => $p) {
                 if ($p->getType()) {
                     if (in_array($p->getType(), array('mixed'))) {
                         $writer->write('/** @var ' . $p->getType() . ' */');
                     } else {
                         $writer->write($p->getType() . ' ');
                     }
                 }
                 if ($p->isPassedByReference()) {
                     $writer->write(' & ');
                 }
                 $writer->write(' $')->write($p->getName());
                 if ($p->hasDefaultValue()) {
                     $writer->write(' = ' . json_encode($p->getDefaultValue()));
                 }
                 if ($i < count($ps) - 1) {
                     $writer->writeln(",");
                 } else {
                     $writer->write("\n");
                 }
             }
             $writer->writeln(')')->outdent();
         }
         $writer->writeln('{')->indent()->writeln($_body)->outdent()->writeln("}");
     }
     $writer->outdent()->writeln('}');
     $content = $writer->getContent();
     /**
      * convert the fake php code
      * '#php{% $this->admin->trans("test.form.enabled.choices.no") %}'
      */
     $content = preg_replace_callback(self::PHP_CODE, function ($m) {
         return stripslashes($m[1]);
     }, $content);
     $_class_dir = dirname($_class_file);
     if (!file_exists($_class_dir)) {
         if (!@mkdir($_class_dir, 0755)) {
             throw new \Exception(sprintf("mkdir(%s) error!", $_class_dir));
         }
     }
     \Dev::write_file($_class_file, $content);
     return $_class_file;
 }
예제 #4
0
 public function setup()
 {
     if (null !== $this->_plugin_entity) {
         throw new \Exception('big error!');
     }
     if (!$this->_container->getParameter('sf.bbs.plugin.enabled')) {
         return;
     }
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->_container->get('doctrine')->getManager();
     /*
     $all =  $em->getRepository(self::ENTITY_CLASS_PLUGIN)->findAll();
     $_types = array_flip($this->_plugin_modules_types);
     foreach($all as $it) {
         $aa = $it->getPluginModules() ;
         echo '// ', $it->name , ', ', $it->identifier, ', ', $it->directory, "\n";
         foreach($aa as $i => $_aa){
             if( is_integer($i) ) {
                 echo "\t  --> name=", $_aa['name']  ;
     
                 if( $_types[ $_aa['type'] ] ) {
                     echo ', type=(', $_aa['type'] , ', ',  $_types[ $_aa['type'] ], ')' ;
                 } else {
                     echo ', type=', $_aa['type'] ;
                 }
     
                 if( isset($_aa['menu']) && !empty($_aa['menu']) ) {
                     echo ', menu=',  strip_tags($_aa['menu']) ;
                 }
                 if( isset($_aa['adminid']) && $_aa['adminid'] ) {
                     echo ', adminid=',  $_aa['adminid'] ;
                 }
                 if( isset($_aa['url']) && $_aa['url'] ) {
                     echo ', url=',  $_aa['url'] ;
                 }
                 echo "\n";
             }
         }
     }
     */
     $this->_plugin_entity = $em->getRepository(self::ENTITY_CLASS_PLUGIN)->findOneBy(array('identifier' => 'sfapp'));
     if (!$this->_plugin_entity) {
         $app = new \Symforce\DiscuzBundle\Entity\Plugin();
         $app->name = 'Symfony';
         $app->identifier = 'sfapp';
         $app->directory = 'sfapp/';
         $app->available = 1;
         $app->adminid = 1;
         $app->copyright = 'Weststar Inc.';
         $app->version = '1.0';
         $this->_plugin_entity = $app;
     }
     /**
      * @var $plugin_module PluginModule
      */
     foreach ($this->_modules as $plugin_module) {
         $plugin_module->setup();
     }
     $modules = $this->_modules;
     usort($modules, function (PluginModule $a, PluginModule $b) {
         $_a = $a->getOrder();
         $_b = $b->getOrder();
         if ($_a !== null && $_b === null) {
             return true;
         }
         if ($_a === null && $_b !== null) {
             return false;
         }
         if ($_a !== null && $_b !== null) {
             return $_a > $_b;
         }
         $_a = $a->getName();
         $_b = $b->getName();
         return strcmp($_a, $_b);
     });
     $plugin_name = $this->_plugin_entity->identifier;
     $_modules_array = array();
     $embed_types = array('页面嵌入 - 普通版', '页面嵌入 - 手机版');
     foreach ($embed_types as $_embed_type) {
         $_modules_array[] = array('name' => $plugin_name, 'param' => '', 'menu' => '', 'url' => '', 'type' => $this->_plugin_modules_types[$_embed_type], 'adminid' => 0, 'displayorder' => 0, 'navtitle' => '', 'navicon' => '', 'navsubname' => '', 'navsuburl' => '');
     }
     $writer = new \CG\Generator\Writer();
     $writer->write('<')->writeln('?php')->writeln("if(!defined('IN_DISCUZ')) exit('Access Denied');")->writeln('\\Dev::getContainer()->get("sf.bbs.plugin_manager")->connect();');
     foreach ($this->_embed_helpers as $group => $group_hellers) {
         $writer->writeln(sprintf("\n// %s", $group));
         $group_class_name = sprintf('plugin_%s', $plugin_name);
         $group_parent_class_name = null;
         if ($group !== 'common') {
             $group_class_name = sprintf('plugin_%s_%s', $plugin_name, $group);
             $group_parent_class_name = sprintf('plugin_%s', $plugin_name);
             if ('mobile_common' === $group) {
                 $group_class_name = sprintf('mobileplugin_%s', $plugin_name);
                 $group_parent_class_name = null;
             } else {
                 if ('mobile_forum' === $group) {
                     $group_class_name = sprintf('mobileplugin_%s_forum', $plugin_name);
                     $group_parent_class_name = sprintf('mobileplugin_%s', $plugin_name);
                 } else {
                     if ('mobile_member' === $group) {
                         $group_class_name = sprintf('mobileplugin_%s_member', $plugin_name);
                         $group_parent_class_name = sprintf('mobileplugin_%s', $plugin_name);
                     }
                 }
             }
         }
         $writer->write('class ')->write($group_class_name);
         if ($group_parent_class_name) {
             $writer->write(' extends ')->write($group_parent_class_name);
         }
         $writer->writeln(" {\n")->indent();
         foreach ($group_hellers as $_embed_function_name => $helpers) {
             usort($helpers, function (EmbedHelper $a, EmbedHelper $b) {
                 $_a = $a->config->order;
                 $_b = $b->config->order;
                 if ($_a !== null && $_b === null) {
                     return true;
                 }
                 if ($_a === null && $_b !== null) {
                     return false;
                 }
                 if ($_a !== null && $_b !== null) {
                     return $_a > $_b;
                 }
                 $_a = $a->method->getName();
                 $_b = $b->method->getName();
                 return strcmp($_a, $_b);
             });
             /**
              * @var $_embed_helper EmbedHelper
              */
             $_embed_helper = $helpers[0];
             if ($_embed_function_name === $group_class_name) {
                 throw new \Exception(sprintf("%s with @(%s, method=%s) can not be construct", \Dev::getMethodDeclaring($_embed_helper->method), get_class($_embed_helper->config), $_embed_function_name));
             }
             $writer->writeln(sprintf('function %s%s {', $_embed_function_name, $_embed_helper->code))->indent();
             $_embed_function_count = count($helpers);
             $_embed_function_parameters = $_embed_helper->method->getParameters();
             $_embed_function_parameters_count = count($_embed_function_parameters);
             if ($_embed_function_count > 1) {
                 $writer->writeln('$cache = array();');
             }
             foreach ($helpers as $_embed_helper) {
                 if ($_embed_function_count > 1) {
                     $writer->write('$cache[] = ');
                 } else {
                     $writer->write('return ');
                 }
                 $writer->write(sprintf('\\Dev::getContainer()->get(%s)->%s(', json_encode($_embed_helper->plugin_module->getServiceId()), $_embed_function_name));
                 foreach ($_embed_function_parameters as $_embed_function_parameter_index => $_embed_function_parameter) {
                     $writer->write('$')->write($_embed_function_parameter->getName());
                     if ($_embed_function_parameter_index < $_embed_function_parameters_count - 1) {
                         $writer->write(', ');
                     }
                 }
                 $writer->writeln(');');
             }
             if ($_embed_function_count > 1) {
                 $writer->writeln('return \\Dev::getContainer()->get("sf.bbs.plugin_manager")->getMergedEmbedFunctionReturnValues($cache);');
             }
             $writer->outdent()->writeln("}\n");
         }
         $writer->outdent()->writeln("}");
     }
     $plugin_file = sprintf('%s/../www/source/plugin/%s/%s.class.php', $this->_container->getParameter('kernel.root_dir'), $plugin_name, $plugin_name);
     $this->_clear_cache_on_connected = \Dev::write_file($plugin_file, $writer->getContent());
     foreach ($modules as $plugin_module) {
         $plugin_module->compile($_modules_array);
     }
     if ($this->_container->getParameter('sf.bbs.plugin.debug')) {
         $_modules_array['system'] = 2;
     }
     $_modules_array['extra'] = array('installtype' => '', 'langexists' => 0);
     if (serialize($_modules_array) !== $this->_plugin_entity->modules) {
         $this->_plugin_entity->setPluginModules($_modules_array);
         $em->persist($this->_plugin_entity);
         $em->flush();
         $this->_clear_cache_on_connected = true;
     }
 }
예제 #5
0
 /**
  * @return \Symforce\AdminBundle\Compiler\Generator\PhpClass
  */
 public function compile()
 {
     parent::compile();
     // $this->children->properties
     $rc = $this->admin_object->reflection;
     $admin_class = $this->admin_object->getCompileClass();
     $class = $this->getCompileClass();
     $twig_writer = $this->_twig->getWriter();
     // generate twig template
     $twig_writer->writeln('{% set _object = object %}')->writeln('{% block content_view %}')->writeln('<div class="form-horizontal">')->indent();
     $children = array();
     foreach ($this->admin_object->form->children->properties as $property_name => $_property) {
         if (isset($this->children->properties[$property_name])) {
             $property = $this->children->properties[$property_name];
             $property->_annot = true;
         } else {
             $property = new ViewProperty($this->children, $this->admin_object, $property_name);
             $property->lazyInitialize();
             $children[$property_name] = $property;
         }
         if (null !== $_property->group && null === $property->group) {
             $property->set_group($_property->group);
         }
         if (null !== $_property->position && null === $property->position) {
             $property->set_position($_property->position);
         }
     }
     foreach ($rc->getProperties() as $p) {
         if ($p->isStatic()) {
             continue;
         }
         $property_name = $p->getName();
         if (isset($children[$property_name])) {
             continue;
         }
         if (isset($this->children->properties[$property_name])) {
             $property = $this->children->properties[$property_name];
         } else {
             $property = new ViewProperty($this->children, $this->admin_object, $property_name);
             $property->lazyInitialize();
             $property->_no_form_and_view = true;
         }
         $children[$property_name] = $property;
     }
     $macro_writer = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter();
     foreach ($children as $property_name => $property) {
         $label = null;
         if ($property->form_element) {
             $label = $property->form_element->label;
         } else {
             if (isset($this->admin_object->action_collection->children['list']->children->properties[$property_name])) {
                 $label = $this->admin_object->action_collection->children['list']->children->properties[$property_name]->label;
             } else {
                 $label = $property->label;
             }
         }
         $admin_twig_calss = var_export($this->admin_object->class_name, 1);
         $admin_twig_code = sprintf('sf_admin_class(%s)', $admin_twig_calss);
         $admin_class->addLazyArray('properties_label', $property_name, array($label->getPath(), $label->getDomain()));
         $macro_writer->write('{% ' . sprintf('macro macro_label_%s(admin=false)', $property_name) . ' %}')->write('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}');
         if ($this->admin_object->_final_template) {
             $macro_writer->write('{% ' . sprintf('import "%s" as parent_macro', $this->admin_object->_final_template) . ' %}')->write('{% ' . sprintf('if twig_macro_exists(parent_macro, "macro_label_%s") ', $property_name) . ' %}')->indent()->write('{{ ' . sprintf('parent_macro.macro_label_%s(admin)', $property_name) . '}}')->outdent()->write('{% else %}')->indent()->write('{{' . $property->compileLabel() . ' }}')->outdent()->write('{% endif %}');
         } else {
             $macro_writer->write('{{ ' . $property->compileLabel() . ' }}');
         }
         $macro_writer->writeln('{% endmacro %} ');
         $macro_writer->writeln('{% ' . sprintf('macro macro_value_%s(_object, _property_value=false, admin=false)', $property_name) . ' %}')->indent()->writeln('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}');
         if ($this->admin_object->generator->getParameter('kernel.debug')) {
             $macro_writer->writeln(sprintf('{{ sf_check_class(_object, %s) }}', $admin_twig_calss));
         }
         $macro_writer->writeln('{% if _property_value is same as(false) %}{% set _property_value = ' . $property->getTwigValue() . ' %}{% endif %}');
         if ($this->admin_object->_final_template) {
             $macro_writer->writeln('{% ' . sprintf('import "%s" as parent_macro', $this->admin_object->_final_template) . ' %}')->writeln('{% ' . sprintf('if twig_macro_exists(parent_macro, "macro_value_%s") ', $property_name) . ' %}')->indent()->writeln('{{ ' . sprintf('parent_macro.macro_value_%s(_object, _property_value, admin)', $property_name) . '}}')->outdent()->writeln('{% else %}')->indent()->writeln($property->compileValue())->outdent()->writeln('{% endif %}');
         } else {
             $macro_writer->writeln($property->compileValue());
         }
         $macro_writer->outdent()->writeln('{% endmacro %} ');
         $macro_writer->write("\n");
     }
     if ($this->admin_object->workflow) {
         $macro_writer->writeln('{% macro macro_workflow_report(admin=false) %}')->indent()->writeln('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}');
         $this->admin_object->workflow->compileListAction($macro_writer);
         $macro_writer->outdent()->writeln('{% endmacro %}');
     }
     \Dev::write_file($this->admin_object->_template_path, $macro_writer->getContent());
     if ($this->admin_object->form->groups) {
         foreach ($this->admin_object->form->groups as $_group) {
             $_annot = array('id' => $_group->id, 'label' => $_group->label);
             if ($_group->name) {
                 $_annot['name'] = $_group->name;
             }
             if (null !== $_group->position) {
                 $_annot['position'] = $_group->position;
             }
             $this->_groups[$_group->id] = new ActionPropertyGroup($_annot);
         }
     }
     if (!isset($this->_groups['default'])) {
         $this->_groups['default'] = new ActionPropertyGroup('default');
     }
     foreach ($children as $property_name => $property) {
         if ($property->form_element && 'apppassword' === $property->form_element->compile_form_type) {
             continue;
         }
         if ($property->_no_form_and_view) {
             continue;
         }
         if ($property->group) {
             if (isset($this->_groups[$property->group])) {
                 $group = $this->_groups[$property->group];
             } else {
                 $group = new ActionPropertyGroup($property->group);
                 $this->_groups[$property->group] = $group;
             }
         } else {
             $group = $this->_groups['default'];
         }
         $group->add($property->class_property, $property->position);
     }
     foreach ($this->_groups as $group) {
         $group->fixLabel($this->admin_object->form->tr_node, $this->admin_object->generator->sf_domain);
         $group->sort();
     }
     $_anonymous_children = array();
     foreach ($this->admin_object->_route_assoc->_anonymous_children as $child_admin_name => $child_properties) {
         $child_admin = $this->admin_object->generator->getAdminByName($child_admin_name);
         if (!$child_admin->_final_template) {
             continue;
         }
         $_anonymous_children[$child_admin_name] = $child_properties;
     }
     if (count($this->_groups) > 1) {
         foreach ($this->_groups as $group) {
             if (!count($group->properties)) {
                 continue;
             }
             $twig_writer->writeln('{% set view_property_count = 0 %}')->writeln('<fieldset class="view-group">')->indent();
             foreach ($group->properties as $property_name) {
                 $children[$property_name]->compileView($twig_writer);
             }
             $twig_writer->write('{% if view_property_count > 0 %}')->write('<legend class="view-group-header">')->write($group->label->getTwigCode())->write('</legend>')->writeln('{% endif %}')->outdent()->writeln('</fieldset>');
         }
         if (!empty($_anonymous_children)) {
             $twig_writer->writeln('{% set view_property_count = 0 %}')->writeln('<fieldset class="view-group">')->indent();
             $this->compileAnonymousChildren($_anonymous_children, $twig_writer);
             $twig_writer->write('{% if view_property_count > 0 %}')->write('<legend class="view-group-header">Others</legend>')->writeln('{% endif %}')->outdent()->writeln('</fieldset>');
         }
     } else {
         foreach ($this->_groups as $group) {
             $twig_writer->writeln('{% set view_property_count = 0 %}');
             foreach ($group->properties as $property_name) {
                 $children[$property_name]->compileView($twig_writer);
             }
         }
         $this->compileAnonymousChildren($_anonymous_children, $twig_writer);
     }
     $twig_writer->writeln('{% block _admin_view_extra %}')->writeln('{% endblock %}')->outdent()->writeln('</div>')->writeln('{% endblock %}');
     return $class;
 }
 public function flush(\Symforce\AdminBundle\Compiler\Generator $gen)
 {
     $template_path = $gen->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template_file;
     \Dev::write_file($template_path, $this->writer->getContent());
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * Performs the asset dump.
  *
  * @param AssetInterface  $asset  An asset
  * @param OutputInterface $output The command output
  *
  * @throws RuntimeException If there is a problem writing the asset
  */
 private function doDump(AssetInterface $asset, OutputInterface $output)
 {
     foreach ($this->getAssetVarCombinations($asset) as $combination) {
         $asset->setValues($combination);
         // resolve the target path
         $target = rtrim($this->basePath, '/') . '/' . $asset->getTargetPath();
         $target = str_replace('_controller/', '', $target);
         $target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());
         if (!is_dir($dir = dirname($target))) {
             $output->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
             if (false === @mkdir($dir, 0777, true)) {
                 throw new \RuntimeException('Unable to create directory ' . $dir);
             }
         }
         $output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
         if ($this->verbose) {
             if ($asset instanceof AssetCollectionInterface) {
                 foreach ($asset as $leaf) {
                     $root = $leaf->getSourceRoot();
                     $path = $leaf->getSourcePath();
                     $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
                 }
             } else {
                 $root = $asset->getSourceRoot();
                 $path = $asset->getSourcePath();
                 $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
             }
         }
         \Dev::write_file($target, $asset->dump());
     }
 }
예제 #9
0
 private function generateExpireCheckCache($expire_check_path)
 {
     $root_dir = dirname($this->container->getParameter('kernel.root_dir'));
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $bundles = array();
     foreach ($this->admin_generators as $key => $admin) {
         if (isset($bundles[$admin->bundle_name])) {
             continue;
         }
         $file = $admin->getFilename();
         $file = trim($fs->makePathRelative($file, $root_dir), '/');
         $bundles[$admin->bundle_name] = dirname($file) . '/';
         continue;
         if (!isset($dirs[$_dir])) {
             $dirs[$_dir] = array();
         }
         $_entity_file = basename($file);
         $dirs[$_dir][$_entity_file] = filemtime($admin->getFilename());
     }
     $dirs = array();
     foreach ($bundles as $entity_dir) {
         $finder = new \Symfony\Component\Finder\Finder();
         $finder->name('*.php');
         foreach ($finder->in($root_dir . '/' . $entity_dir) as $file) {
             $dirs[$entity_dir][$file->getRelativePathname()] = filemtime($file->getRealpath());
         }
     }
     $default_resources = array('app/config/symforce/admin.yml');
     foreach ($default_resources as $file) {
         $dirs[0][$file] = filemtime($root_dir . '/' . $file);
     }
     foreach ($this->expire_check_resources as $file) {
         $_file = trim($fs->makePathRelative($file, $root_dir), '/');
         if (!in_array($_file, $dirs[0])) {
             $dirs[0][$_file] = filemtime($file);
         }
     }
     /**
      * @todo add yml configure check 
      */
     \Dev::write_file($expire_check_path, '<' . '?php return ' . var_export($dirs, 1) . ';');
 }
예제 #10
0
 protected function compileGroup(\Symforce\AdminBundle\Entity\MenuGroup $group, $path)
 {
     $writer = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter();
     $id = 'sf_menu_group_' . $group->slug;
     $writer->writeln(sprintf('<!-- sf  menu group( %s ) -->', $group->name));
     if ($group->group_css) {
         $group_css = $group->group_css;
         $child_css = $group->child_css;
         $writer->writeln(sprintf('<style type="text/css">%s</style>', $group_css));
     }
     $writer->writeln(sprintf('<div id="%s" class="sf_menu_box %s">', $id, $group->group_class));
     $writer->writeln(sprintf('<%s>', $group->group_tag));
     foreach ($group->menu_list as $menu) {
         if ($menu->getParent()) {
             continue;
         }
         if ($menu->disabled) {
             continue;
         }
         $this->compileMenu($menu, $writer);
     }
     $writer->writeln(sprintf('</%s>', $group->group_tag));
     $writer->writeln(sprintf('</div>'));
     $writer->writeln(sprintf('<!-- /sf  menu group( %s ) -->', $group->name));
     \Dev::write_file($path, $writer->getContent());
 }