call() public method

Execute callback/hooks (supports 'class->method' format)
public call ( $func, $args = NULL, $hooks = '' ) : mixed | FALSE
$func callback
$args mixed
$hooks string
return mixed | FALSE
Esempio n. 1
0
 /**
  * auth service callback
  * @param Base $f3
  * @param $params
  */
 function callback(\Base $f3, $params)
 {
     $Opauth = new \Opauth($this->config, false);
     switch ($Opauth->env['callback_transport']) {
         case 'session':
             $response = $f3->get('SESSION.opauth');
             $f3->clear('SESSION.opauth');
             break;
         case 'post':
             $response = unserialize(base64_decode($f3->get('POST.opauth')));
             break;
         case 'get':
             $response = unserialize(base64_decode($f3->get('GET.opauth')));
             break;
         default:
             $f3->error(400, 'Unsupported callback_transport');
             break;
     }
     if (isset($response['error'])) {
         $f3->call($this->abortFunc, array($response));
         return;
     }
     $data = $response['auth'];
     // validate
     if (empty($data) || empty($response['timestamp']) || empty($response['signature']) || empty($data['provider']) || empty($data['uid'])) {
         $f3->error(400, 'Invalid auth response: Missing key auth response components');
     } elseif (!$Opauth->validate(sha1(print_r($data, true)), $response['timestamp'], $response['signature'], $reason)) {
         $f3->error(400, 'Invalid auth response: ' . $reason);
     } else {
         // It's all good
         $f3->call($this->successFunc, array($data));
     }
 }
Esempio n. 2
0
 /**
  * parse node data on template compiling
  * @param $node
  * @return string
  */
 function parseNode($node)
 {
     $src = false;
     $params = array();
     if (isset($node['@attrib'])) {
         $params = $node['@attrib'];
         unset($node['@attrib']);
     }
     // find src
     if (array_key_exists('src', $params)) {
         $src = $params['src'];
     } elseif (array_key_exists('href', $params)) {
         $src = $params['href'];
     }
     if ($src) {
         $out = '<?php \\Assets::instance()->addNode(array(';
         foreach ($params as $key => $val) {
             $out .= var_export($key, true) . '=>' . (preg_match('/{{(.+?)}}/s', $val) ? $this->template->token($val) : var_export($val, true)) . ',';
         }
         $out .= ')); ?>';
         return $out;
     }
     // inner content
     if (isset($node[0]) && isset($params['type'])) {
         if (!isset($params['group'])) {
             $params['group'] = $params['type'] == 'js' ? 'footer' : 'head';
         }
         if ($this->f3->get('ASSETS.handle_inline')) {
             return '<?php \\Assets::instance()->addInline(' . '$this->resolve(' . var_export($node, true) . ',get_defined_vars()),' . var_export($params['type'], true) . ',' . var_export($params['group'], true) . '); ?>';
         } else {
             // just bypass
             return $this->f3->call($this->formatter[$params['type']], array(array('data' => $this->template->build($node), 'origin' => 'inline')));
         }
     }
 }
Esempio n. 3
0
 public function run($event = 'before')
 {
     if (!isset($this->routes[$event])) {
         return true;
     }
     foreach ($keys = array_keys($this->routes[$event]) as $key) {
         $paths[] = str_replace('@', '*@', $key);
     }
     $vals = array_values($this->routes[$event]);
     array_multisort($paths, SORT_DESC, $keys, $vals);
     $this->routes[$event] = array_combine($keys, $vals);
     // Convert to BASE-relative URL
     $req = $this->f3->rel(urldecode($this->f3->URI));
     foreach ($this->routes[$event] as $pattern => $routes) {
         if (!($args = $this->f3->mask($pattern, $req))) {
             continue;
         }
         ksort($args);
         $route = NULL;
         if (isset($routes[$ptr = $this->f3->AJAX + 1][$this->f3->VERB])) {
             $route = $routes[$ptr];
         } elseif (isset($routes[\Base::REQ_SYNC | \Base::REQ_AJAX])) {
             $route = $routes[\Base::REQ_SYNC | \Base::REQ_AJAX];
         }
         if (!$route) {
             continue;
         }
         if ($this->f3->VERB != 'OPTIONS' && isset($route[$this->f3->VERB])) {
             $parts = parse_url($req);
             if ($this->f3->VERB == 'GET' && preg_match('/.+\\/$/', $parts['path'])) {
                 $this->f3->reroute(substr($parts['path'], 0, -1) . (isset($parts['query']) ? '?' . $parts['query'] : ''));
             }
             $handler = $route[$this->f3->VERB][0];
             if (is_bool(strpos($pattern, '/*'))) {
                 foreach (array_keys($args) as $key) {
                     if (is_numeric($key) && $key) {
                         unset($args[$key]);
                     }
                 }
             }
             if (is_string($handler)) {
                 // Replace route pattern tokens in handler if any
                 $handler = preg_replace_callback('/@(\\w+\\b)/', function ($id) use($args) {
                     return isset($args[$id[1]]) ? $args[$id[1]] : $id[0];
                 }, $handler);
                 if (preg_match('/(.+)\\h*(?:->|::)/', $handler, $match) && !class_exists($match[1])) {
                     $this->f3->error(500, 'PreRoute handler not found');
                 }
             }
             // Call route handler
             return $this->f3->call($handler, array($this->f3, $args), 'beforeroute,afterroute') !== FALSE;
         }
     }
     return true;
 }
Esempio n. 4
0
//
//var_dump($a);
//var_dump($d);
//var_dump(namespace\MYCONST);
//echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
//define('foo',222);
//define(__NAMESPACE__.'foo',333);
//define(__NAMESPACE__.'\foo',111);
//var_dump(foo);
//var_dump(\foo);
//var_dump(\my\name\foo);
class OOB
{
    public function __construct()
    {
        var_dump($this);
        $this->ss = 'aa';
        var_dump($this->ss);
    }
}
class Base
{
    public function call()
    {
        $obj = new OOB();
    }
}
echo "here\n";
$obj = new Base();
$obj->call();