Advertisement
stuppid_bot

Untitled

Jun 1st, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Core;
  4.  
  5. class Request {
  6.     private function __construct() {}
  7.  
  8.     public static function get(array $opts) {
  9.         if (!isset($opts['controller'])) {
  10.             throw new \Exception("Missing required key 'controller'");
  11.         }
  12.         $controller = new $opts['controller'];
  13.         $action = empty($opts['action']) ? 'index' : $opts['action'];
  14.         $args = empty($opts['args']) ? array() : $opts['args'];
  15.         if (!method_exists($controller, $action)) {
  16.             throw new \Exception("The action $action does not exists in class {$opts['controller']}");
  17.         }
  18.         return call_user_func_array(array($controller, $action), $args);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement