本文整理汇总了PHP中ReflectionMethod::isStatic方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::isStatic方法的具体用法?PHP ReflectionMethod::isStatic怎么用?PHP ReflectionMethod::isStatic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::isStatic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createHandler
/**
* @param string | object $listener
* @param \ReflectionMethod $methodReflection
* @return array
*/
protected function createHandler($listener, \ReflectionMethod $methodReflection)
{
if (is_string($listener) && $methodReflection->isStatic()) {
return [$listener, $methodReflection->getName()];
} elseif (is_object($listener) && $methodReflection->isStatic()) {
return [get_class($listener), $methodReflection->getName()];
} elseif (is_object($listener) && $methodReflection->isStatic() == false) {
return [$listener, $methodReflection->getName()];
}
return false;
}
示例2: getMode
/**
* {@inheritDoc}
*/
public function getMode()
{
if ($this->reflection instanceof \ReflectionFunction) {
return self::MODE_FUNCTION;
} elseif ($this->reflection instanceof \ReflectionMethod) {
if ($this->reflection->isStatic()) {
return self::MODE_METHOD_STATIC;
} else {
return self::MODE_METHOD;
}
} else {
throw new \RuntimeException(sprintf('The reflection "%s" not supported.', get_class($this->reflection)));
}
}
示例3: execute
/**
* Execute callback
* @return mixed
*/
public function execute()
{
// token check
if (!$this->checkToken()) {
throw new InvalidArgumentException('Invalid security token.', self::ERROR_SECURITY_TOKEN);
}
// authorisation check
if (!$this->checkPermission()) {
throw new LogicException('Access denied.', self::ERROR_PERMISSION);
}
// function
if (function_exists($this->callable_name)) {
return call_user_func_array($this->callable_name, $this->args);
}
list($class, $method) = explode('::', $this->callable_name);
$methodRef = new ReflectionMethod($class, $method);
// static method
if ($methodRef->isStatic()) {
return call_user_func_array($this->callable_name, $this->args);
}
// object method - create object instance
$classRef = new ReflectionClass($class);
$cargsNum = $classRef->getConstructor()->getNumberOfParameters();
$cargs = array_slice($this->args, 0, $cargsNum);
$instance = $classRef->newInstanceArgs($cargs);
// call instance method
$args = array_slice($this->args, $cargsNum);
return $methodRef->invokeArgs($instance, $args);
}
示例4: getCallback
public static function getCallback($callback, $file = null)
{
try {
if ($file) {
self::loadFile($file);
}
if (is_array($callback)) {
$method = new \ReflectionMethod(array_shift($callback), array_shift($callback));
if ($method->isPublic()) {
if ($method->isStatic()) {
$callback = array($method->class, $method->name);
} else {
$callback = array(new $method->class(), $method->name);
}
}
} else {
if (is_string($callback)) {
$callback = $callback;
}
}
if (is_callable($callback)) {
return $callback;
}
throw new InvalidCallbackException("Invalid callback");
} catch (\Exception $ex) {
throw $ex;
}
}
示例5: set_title
/**
* @throws \InvalidArgumentException
*/
private function set_title()
{
/**
* @var $router Router
*/
$router = Application::get_class(Router::class);
$pageModel = $router->current_page();
if ($pageModel) {
$title = $this->titles[$pageModel->name];
if (is_array($title)) {
list($class, $method, $prefix) = array_pad($title, 3, '');
try {
$reflection_method = new \ReflectionMethod($class, $method);
$params = $router->get_route_params();
$params[] = $prefix;
if ($reflection_method->isStatic()) {
$this->current = call_user_func_array([$class, $method], $params);
} else {
$this->current = call_user_func_array([Application::get_class($class), $method], $params);
}
} catch (\Exception $e) {
Error::log($e->getMessage());
}
} else {
$this->current = $title;
}
}
}
示例6: __call
public function __call($method, $args)
{
if (stripos($method, 'static') === 0) {
$mtd = substr($method, 6);
$nmtd = strtolower($mtd);
if (!isset($this->staticMethods[$nmtd])) {
try {
$rm = new ReflectionMethod($this->classn, $mtd);
} catch (Exception $e) {
throw new Exception('Method "Clap_ServiceInstance->' . $method . '()" is trying to call "' . $this->classn . '::' . $mtd . '()" static method, which is not defined');
}
if (!$rm->isStatic()) {
throw new Exception('Method "Clap_ServiceInstance->' . $method . '()" cannot call "' . $this->classn . '::' . $mtd . '()" because this is not a static method');
}
$this->staticMethods[$nmtd] = true;
}
return call_user_func_array(array($this->classn, $mtd), $args);
} else {
$class = get_called_class();
if ($class == 'Clap_ServiceInstance') {
throw new Exception('Method "' . $method . '()" called on a "' . $this->classn . '" ServiceInstance, use "getNew()" or "getInstance()" to get an instance of "' . $this->classn . '"');
} else {
throw new Exception('Undefined method "' . $class . '::' . $method . '()" called, check "Backtrace" for more informations');
}
}
}
示例7: execute
public function execute($argv)
{
if (!is_array($argv)) {
$argv = array($argv);
}
$argc = count($argv);
if (empty($this->action)) {
throw new \Jolt\Exception('controller_action_not_set');
}
try {
$action = new \ReflectionMethod($this, $this->action);
} catch (\ReflectionException $e) {
throw new \Jolt\Exception('controller_action_not_part_of_class');
}
$paramCount = $action->getNumberOfRequiredParameters();
if ($paramCount != $argc && $paramCount > $argc) {
$argv = array_pad($argv, $paramCount, NULL);
}
ob_start();
if ($action->isPublic()) {
if ($action->isStatic()) {
$action->invokeArgs(NULL, $argv);
} else {
$action->invokeArgs($this, $argv);
}
}
$renderedController = ob_get_clean();
if (!empty($renderedController)) {
$this->renderedController = $renderedController;
} else {
$this->renderedController = $this->renderedView;
}
return $this->renderedController;
}
示例8: findRenderer
/**
* This method searches for the renderer in den Renderer directory and
* loads them. The class itself ensures to run this method once before
* the data from this run is needed.
*/
public function findRenderer()
{
if (!$this->findRendererAlreadyRun) {
foreach (glob(dirname(__FILE__) . DIRECTORY_SEPARATOR . "Renderer" . DIRECTORY_SEPARATOR . "*Renderer") as $filename) {
$filename = $filename . DIRECTORY_SEPARATOR . basename($filename) . ".php";
if (is_file($filename)) {
$className = basename($filename, '.php');
$classNameWithNamespace = 'PartKeepr\\Printing\\Renderer\\' . $className . '\\' . $className;
$exists = class_exists($classNameWithNamespace);
if ($exists) {
try {
$onRegister = new \ReflectionMethod($classNameWithNamespace, 'onRegister');
if ($onRegister->isStatic()) {
// Enough sanity checks, if now something goes wrong, we will fail.
$onRegister->invoke(null, $this);
} else {
trigger_error("Method onRegister in class {$classNameWithNamespace} is not static, ignoring class.", E_USER_WARNING);
}
} catch (\ReflectionException $e) {
trigger_error("Method onRegister in class {$classNameWithNamespace} gave an error: " . $e->getMessage() . ". Ignoring class.", E_USER_WARNING);
}
} else {
// Sanely ignore this case, because this may arise often if a needed library is not present.
// trigger_error("File $filename does not contain a class with $classNameWithNamespace.",E_USER_WARNING );
}
}
}
$this->findRendererAlreadyRun = true;
}
}
示例9: _invoke
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())));
}
}
示例10: registerPrefix
/**
*
* Expects an either a function name or an array of class and method as
* callback.
*
* @param string $prefix
* @param mixed $callback
* @param bool $is_fallback if true, method will be used as last resort (if there's no phptal_tales_foo)
*/
public function registerPrefix($prefix, $callback, $is_fallback = false)
{
if ($this->isRegistered($prefix) && !$this->_callbacks[$prefix]['is_fallback']) {
if ($is_fallback) {
return;
// simply ignored
}
throw new PHPTAL_ConfigurationException("Expression modifier '{$prefix}' is already registered");
}
// Check if valid callback
if (is_array($callback)) {
$class = new ReflectionClass($callback[0]);
if (!$class->isSubclassOf('PHPTAL_Tales')) {
throw new PHPTAL_ConfigurationException('The class you want to register does not implement "PHPTAL_Tales".');
}
$method = new ReflectionMethod($callback[0], $callback[1]);
if (!$method->isStatic()) {
throw new PHPTAL_ConfigurationException('The method you want to register is not static.');
}
// maybe we want to check the parameters the method takes
} else {
if (!function_exists($callback)) {
throw new PHPTAL_ConfigurationException('The function you are trying to register does not exist.');
}
}
$this->_callbacks[$prefix] = array('callback' => $callback, 'is_fallback' => $is_fallback);
}
示例11: getCallable
/**
* Resolves the target of the route and returns a callable.
*
* @param mixed $target
* @param array $construct_args
*
* @throws RuntimeException If the target is not callable
*
* @return callable
*/
private static function getCallable($target, array $construct_args)
{
if (is_string($target)) {
//is a class "classname::method"
if (strpos($target, '::') === false) {
$class = $target;
$method = '__invoke';
} else {
list($class, $method) = explode('::', $target, 2);
}
if (!class_exists($class)) {
throw new RuntimeException("The class {$class} does not exists");
}
$fn = new \ReflectionMethod($class, $method);
if (!$fn->isStatic()) {
$class = new \ReflectionClass($class);
$instance = $class->hasMethod('__construct') ? $class->newInstanceArgs($construct_args) : $class->newInstance();
$target = [$instance, $method];
}
}
//if it's callable as is
if (is_callable($target)) {
return $target;
}
throw new RuntimeException('The route target is not callable');
}
示例12: do_ajax
public function do_ajax()
{
$class = $_REQUEST['module'];
$function = $_REQUEST['act'];
if ($class == 'core' || $class == 'this') {
$module = 'core';
} else {
if (class_exists($class)) {
$module = $class;
} else {
$module = '\\module\\' . $class . '\\controller';
}
}
if (class_exists($module)) {
$class = new \ReflectionClass($module);
if ($class->hasMethod($function)) {
$method = new \ReflectionMethod($module, $function);
if ($method->isStatic()) {
$module::$function();
} else {
if ($module != 'core') {
$object = new $module();
$object->{$function}();
} else {
$this->{$function}();
}
}
}
}
ajax::do_serve();
exit;
}
示例13: dispatch
/**
* Executes an action with named parameters
* @param mixed $action An action that can be a function, callback or class method.
* @param array $params (optional) An array of named parameters to pass into the action.
* @return mixed Returns any values returned by the action.
*/
public function dispatch($action, $params = array())
{
$invokeParams = array();
if (is_array($action)) {
$reflection = new \ReflectionMethod($action[0], $action[1]);
if ($reflection->isStatic()) {
$invokeParams[] = null;
} else {
$invokeParams[] = $action[0];
}
} else {
$reflection = new \ReflectionFunction($action);
}
$pass = array();
foreach ($reflection->getParameters() as $param) {
/* @var $param ReflectionParameter */
if (isset($params[$param->getName()])) {
$pass[] = $params[$param->getName()];
} elseif ($param->isOptional()) {
try {
$pass[] = $param->getDefaultValue();
} catch (\ReflectionException $ex) {
// move on if there is no default value.
}
}
}
$invokeParams[] = $pass;
return call_user_func_array(array($reflection, 'invokeArgs'), $invokeParams);
}
示例14: profile
public function profile($classname, $methodname, $methodargs, $invocations = 1)
{
if (class_exists($classname) != TRUE) {
throw new Exception("{$classname} doesn't exist");
}
$method = new ReflectionMethod($classname, $methodname);
$this->reflection = $method;
$instance = NULL;
if (!$method->isStatic()) {
$class = new ReflectionClass($classname);
$instance = $class->newInstance();
}
$durations = array();
for ($i = 0; $i < $invocations; $i++) {
$start = microtime(true);
$method->invokeArgs($instance, $methodargs);
$durations[] = microtime(true) - $start;
$memory_script[] = memory_get_peak_usage(false) / 1024 / 1024;
// User from the script
$memory_real[] = memory_get_peak_usage(true) / 1024 / 1024;
// Allocated memory from the system
}
$duration["total"] = round(array_sum($duration), 4);
$duration["average"] = round($duration["total"] / count($durations), 4);
$duration["worst"] = round(max($durations), 4);
$mm_real["total"] = round(array_sum($memory_real), 4);
$mm_real["average"] = round($mm_real["total"] / count($memory_real), 4);
$mm_real["worst"] = round(max($memory_real), 4);
$mm_script["total"] = round(array_sum($memory_script), 4);
$mm_script["average"] = round($mm_script["total"] / count($memory_script), 4);
$mm_script["worst"] = round(max($memory_script), 4);
$this->details = array("date" => date('Y-m-d h:m:s'), "class" => $classname, "method" => $methodname, "arguments" => $methodargs, "duration" => $duration, "invocations" => $invocations, "allocated_memory_average" => $mm_real['average'], "allocated_memory_worst" => $mm_real['worst'], "script_memory_average" => $mm_script['average'], "script_memory_worst" => $mm_script['worst']);
$this->printDetails();
$this->storeDetails();
}
示例15: run
/**
* @param App\Request $request
* @return App\IResponse
*/
public function run(App\Request $request)
{
$this->request = $request;
$this->startup();
if (!$this->startupCheck) {
$class = (new \ReflectionClass($this))->getMethod('startup')->getDeclaringClass()->getName();
throw new Nette\InvalidStateException("'{$class}::startup()' or its descendant does not call parent method");
}
try {
$rm = new \ReflectionMethod($this, $this->getAction());
} catch (\ReflectionException $e) {
}
if (isset($e) || $rm->isAbstract() || $rm->isStatic() || !$rm->isPublic()) {
throw new App\BadRequestException("Method '{$request->getMethod()}' not allowed", 405);
}
$params = $this->getParameters();
$args = App\UI\PresenterComponentReflection::combineArgs($rm, $params);
$response = $rm->invokeArgs($this, $args);
if ($response === null) {
$response = new Responses\NullResponse();
} elseif (!$response instanceof App\IResponse) {
throw new Nette\InvalidStateException("Action '{$this->getAction(true)}' does not return instance of Nette\\Application\\IResponse");
}
return $response;
}