Zaphpa_Callback_Util::getCallback PHP Method

getCallback() public static method

public static getCallback ( $callback, $file = null )
    public static function getCallback($callback, $file = null)
    {
        if ($file) {
            self::loadFile($file);
        }
        if (is_array($callback)) {
            $originalClass = array_shift($callback);
            $method = new ReflectionMethod($originalClass, array_shift($callback));
            if ($method->isPublic()) {
                if ($method->isStatic()) {
                    $callback = array($originalClass, $method->name);
                } else {
                    $callback = array(new $originalClass(), $method->name);
                }
            }
        }
        if (is_callable($callback)) {
            return $callback;
        }
        throw new Zaphpa_InvalidCallbackException('Invalid callback');
    }

Usage Example

Esempio n. 1
0
 public function route($uri = null)
 {
     if (empty($uri)) {
         // CAUTION: parse_url does not work reliably with relative URIs, it is intended for fully qualified URLs.
         // Using parse_url with URI can cause bugs like this: https://github.com/zaphpa/zaphpa/issues/13
         // We have URI and we could really use parse_url however, so let's pretend we have a full URL by prepending
         // our URI with a meaningless scheme/domain.
         $tokens = parse_url('http://foo.com' . $_SERVER['REQUEST_URI']);
         $uri = rawurldecode($tokens['path']);
     }
     /* Call preprocessors on each middleware impl */
     foreach (self::$middleware as $m) {
         $m->preprocess($this);
     }
     $routes = $this->getRoutes();
     foreach ($routes as $route) {
         $params = $route['template']->match($uri);
         if (!is_null($params)) {
             Zaphpa_Middleware::$context['pattern'] = $route['template']->getTemplate();
             Zaphpa_Middleware::$context['http_method'] = self::getRequestMethod();
             Zaphpa_Middleware::$context['callback'] = $route['callback'];
             $callback = Zaphpa_Callback_Util::getCallback($route['callback'], $route['file']);
             return $this->invoke_callback($callback, $params);
         }
     }
     if (strcasecmp(Zaphpa_Router::getRequestMethod(), "options") == 0) {
         return $this->invoke_options();
     }
     throw new Zaphpa_InvalidPathException('Invalid path');
 }
All Usage Examples Of Zaphpa_Callback_Util::getCallback
Zaphpa_Callback_Util