Example #1
0
 public static function register($prepend = false)
 {
     $error = false;
     if (self::$autoloader_set) {
         trigger_error("Auto loader already set", E_USER_NOTICE);
     } else {
         self::add_path(__DIR__ . DIRECTORY_SEPARATOR . "..");
         $class_extensions = spl_autoload_extensions();
         if (strpos($class_extensions, ".php") === false) {
             spl_autoload_extensions($class_extensions . ",.php");
         }
         if (is_array(spl_autoload_functions()) && in_array("spl_autoload", spl_autoload_functions())) {
             trigger_error("Auto loader already set", E_USER_NOTICE);
         } else {
             if (PHP_VERSION_ID < 50300) {
                 if (!spl_autoload_register("spl_autoload")) {
                     $error = true;
                 }
             } else {
                 if (!spl_autoload_register("spl_autoload", true, $prepend)) {
                     $error = true;
                 }
             }
         }
         if ($error) {
             trigger_error("Could not add autoloader to the queue", E_USER_NOTICE);
         } else {
             self::$autoloader_set = true;
         }
     }
 }
Example #2
0
<?php

// Include the YAR autoloader.
require_once __SYSTEM__ . DIRECTORY_SEPARATOR . "yar" . DIRECTORY_SEPARATOR . "yar" . DIRECTORY_SEPARATOR . "autoloader.php";
// Load the YAR autoloader.
yar_autoloader::register();
// Add the controllers directorary to the include path.
yar_autoloader::add_path(__DIR__ . DIRECTORY_SEPARATOR . "controllers");
// Create a new YAR object.
$router = new \yar\yar(true, null, true);
// Add routes from a file.
$router->add_routes_from_file(__SYSTEM__ . DIRECTORY_SEPARATOR . "routes.json");
// Find the route to serve.
$router->find_route("/home");
// Render the page.
$router->render();