Skip to content

Instantly share code, notes, and snippets.

@meglio
Created March 31, 2014 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meglio/9896773 to your computer and use it in GitHub Desktop.
Save meglio/9896773 to your computer and use it in GitHub Desktop.
<?php
# Router:
R::route('GET|POST', '/ajax', '\_\web\Ajax::processAjaxCall');
# Handler method:
static function processAjaxCall()
{
$class = Req::request('class');
$method = Req::request('method');
if (empty($class) || empty($method))
self::error('Please specify class and method.');
if (strlen($class) > 500 || strlen($method) > 500)
self::error('Wrong class or method name.');
if (strpos($method, 'ajax') !== 0)
self::error('Method cannot be used ajaxy.');
$class = str_replace('|', '\\', $class);
$class = '_\\' . $class;
if (!class_exists($class))
self::error('Class does not exit.');
if (!in_array(AjaxyClass::fullClassName(), class_uses($class)))
self::error('Class cannot be used ajaxy.');
if (!method_exists($class, $method))
self::error('Method does not exit.');
$callable = [$class, $method];
if (!is_callable($callable))
self::error('Method is not callable.');
call_user_func($callable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment