/**
  * This method takes the given request finds the resource and gets the response from the
  * resources controller.
  *
  * @param Request $r
  * @return string
  */
 public static function dispatch(Request $r)
 {
     $res = self::getListener($r->getKey());
     if ($res != NULL) {
         return $res->getController($r)->getResponse();
     }
     // if we rebuild on 404, disable this for performance
     if (Registry::get("AUTO_REBUILD_REQUEST_MAP")) {
         RequestMapGenerator::buildAll(true);
         $res = self::getListener($r->getKey());
         if ($res != NULL) {
             return $res->getController($r)->getResponse();
         }
     }
     // otherwise 404 (no need to add die, execution will end anyway
     header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
 }
 /**
  * Build a single package
  * @param string $package
  */
 public static function build($package)
 {
     $generator = new RequestMapGenerator();
     $contents = $generator->buildDirectory($package . '/controller/');
     self::writeRequestMap($package, $contents);
 }
Example #3
0
 /**
  * Include the class mapping and run the init script of the given package
  * @param string $package
  */
 public static function boot($package)
 {
     $tmpPath = self::$tmp . str_replace(DIRECTORY_SEPARATOR, "_", realpath($package));
     //load the class mapping
     try {
         include $tmpPath . ".classes.php";
     } catch (FrameEx $ex) {
         self::rebuildDirectory($package . "/");
     }
     //boot
     try {
         include_once realpath($package . DIRECTORY_SEPARATOR . "init.php");
     } catch (FrameEx $ex) {
         $ex->setMessage("Unable to boot package: {$package}: " . $ex->getMessage());
         throw $ex;
     }
     //load the class mapping
     try {
         include $tmpPath . ".request-map.php";
     } catch (FrameEx $ex) {
         RequestMapGenerator::build($package);
         include $tmpPath . ".request-map.php";
     }
     if (self::$autoloader) {
         self::$autoloader->addPath(realpath($package . DIRECTORY_SEPARATOR));
     }
     self::$loadedPackages[] = $package;
 }