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)
 {
     $source_dir = __DIR__ . '/../Resources/docs/discuzx_embed.txt';
     $writer = new \CG\Generator\Writer();
     $writer->writeln('array(')->indent();
     $key = null;
     foreach (file($source_dir) as $ln) {
         $ln = trim($ln);
         if (empty($ln)) {
             continue;
         }
         if (preg_match('/^(.+)\\((.+)\\/\\s*\\)$/', $ln, $ms)) {
             if ($key) {
                 $writer->outdent()->writeln('),');
             }
             $name = $ms[1];
             $key = preg_replace('/\\//', '_', $ms[2]);
             $writer->writeln(sprintf('%s => array( // %s ', var_export($key, 1), $name))->indent();
             continue;
         }
         if (preg_match('/^.+\\.htm/', $ln)) {
             // echo $ln, "\n" ;
             $writer->writeln(sprintf('// %s ', $ln));
             continue;
         }
         if (preg_match('/([^\\s]+)\\s+([^\\s]+)/', $ln, $ms)) {
             $writer->writeln(sprintf('%s, // %s ', var_export($ms[2], 1), $ms[1]));
             continue;
         }
     }
     $writer->outdent()->writeln('),')->outdent()->write(');');
     $output->writeln($writer->getContent());
 }
 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;
     }
 }
 public static function dump($object, $deep = 4, $do_print = true)
 {
     if (!$do_print) {
         ob_start();
     }
     self::print_callback();
     $writer = new \CG\Generator\Writer();
     $writer->indent();
     $writer->write("\n");
     $visited = array();
     self::export($writer, $visited, $object, $deep);
     $writer->outdent();
     echo $writer->getContent(), "\n";
     if (!$do_print) {
         $out = ob_get_contents();
         ob_end_clean();
         return $out;
     }
 }