public function __construct(PropertyAnnotation $annotation, \ReflectionMethod $reflection) { $this->reflection = $reflection; $this->annotation = $annotation; if ($this->reflection->isPrivate() || $this->reflection->isProtected()) { $this->reflection->setAccessible(true); } }
/** * Prints warning about any hooked method with bad visibility (that are either protected or private) * @return void */ function appthemes_bad_method_visibility() { global $wp_filter; $arguments = func_get_args(); $tag = array_shift($arguments); $errors = new WP_Error(); if (!isset($wp_filter[$tag])) { return; } foreach ($wp_filter[$tag] as $prioritized_callbacks) { foreach ($prioritized_callbacks as $callback) { $function = $callback['function']; if (is_array($function)) { try { $method = new ReflectionMethod($function[0], $function[1]); if ($method->isPrivate() || $method->isProtected()) { $class = get_class($function[0]); if (!$class) { $class = $function[0]; } $errors->add('visiblity', $class . '::' . $function[1] . ' was hooked into "' . $tag . '", but is either protected or private.'); } } catch (Exception $e) { // Failure to replicate method. Might be magic method. Fail silently } } } } if ($errors->get_error_messages()) { foreach ($errors->get_error_messages() as $message) { echo $message; } } }
private function _invoke($clz = '', $act = '', $param, $namespace = 'Home\\Controller\\') { $clz = ucwords($clz); $clz_name = $namespace . $clz . 'Controller'; try { $ref_clz = new \ReflectionClass($clz_name); if ($ref_clz->hasMethod($act)) { $ref_fun = new \ReflectionMethod($clz_name, $act); if ($ref_fun->isPrivate() || $ref_fun->isProtected()) { $ref_fun->setAccessible(true); } if ($ref_fun->isStatic()) { $ref_fun->invoke(null); } else { $ref_fun_par = $ref_fun->getParameters(); if (!empty($param) && is_array($param)) { if (is_array($ref_fun_par) && count($ref_fun_par) == count($param)) { $ref_fun->invokeArgs(new $clz_name(), $param); } else { $ref_fun->invoke(new $clz_name()); } } else { $ref_fun->invoke(new $clz_name()); } } } } catch (\LogicException $le) { $this->ajaxReturn(array('status' => '500', 'info' => '服务器内部发生严重错误')); } catch (\ReflectionException $re) { $this->ajaxReturn(array('status' => '404', 'info' => '访问' . $clz . '控制器下的非法操作', 'data' => array('code' => $re->getCode()))); } }
protected function _checkProtection($protectionType) { // Check type if (!is_string($protectionType) || $protectionType != self::PROTECTION_CSRF && $protectionType != self::PROTECTION_CAPTCHA && $protectionType != self::PROTECTION_BRUTEFORCE && $protectionType != self::PROTECTION_XSS) { throw new \Exception('Invalid protection type : "' . $protectionType . '"'); } // Check class if (class_exists('framework\\security\\form\\' . ucfirst($protectionType))) { $className = 'framework\\security\\form\\' . ucfirst($protectionType); } else { $className = $protectionType; } $class = new \ReflectionClass($className); if (!in_array('framework\\security\\IForm', $class->getInterfaceNames())) { throw new \Exception('Form protection drivers must be implement framework\\security\\IForm'); } if ($class->isAbstract()) { throw new \Exception('Form protection drivers must be not abstract class'); } if ($class->isInterface()) { throw new \Exception('Form protection drivers must be not interface'); } $classInstance = $class->newInstanceWithoutConstructor(); $constuctor = new \ReflectionMethod($classInstance, '__construct'); if ($constuctor->isPrivate() || $constuctor->isProtected()) { throw new \Exception('Protection constructor must be public'); } return $className; }
/** * Returns whether this method is protected * * @return boolean TRUE if this method is protected */ public function isProtected() { if ($this->reflectionSource instanceof ReflectionMethod) { return $this->reflectionSource->isProtected(); } else { return parent::isProtected(); } }
public function testPublicize_with_protected_static_method() { $className = __FUNCTION__ . md5(uniqid()); eval(sprintf('class %s { protected static function foo() { return true; } }', $className)); $reflectionMethod = new ReflectionMethod($className, 'foo'); $this->assertTrue($reflectionMethod->isProtected()); $this->assertTrue($reflectionMethod->isStatic()); $this->assertSame($reflectionMethod, $reflectionMethod->publicize()); $this->assertSame(true, $reflectionMethod->invoke($className)); }
/** * Get output style for the given method's visibility. * * @param \ReflectionMethod $method * * @return string */ private function getVisibilityStyle(\ReflectionMethod $method) { if ($method->isPublic()) { return self::IS_PUBLIC; } elseif ($method->isProtected()) { return self::IS_PROTECTED; } else { return self::IS_PRIVATE; } }
/** * @param \ReflectionMethod $reflection */ public function setVisibilityFromReflection(\ReflectionMethod $reflection) { if ($reflection->isPublic()) { $this->setVisibility('public'); } if ($reflection->isProtected()) { $this->setVisibility('protected'); } if ($reflection->isPrivate()) { $this->setVisibility('private'); } }
/** * @param object $object * @param string $method * @param array $args * * @return mixed */ protected function callPrivateMethod($object, $method, $args = array()) { $reflectionMethod = new \ReflectionMethod($object, $method); if ($reflectionMethod->isPrivate() || $reflectionMethod->isProtected()) { $reflectionMethod->setAccessible(true); $result = $reflectionMethod->invokeArgs($reflectionMethod->isStatic() ? null : $object, $args); $reflectionMethod->setAccessible(false); return $result; } else { return call_user_func_array(array($object, $method), $args); } }
/** * @dataProvider templateDataProvider */ public function testGetVariable($data) { $method = new ReflectionMethod($this->parser, 'getVariable'); $this->assertTrue($method->isProtected()); $method->setAccessible(true); $this->assertEquals('Lex', $method->invoke($this->parser, 'name', $data)); $this->assertEquals(null, $method->invoke($this->parser, 'age', $data)); $this->assertEquals(false, $method->invoke($this->parser, 'age', $data, false)); $this->assertEquals(true, $method->invoke($this->parser, 'filters.enable', $data)); $this->assertEquals(null, $method->invoke($this->parser, 'filters.name', $data)); $this->assertEquals(false, $method->invoke($this->parser, 'filters.name', $data, false)); }
public static function fromReflection(\ReflectionMethod $ref) { $method = new static(); $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setName($ref->name); if ($docComment = $ref->getDocComment()) { $method->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment)); } foreach ($ref->getParameters() as $param) { $method->addParameter(static::createParameter($param)); } // FIXME: Extract body? return $method; }
/** * {@inheritdoc} */ public function execute(MetaModel $metaModel) { $object = $this->subNode->execute($metaModel); if (is_null($object)) { throw new ExecutionException("Calling method '{$this->method}' on null"); } $reflectionMethod = new \ReflectionMethod($object, $this->method); // God mode if ($reflectionMethod->isPrivate() || $reflectionMethod->isProtected()) { $reflectionMethod->setAccessible(true); } return $reflectionMethod->invoke($object); }
public static function fromReflection(\ReflectionMethod $ref) { $method = new static($ref->name); $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setBody(ReflectionUtils::getFunctionBody($ref)); $docblock = new Docblock($ref); $method->setDocblock($docblock); $method->setDescription($docblock->getShortDescription()); $method->setLongDescription($docblock->getLongDescription()); foreach ($ref->getParameters() as $param) { $method->addParameter(static::createParameter($param)); } return $method; }
protected function assertIsSingleton($class, $instance = null) { foreach (array('__construct', '__clone') as $methodName) { $method = new \ReflectionMethod($class, $methodName); $this->assertTrue($method->isProtected() || $method->isPrivate()); } $getInstance = function () use($class) { return call_user_func(array($class, 'getInstance')); }; if ($instance) { $this->assertEquals(spl_object_hash($instance), spl_object_hash($getInstance())); } $this->assertEquals(spl_object_hash($getInstance()), spl_object_hash($getInstance())); }
public static final function getService() { $class = get_called_class(); if (($rc = new ReflectionClass($class)) && $rc->isAbstract()) { throw new Exception('Class "' . $class . '", extending "Clap_ServiceInstance", cannot be called as a "Service" if it is "Abstract"'); } if (!method_exists($class, '__construct')) { throw new Exception('Class "' . $class . '" extending "Clap_ServiceInstance", require "' . $class . '" to implement the method "protected function __construct()"'); } if (($rm = new ReflectionMethod($class, '__construct')) && !$rm->isProtected()) { throw new Exception('Access type for method "' . $class . '::__construct()" must be declared as "protected" to be compatible with "Clap_ServiceInstance", in "' . $rm->getFileName() . '" on line "' . $rm->getStartLine() . '"'); } return new self($class); }
/** * @param \ReflectionMethod $reflectionMethod * @param \Donquixote\HastyReflectionCommon\Reflection\FunctionLike\MethodReflectionInterface $methodReflection */ private function assertEqualMethods(\ReflectionMethod $reflectionMethod, MethodReflectionInterface $methodReflection) { $this->assertEquals($reflectionMethod->isAbstract(), $methodReflection->isAbstract()); $this->assertEquals($reflectionMethod->getDeclaringClass()->getName(), $methodReflection->getDeclaringClassName()); $this->assertEquals($reflectionMethod->getDocComment(), $methodReflection->getDocComment()); $this->assertEquals($reflectionMethod->getShortName(), $methodReflection->getName()); $this->assertEquals($reflectionMethod->getName(), $methodReflection->getName()); $this->assertEquals($reflectionMethod->class . '::' . $reflectionMethod->getName(), $methodReflection->getQualifiedName()); $this->assertEquals($reflectionMethod->returnsReference(), $methodReflection->isByReference()); $this->assertEquals($reflectionMethod->isPrivate(), $methodReflection->isPrivate()); $this->assertEquals($reflectionMethod->isProtected(), $methodReflection->isProtected()); $this->assertEquals($reflectionMethod->isPublic(), $methodReflection->isPublic()); $this->assertEquals($reflectionMethod->isStatic(), $methodReflection->isStatic()); }
protected function resolvedActionMethod($handlerAdapter) { $action = $handlerAdapter->getAction(); if ($action !== 'run') { $action = $this->resolvedActionName($action); } if (in_array($action, array('doAction', 'beforeAction', 'afterAction', 'forwardAction')) || !method_exists($this, $action)) { throw new WindException('Your request action \'' . get_class($this) . '::' . $action . '()\' was not found on this server.', 404); } $method = new ReflectionMethod($this, $action); if ($method->isProtected()) { throw new WindException('Your request action \'' . get_class($this) . '::' . $action . '()\' was not found on this server.', 404); } return $action; }
protected function resolvedActionMethod($handlerAdapter) { $action = $handlerAdapter->getAction(); if ($action !== 'run') { $action = $this->resolvedActionName($action); } if (in_array($action, array('doAction', 'beforeAction', 'afterAction', 'forwardAction')) || !method_exists($this, $action)) { throw new WindException('[web.WindController.resolvedActionMethod] ', WindException::ERROR_CLASS_METHOD_NOT_EXIST); } $method = new ReflectionMethod($this, $action); if ($method->isProtected()) { throw new WindException('[web.WindController.resolvedActionMethod]', WindException::ERROR_CLASS_METHOD_NOT_EXIST); } return $action; }
/** * Tests the cache static instance method */ public function testInstance() { $file_instance = Cache::instance('file'); $file_instance2 = Cache::instance('file'); // Try and load a Cache instance $this->assertType('Kohana_Cache', Cache::instance()); $this->assertType('Kohana_Cache_File', $file_instance); // Test instances are only initialised once $this->assertTrue(spl_object_hash($file_instance) == spl_object_hash($file_instance2)); // Test the publically accessible Cache instance store $this->assertTrue(spl_object_hash(Cache::$instances['file']) == spl_object_hash($file_instance)); // Get the constructor method $constructorMethod = new ReflectionMethod($file_instance, '__construct'); // Test the constructor for hidden visibility $this->assertTrue($constructorMethod->isProtected(), '__construct is does not have protected visibility'); }
public static function reload_method($classname, $methodname) { $method = new ReflectionMethod($classname, $methodname); $visibility = RUNKIT_ACC_PUBLIC; if ($method->isProtected()) { $visibility = RUNKIT_ACC_PROTECTED; } else { if ($method->isPrivate()) { $visibility = RUNKIT_ACC_PRIVATE; } } if ($method->isStatic()) { $visibility = $visibility | RUNKIT_ACC_STATIC; } return runkit_method_redefine($classname, $methodname, self::getMethodArguments($classname, $methodname), self::getMethodCode($classname, $methodname), $visibility); }
public static function getRunkitMethodFlags($className, $methodName) { $ref = new ReflectionMethod($className, $methodName); $flags = 0; if ($ref->isPrivate()) { $flags |= RUNKIT_ACC_PRIVATE; } elseif ($ref->isProtected()) { $flags |= RUNKIT_ACC_PROTECTED; } else { $flags |= RUNKIT_ACC_PUBLIC; } if ($ref->isStatic()) { $flags |= RUNKIT_ACC_STATIC; } return $flags; }
/** * @param \ReflectionMethod $method * @return \Phpy\Method\Method */ public function method(\ReflectionMethod $method) { $phpyMethod = new Method($method->getName()); $phpyMethod->setStatic($method->isStatic())->setFinal($method->isFinal())->setAbstract($method->isAbstract()); if ($method->isPublic()) { $phpyMethod->setVisibility('public'); } elseif ($method->isProtected()) { $phpyMethod->setVisibility('protected'); } else { $phpyMethod->setVisibility('private'); } foreach ($method->getParameters() as $refParameter) { $phpyMethod->addParameter($this->parameter($refParameter)); } return $phpyMethod; }
public final function getMethodHeader(ReflectionMethod $method) { $param_sources = array(); foreach ($method->getParameters() as $param) { $param_sources[] = $this->generateParameterCode($param); } if ($method->isProtected()) { $modifier = 'protected'; } else { if ($method->isPrivate()) { $modifier = 'private'; } else { $modifier = 'public'; } } return sprintf('%s %sfunction %s(%s)', $modifier, $method->isStatic() ? 'static ' : '', $method->getName(), implode(', ', $param_sources)); }
function __construct($q) { // echo('<br />q3:' . $q.'<br />'); $data = explode("/", $q); $this->action = $data[0]; // /home/par1/par2 global $user; $menu_obj = new Menu(); //$this->params = @$data[1]; $new_params = ""; for ($i = 1; $i < count($data); $i++) { $new_params .= $data[$i] . "/"; } $new_params = substr(@$new_params, 0, strlen(@$new_params) - 1); $this->params = @$new_params; $function = $this->action; if (empty($this->action)) { $function = "home"; $this->action = $function; } elseif (!method_exists($this, $function)) { $function = "page_not_found"; $this->action = $function; } $reflection = new ReflectionMethod($this, $this->action); if ($reflection->isPublic()) { //echo "Public method"; } if ($reflection->isPrivate()) { //echo "Private method"; $function = "page_not_found"; } if ($reflection->isProtected()) { //echo "Protected method"; $function = "page_not_found"; } if (MAINTENANCE) { $function = "maintenance"; } // echo('function:' . $function); $this->{$function}($this->params); if ($user['id']) { //pr($user->id); $this->menu = $menu_obj->build_menu_by_client($user['cid']); } }
public function doAction($handlerAdapter) { $this->beforeAction($handlerAdapter); $action = $handlerAdapter->getAction(); if ($action !== 'run') { $action = $this->resolvedActionName($action); } if (in_array($action, array('doAction', 'beforeAction', 'afterAction', 'resolvedActionName')) || !method_exists($this, $action)) { throw new WindException('[command.WindCommandController.doAction] ', WindException::ERROR_CLASS_METHOD_NOT_EXIST); } $method = new ReflectionMethod($this, $action); if ($method->isProtected()) { throw new WindException('[command.WindCommandController.doAction] ', WindException::ERROR_CLASS_METHOD_NOT_EXIST); } $args = $this->getRequest()->getRequest('argv'); call_user_func_array(array($this, $action), $args); $this->afterAction($handlerAdapter); }
/** * @param \ReflectionMethod|\ReflectionProperty $element * @return bool */ private function filter($element, $static, $public_only) { if (!$element instanceof \ReflectionMethod && !$element instanceof \ReflectionProperty) { throw new \InvalidArgumentException('Parameter must be a member of ReflectionMethod or ReflectionProperty class'); } if ($static !== null && ($element->isStatic() xor $static)) { return false; } if ($element->isPublic()) { return true; } if ($public_only) { return false; } if ($element->isProtected()) { return true; } // $element is then private return $element->getDeclaringClass()->getName() === $this->getName(); }
public static final function getService(&$instances, $class) { $class = get_called_class(); // Class struct check : if (($rc = new ReflectionClass($class)) && $rc->isAbstract()) { throw new Exception('Class "' . $class . '", extending "Clap_ServiceSingleton", cannot be called as a "Service" if it is "Abstract"'); } if (!method_exists($class, '__construct')) { throw new Exception('Class "' . $class . '" extending "Clap_ServiceSingleton", require "' . $class . '" to implement method "protected function __construct()"'); } if (($rm = new ReflectionMethod($class, '__construct')) && !$rm->isProtected()) { throw new Exception('Access type for method "' . $class . '::__construct()" must be declared as "protected" to be compatible with "Clap_ServiceSingleton", in "' . $rm->getFileName() . '" on line "' . $rm->getStartLine() . '"'); } // Class instance creation : $rc = new ReflectionClass($class); $object = $rc->newInstanceWithoutConstructor(); $instances[$class] = $object; call_user_func(array($object, '__construct')); return $object; }
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)))); } }
protected function buildMethodSignature(\ReflectionMethod $method, bool $skipAbstract = false, bool $skipDefaultValues = false) : string { if ($method->isProtected()) { $code = 'protected '; } elseif ($method->isPrivate()) { $code = 'private '; } else { $code = 'public '; } if ($method->isAbstract()) { if (!$skipAbstract) { $code .= 'abstract '; } } elseif ($method->isFinal()) { $code .= 'final '; } if ($method->isStatic()) { $code .= 'static '; } $code .= 'function '; if ($method->returnsReference()) { $code .= '& '; } $code .= $method->getName() . '('; foreach ($method->getParameters() as $i => $param) { if ($i > 0) { $code .= ', '; } $code .= $this->buildParameterSignature($param, $skipDefaultValues); } $code .= ')'; if ($method->hasReturnType()) { $type = $method->getReturnType(); if ($type->isBuiltin) { $code .= ': ' . $type; } else { $code .= ': \\' . $type; } } return $code; }
function methodCheck($className, $methodName) { if (method_exists($className, $methodName)) { $refl = new ReflectionMethod($className, $methodName); if ($refl->isPrivate()) { throw new Exception("This method is not callable. Because this is private function."); } else { if ($refl->isProtected()) { throw new Exception("This method is not direct callable. Because this is protected function."); } else { try { $return = $refl->invoke(new $className()); } catch (Exception $e) { die($e->getMessage()); } } } return $return; } else { return false; } }