You are here

protected function CallbackHandler::validateStringCallbackFor54 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/CallbackHandler.php \Zend\Stdlib\CallbackHandler::validateStringCallbackFor54()

Validate a static method call

Parameters

string $callback:

Return value

true|array

Throws

Exception\InvalidCallbackException if invalid

1 call to CallbackHandler::validateStringCallbackFor54()
CallbackHandler::call in vendor/zendframework/zend-stdlib/src/CallbackHandler.php
Invoke handler

File

vendor/zendframework/zend-stdlib/src/CallbackHandler.php, line 157

Class

CallbackHandler
CallbackHandler

Namespace

Zend\Stdlib

Code

protected function validateStringCallbackFor54($callback) {
  if (!strstr($callback, '::')) {
    return true;
  }
  list($class, $method) = explode('::', $callback, 2);
  if (!class_exists($class)) {
    throw new Exception\InvalidCallbackException(sprintf('Static method call "%s" refers to a class that does not exist', $callback));
  }
  $r = new ReflectionClass($class);
  if (!$r
    ->hasMethod($method)) {
    throw new Exception\InvalidCallbackException(sprintf('Static method call "%s" refers to a method that does not exist', $callback));
  }
  $m = $r
    ->getMethod($method);
  if (!$m
    ->isStatic()) {
    throw new Exception\InvalidCallbackException(sprintf('Static method call "%s" refers to a method that is not static', $callback));
  }

  // returning a non boolean value may not be nice for a validate method,
  // but that allows the usage of a static string callback without using
  // the call_user_func function.
  return [
    $class,
    $method,
  ];
}