示例#1
0
文件: App.php 项目: pinahq/framework
 public static function run()
 {
     if (!Site::init(!empty($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : '')) {
         @header('HTTP/1.1 404 Not Found');
         exit;
     }
     $method = Core::getRequestMethod();
     if (!in_array($method, array('get', 'put', 'delete', 'post'))) {
         @header("HTTP/1.1 501 Not Implemented");
         exit;
     }
     $data = Core::getRequestData();
     if (empty($data[$method]) && !in_array($_SERVER['REQUEST_URI'], array($_SERVER['SCRIPT_NAME'], "", "/"))) {
         $data[$method] = $_SERVER['REQUEST_URI'];
     }
     $resource = Core::getResource($data, $method);
     $staticFolders = array('/cache/', '/static/', '/uploads/', '/vendor/');
     foreach ($staticFolders as $folder) {
         if (strncasecmp($resource, $folder, strlen($folder)) === 0) {
             @header('HTTP/1.1 404 Not Found');
             exit;
         }
     }
     App::set(App::parse($resource));
     Core::resource($resource);
     Module::init();
     $response = Response\Factory::get($resource, $method);
     if (empty($response)) {
         @header('HTTP/1.1 406 Not Acceptable');
         exit;
     }
     Request::init($response, $data);
     echo Request::run($resource, $method);
 }
示例#2
0
 public function testCorrectReader()
 {
     require_once __DIR__ . '/D/CorrectReader.php';
     $throwException = false;
     try {
         new App(new CorrectReader());
     } catch (Exception $e) {
         $throwException = true;
     }
     $this->assertFalse($throwException, 'Passed IReader type to App and catch exception');
     $app = new App($reader = new CorrectReader());
     $this->assertEquals($reader->read(), $app->parse(), 'App parse must return reader result.');
 }
示例#3
0
 /**
  * @param App $app
  */
 private function checkRead($app)
 {
     $this->assertEquals([1, 2, 3], $app->parse());
 }