Created
March 31, 2014 16:54
-
-
Save meglio/9896773 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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