コード例 #1
0
 /**
  * Dispatch the route
  * @access 	Public
  * @return 	Mixed
  */
 public function dispatch()
 {
     // Make sure the controller is available
     if (!class_exists($this->controller)) {
         return false;
     }
     // Create a new instance of the controller
     $instance = new $this->controller($this->parameters);
     JEEngine::getEvent()->dispatch('jeroutedispatch', array(&$this->controller));
     // Return the controller
     return $instance;
 }
コード例 #2
0
 /**
  * Check data against a test
  * @param 	String 	$name 	The name of the test
  * @param 	Mixed 	$data 	The data to test
  * @access 	Public
  * @return 	Boolean
  */
 public static function test(string $name, $data) : bool
 {
     if (!self::testExists($name)) {
         throw new JEException(500, 'The requested test "' . $name . '" does not exist!');
     }
     $name = strtolower($name);
     // Try to set the data
     if (!self::$tests[$name]->setData($data)) {
         throw new JEException(500, 'Failed to set the data for test "' . $name . '"');
     }
     JEEngine::getEvent()->dispatch('jevalidatetest', array($name, $data));
     return self::$tests[$name]->validate();
 }
コード例 #3
0
 /**
  * Get a database instance
  * @access 	Public
  * @return 	String 			Full URL
  */
 public static function getInstance() : PDO
 {
     // Return the cached object
     if (is_object(self::$db) && get_class(self::$db) == 'PDO') {
         return self::$db;
     }
     // Connect to the database
     try {
         self::$db = new PDO('mysql:host=' . self::$host . (!empty(self::$port) ? ':' . self::$port : '') . ';dbname=' . self::$database, self::$username, self::$password);
     } catch (PDOException $e) {
         throw new JEException(500, 'Failed to connect to the database. Error: ' . $e->getMessage());
     }
     JEEngine::getEvent()->dispatch('jedbconnected', array(&self::$db));
     return self::$db;
 }
コード例 #4
0
 /**
  * Load the currently set language
  * @access 	Public
  * @return 	Boolean
  */
 public static function load()
 {
     if (empty(self::$lang) || !count(self::$availableLang)) {
         return false;
     }
     // Create the path
     $path = self::$path . self::$lang . '/';
     $files = scandir($path);
     foreach ($files as $file) {
         if ($file == '.' || $file == '..' || is_dir($path . $file)) {
             continue;
         }
         self::parseFile($path . $file);
     }
     JEEngine::getEvent()->dispatch('jeloadlanguage', array(self::$lang));
 }
コード例 #5
0
 /**
  * Throw an error
  * @param 	Integer $code 	The HTTP code
  * @param 	String 	$msg 	A message to add to the request
  * @param 	String 	$trace 	The code trace to display
  * @access 	Public
  * @return 	Boolean
  */
 public static function raiseError(int $code, string $msg = '', string $trace = '') : bool
 {
     if (array_key_exists($code, self::$codes)) {
         header($_SERVER['SERVER_PROTOCOL'] . ' ' . $code . ' ' . self::$codes[$code]);
     }
     // Create a new view if there is none set
     if (is_null(self::$view)) {
         self::$view = new JEErrorView($code, $msg, $trace);
     } else {
         self::$view->setCode($code);
         self::$view->setMessage($msg);
         self::$view->setTrace($trace);
     }
     JEEngine::getEvent()->dispatch('jeerror', array($code, $msg, $trace));
     // Enable language features in the error view
     exit(preg_replace_callback('/\\{\\{([a-z_]{1,})\\}\\}/', function ($match) {
         return JELanguage::get($match[1]);
     }, self::$view->display()));
     return true;
 }
コード例 #6
0
 /**
  * Match a route to the current requested URL
  * @param 	String 	$url 	The requested URL
  * @param 	String 	$method The method used
  * @access 	Private
  * @return 	Mixed
  */
 private function match(string $url, string $method)
 {
     foreach ($this->routes->getRoutes() as $route) {
         // Skip methods that dont match
         if (!in_array($method, (array) explode('|', $route->getMethod()))) {
             continue;
         }
         // Get and replace the URL parameters
         preg_match_all('/\\{([a-zA-Z]{1,})\\}/', $route->getRoute(), $vars);
         $parameter_names = $vars[1];
         $parameters = new stdClass();
         $regex = preg_replace('/{([a-zA-Z]{1,})}/', '([\\%a-zA-Z0-9_-]{1,})', $route->getRegex());
         // Check if it matches
         if (!preg_match('/^' . $this->basePath . $regex . '$/', $url, $matches)) {
             continue;
         }
         if (preg_match_all('/^' . $this->basePath . $regex . '$/', $url, $params)) {
             // Create the parameter array
             if (isset($params[1])) {
                 foreach ($parameter_names as $i => $param) {
                     $parameters->{$param} = $params[$i + 1][0];
                 }
             }
         }
         $route->setParameters($parameters);
         $route->dispatch();
         JEEngine::getEvent()->dispatch('jepostroute', array(&$route, &$parameters));
         return $route;
     }
     return false;
 }