随笔 - 79  文章 - 58  trackbacks - 0
<2015年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(9)

随笔分类

随笔档案

文章档案

相册

搜索

  •  

积分与排名

  • 积分 - 291999
  • 排名 - 87

最新评论

阅读排行榜

评论排行榜

Flight 是一个快速、简单、可扩展的 PHP 框架。 你能够使用 Flight 快速、轻松的构建 RESTful Web 应用程序。
helloworld示例:
require 'flight/Flight.php';
//指定路由
Flight::route('/', function(){
    echo 'hello world!';
});

Flight::start()
Flight类本身没有方法,只有一个静态成员$engine,这个是框架的引擎,通过魔术方法__callStatic来调用。
    public static function __callStatic($name$params) {
        static $initialized = false;

        if (!$initialized) {
            // 指定自动加载函数和目录
            require_once __DIR__.'/autoload.php';

            self::$engine = new \flight\Engine();

            $initialized = true;
        }

        return \flight\core\Dispatcher::invokeMethod(array(self::$engine$name), $params);
    }
类名使用\flight\Engine的方式,是通过Loader类来自动加载的
    public static function loadClass($class) {
        $class_file = str_replace(array('\\', '_'), '/', $class).'.php';
        //在注册的目录中寻找文件进行require
        foreach (self::$dirs as $dir) {
            $file = $dir.'/'.$class_file;
            if (file_exists($file)) {
                require $file;
                return;
            }
        }
    }

 Dispatcher用于处理事件的回调,事件可以简单的认为是方法名,除了调用事件的方法外, 还允许注册before和after钩子函数。
    public function run($namearray $params = array()) {
        $output = '';

        // Run pre-filters
        if (!empty($this->filters[$name]['before'])) {
            $this->filter($this->filters[$name]['before'], $params$output);
        }

        // Run requested method
        $output = $this->execute($this->get($name), $params);

        // Run post-filters
        if (!empty($this->filters[$name]['after'])) {
            $this->filter($this->filters[$name]['after'], $params$output);
        }

        return $output;
    }

Engine类负责加载一个HTTP请求运行指定的服务并产生一个HTTP响应
这四个类构建了Flight框架的核心



posted on 2015-04-25 10:25 merlinfang 阅读(433) 评论(0)  编辑 收藏 引用 所属分类: flight

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理