Пример #1
0
 public function checkMethod(\ReflectionMethod $method)
 {
     $class = $method->getDeclaringClass();
     if (!$class->isSubclassOf(self::BASE_CLASS_NAME)) {
         throw new \Exception(sprintf("%s with @(%s) must extends from class(%s)", \Dev::getMethodDeclaring($method), __CLASS__, self::BASE_CLASS_NAME));
     }
     if ($method->isPrivate() || $method->isPublic()) {
         throw new \Exception(sprintf("%s with @(%s) must be protected", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isStatic()) {
         throw new \Exception(sprintf("%s with @(%s) can not be static", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isAbstract()) {
         throw new \Exception(sprintf("%s with @(%s) can not be abstract", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isConstructor()) {
         throw new \Exception(sprintf("%s with @(%s) can not be constructor", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isDestructor()) {
         throw new \Exception(sprintf("%s with @(%s) can not be destructor", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     $ps = $method->getParameters();
     if (count($ps) !== 0) {
         throw new \Exception(sprintf("%s with @(%s) can not has parameters", \Dev::getMethodDeclaring($method), __CLASS__));
     }
 }
Пример #2
0
 public function checkMethod(\ReflectionMethod $method)
 {
     if ($method->isPrivate() || $method->isProtected()) {
         throw new \Exception(sprintf("%s with @(%s) must be public", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isStatic()) {
         throw new \Exception(sprintf("%s with @(%s) can not be static", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isAbstract()) {
         throw new \Exception(sprintf("%s with @(%s) can not be abstract", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isConstructor()) {
         throw new \Exception(sprintf("%s with @(%s) can not be constructor", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     if ($method->isDestructor()) {
         throw new \Exception(sprintf("%s with @(%s) can not be destructor", \Dev::getMethodDeclaring($method), __CLASS__));
     }
     $class = $method->getDeclaringClass();
     if (!$class->isSubclassOf(self::BASE_CLASS_NAME)) {
         throw new \Exception(sprintf("%s with @(%s) must extends from class(%s)", \Dev::getMethodDeclaring($method), __CLASS__, self::BASE_CLASS_NAME));
     }
     $parent = $class->getParentClass();
     $fn = $method->getName();
     if ($parent->hasMethod($fn)) {
         throw new \Exception(sprintf("%s with @(%s) can not use with parent class method(%s)", \Dev::getMethodDeclaring($method), __CLASS__, $fn));
     }
     if ($this->method) {
         if (!preg_match('/^[a-z][\\w\\_]+$/', $this->method)) {
             throw new \Exception(sprintf("%s with @(%s) method(%s) invalid", \Dev::getMethodDeclaring($method), __CLASS__, $this->method));
         }
     } else {
         $this->method = $fn;
     }
     if (!$this->type) {
         $this->type = 'common';
     }
     $exists = array('common' => array('spacecp_credit_extra', 'faq_extra', 'global_footer', 'global_footerlink', 'global_cpnav_top', 'global_cpnav_extra1', 'global_cpnav_extra2', 'global_usernav_extra1', 'global_usernav_extra2', 'global_usernav_extra3', 'global_usernav_extra4', 'global_nav_extra', 'global_header', 'global_userabout_top', 'userapp_menu_top', 'userapp_menu_middle', 'global_userabout_bottom'), 'forum' => array('collection_index_top', 'collection_index_bottom', 'collection_nav_extra', 'collection_index_top', 'collection_index_bottom', 'collection_index_top', 'collection_index_bottom', 'collection_nav_extra', 'collection_viewoptions', 'collection_view_top', 'collection_threadlistbottom', 'collection_relatedop', 'collection_view_bottom', 'collection_side_bottom', 'index_status_extra', 'index_nav_extra', 'index_top', 'index_catlist_top', 'index_favforum_extra', 'index_catlist', 'index_forum_extra', 'index_forum_extra', 'index_middle', 'index_bottom', 'index_side_top', 'index_side_bottom', 'viewthread_attach_extra', 'post_image_btn_extra', 'post_image_tab_extra', 'post_attach_btn_extra', 'post_attach_tab_extra', 'forumdisplay_leftside_top', 'forumdisplay_leftside_bottom', 'forumdisplay_forumaction', 'forumdisplay_modlink', 'forumdisplay_top', 'forumdisplay_middle', 'forumdisplay_postbutton_top', 'forumdisplay_threadtype_inner', 'forumdisplay_filter_extra', 'forumdisplay_threadtype_extra', 'forumdisplay_bottom', 'forumdisplay_side_top', 'forumdisplay_side_bottom', 'forumdisplay_fastpost_content', 'forumdisplay_fastpost_func_extra', 'forumdisplay_fastpost_ctrl_extra', 'global_login_text', 'forumdisplay_fastpost_btn_extra', 'forumdisplay_fastpost_sync_method', 'forumdisplay_filter_extra', 'forumdisplay_thread', 'forumdisplay_thread_subject', 'forumdisplay_author', 'forumdisplay_thread', 'forumdisplay_author', 'forumdisplay_threadlist_bottom', 'forumdisplay_postbutton_bottom', 'forumdisplay_postbutton_bottom', 'forumdisplay_subforum_extra', 'forumdisplay_subforum_extra', 'guide_nav_extra', 'guide_top', 'guide_bottom', 'forumdisplay_thread', 'index_navbar', 'post_top', 'post_middle', 'post_btn_extra', 'post_sync_method', 'post_bottom', 'post_activity_extra', 'post_debate_extra', 'post_editorctrl_right', 'post_editorctrl_left', 'post_editorctrl_top', 'post_editorctrl_bottom', 'post_side_top', 'post_side_bottom', 'post_infloat_top', 'post_infloat_middle', 'post_infloat_btn_extra', 'post_poll_extra', 'post_reward_extra', 'post_trade_extra', 'forumdisplay_modlayer', 'modcp_modlayer', 'viewthread_tradeinfo_extra', 'viewthread_top', 'viewthread_postbutton_top', 'viewthread_modoption', 'viewthread_beginline', 'viewthread_title_extra', 'viewthread_title_row', 'viewthread_middle', 'viewthread_bottom', 'viewthread_activity_extra1', 'viewthread_activity_extra2', 'viewthread_fastpost_side', 'viewthread_fastpost_content', 'viewthread_fastpost_func_extra', 'viewthread_fastpost_ctrl_extra', 'global_login_text', 'viewthread_fastpost_btn_extra', 'viewthread_postheader', 'viewthread_postheader', 'viewthread_postheader', 'viewthread_endline', 'viewthread_profileside', 'viewthread_imicons', 'viewthread_magic_user', 'viewthread_avatar', 'viewthread_sidetop', 'viewthread_sidebottom', 'viewthread_postheader', 'viewthread_modaction', 'viewthread_share_method', 'viewthread_useraction', 'viewthread_postsightmlafter', 'viewthread_postfooter', 'viewthread_postaction', 'viewthread_magic_thread', 'viewthread_magic_post', 'viewthread_endline', 'viewthread_posttop', 'global_login_text', 'viewthread_postbottom', 'viewthread_poll_top', 'viewthread_poll_bottom', 'viewthread_useraction_prefix', 'viewthread_useraction', 'viewthread_side_bottom', 'viewthread_trade_extra'), 'group' => array('group_navlink', 'forumdisplay_navlink', 'group_navlink', 'forumdisplay_navlink', 'group_top', 'forumdisplay_top', 'group_nav_extra', 'forumdisplay_nav_extra', 'group_bottom', 'forumdisplay_bottom', 'group_side_bottom', 'forumdisplay_side_bottom', 'forumdisplay_postbutton_top', 'forumdisplay_filter_extra', 'forumdisplay_thread', 'forumdisplay_postbutton_bottom', 'my_header', 'my_bottom', 'my_side_top', 'my_side_bottom', 'group_index_side', 'group_side_top', 'forumdisplay_side_top', 'index_header', 'index_top', 'index_bottom', 'index_side_top', 'index_side_bottom', 'index_top', 'index_grouplist', 'index_bottom', 'index_side_top', 'index_side_bottom'), 'home' => array('follow_nav_extra', 'follow_top', 'spacecp_avatar_top', 'spacecp_avatar_bottom', 'spacecp_blog_top', 'spacecp_blog_middle', 'spacecp_blog_bottom', 'spacecp_credit_top', 'spacecp_credit_extra', 'spacecp_credit_bottom', 'spacecp_credit_top', 'spacecp_credit_bottom', 'spacecp_privacy_top', 'spacecp_privacy_base_extra', 'spacecp_privacy_feed_extra', 'spacecp_privacy_bottom', 'spacecp_profile_top', 'spacecp_profile_extra', 'spacecp_profile_bottom', 'spacecp_promotion_top', 'spacecp_promotion_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'space_album_pic_top', 'space_album_pic_op_extra', 'space_album_pic_bottom', 'space_album_pic_face_extra', 'space_album_op_extra', 'space_blog_list_status', 'space_blog_title', 'space_blog_share_method', 'space_blog_op_extra', 'space_blog_face_extra', 'space_card_top', 'space_card_baseinfo_middle', 'space_card_baseinfo_bottom', 'space_card_option', 'space_card_magic_user', 'space_card_bottom', 'space_blog_comment_op', 'space_blog_comment_bottom', 'space_doing_top', 'space_doing_bottom', 'space_favorite_nav_extra', 'space_interaction_extra', 'global_usernav_extra1', 'global_usernav_extra2', 'space_home_side_top', 'space_home_side_bottom', 'space_home_top', 'space_home_navlink', 'space_home_bottom', 'magic_nav_extra', 'medal_nav_extra', 'space_menu_extra', 'space_profile_baseinfo_top', 'follow_profile_baseinfo_top', 'space_profile_baseinfo_middle', 'follow_profile_baseinfo_middle', 'space_profile_baseinfo_bottom', 'follow_profile_baseinfo_bottom', 'space_profile_extrainfo', 'follow_profile_extrainfo', 'space_share_comment_op', 'space_home_doing_sync_method', 'space_wall_face_extra'), 'member' => array('logging_side_top', 'logging_top', 'logging_input', 'logging_method', 'global_login_extra', 'register_side_top', 'register_top', 'register_input', 'register_logging_method', 'register_bottom'), 'portal' => array('portalcp_top', 'portalcp_extend', 'portalcp_middle', 'portalcp_bottom', 'view_article_top', 'view_article_subtitle', 'view_article_summary', 'view_article_content', 'view_share_method', 'view_article_op_extra', 'view_article_side_top', 'view_article_side_bottom'), 'ranklist' => array('ranklist_nav_extra'), 'search' => array('album_top', 'album_bottom', 'blog_top', 'blog_bottom', 'global_footer', 'global_footerlink', 'forum_top', 'forum_bottom', 'group_top', 'group_bottom', 'global_usernav_extra1', 'global_usernav_extra2', 'portal_top', 'portal_bottom'), 'userapp' => array('userapp_app_top', 'userapp_app_bottom', 'userapp_index_top', 'userapp_index_bottom', 'userapp_menu_top', 'userapp_menu_middle', 'userapp_menu_bottom'), 'mobile_common' => array('global_footer_mobile', 'global_header_mobile'), 'mobile_forum' => array('index_top_mobile', 'index_middle_mobile', 'index_bottom_mobile', 'forumdisplay_top_mobile', 'forumdisplay_thread_mobile', 'forumdisplay_bottom_mobile', 'viewthread_top_mobile', 'viewthread_posttop_mobile', 'viewthread_postbottom_mobile', 'viewthread_bottom_mobile'));
     if (!isset($exists[$this->type])) {
         throw new \Exception(sprintf("%s with @(%s) type(%s) must be one of(%s)", \Dev::getMethodDeclaring($method), __CLASS__, json_encode($this->type), join(', ', array_keys($exists))));
     }
 }
 public final function addAction(\Symforce\DiscuzBundle\Annotation\Action $config, \ReflectionMethod $method)
 {
     if ($config->name) {
         if (!preg_match('/^[a-zAZ\\_][\\_\\w]*$/', $config->name)) {
             throw new \Exception(sprintf("%s with @(%s) name(%s) invlaid", \Dev::getMethodDeclaring($method), get_class($config), json_encode($config->name)));
         }
     } else {
         $config->name = strtolower(preg_replace('/^on|Action$/', '', $method->getName()));
     }
     if (isset($this->action_helpers[$config->name])) {
         throw new \Exception(sprintf("%s with @(%s) name(%s) duplicate with %s ", \Dev::getMethodDeclaring($method), get_class($config), json_encode($config->name), \Dev::getMethodDeclaring($this->action_helpers[$config->name]->method)));
     }
     $this->action_helpers[$config->name] = new ActionHelper($config, $method, $this);
     if ($config->default) {
         if ($this->action_default) {
             throw new \Exception(sprintf("%s with @(%s) default duplicate with %s ", \Dev::getMethodDeclaring($method), get_class($config), \Dev::getMethodDeclaring($this->config_methods[$this->action_default]->method)));
         }
         $this->action_default = $config->name;
     }
 }
Пример #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;
     }
 }