1.1 Minor是什么
Minor是一个简单但是优秀的PHP框架,It just did what a framework should do. 只做一个框架应该做的,简单而又强大!
框架Github地址:github.com/Orlion/Minor
(如果觉得还不错给个star哦(^-^)V)
作者: Orlion
知乎:https://www.zhihu.com/people/orlion
Github: https://github.com/Orlion
1.2 Minor有什么
1.2.1 Minor主要提供了:
1.2.2 Minor为什么只提供了这么点东西?
现在的PHP框架大多很臃肿,提供了各种功能,在本人看来这只是在重复造轮子(虽然写框架也是在重复造轮子...),框架只需要提供给用户一个架子和一些工具即可,不应该给用户一大堆东西(一大堆重复造的轮子),不应该捆绑用户而应该给用户极大自由,这样也会使用户更容易上手。个人觉得java的Spring框架就是一个很不错的框架,足够简单,足够强大,小即是美!而Minor就是在这种思想下诞生的框架。没有各种乱七八糟的分页、ORM、模板引擎、日志、队列等功能,就是一个很纯粹的“架子”。
1.2.3 优点
快! 性能高! 简单! 容易上手! 结构清晰!
小即是美!
1.3 安装
只需从github上(github.com/Orlion/Minor) git clone或者直接复制zip压缩包然后解压到项目中即可。
Minor框架通过设置 <span class="token keyword">public<span class="token operator">/<span class="token punctuation">.htaccess</span></span></span>
文件去除链接中的index<span class="token punctuation">.php</span>
。 如果你你的服务器使用的是 Apache,请确保开启 mod_rewrite
模块。
如果是 Nginx 服务器,将下列指令放到网址的配置文件中:
location /<span style="color: #000000;"> { try_files $uri $uri</span>/ /index.php?<span style="color: #000000;">$query_string; }</span>
这样当你访问http://localhost/public/时就可以看到安装成功的画面了。 (当然你也可以配置一下把public去掉)
1.4 Minor是如何运转的
1.4.1 整体流程
以访问网址http://www.servername.com/demo/test为例:
<span style="color: #008080;">define</span>('APP_DIR', <span style="color: #008080;">realpath</span>(__DIR__.'/../app/') .<span style="color: #000000;">DIRECTORY_SEPARATOR); </span><span style="color: #008080;">define</span>('PUBLIC_DIR', <span style="color: #008080;">realpath</span>(__DIR__) .<span style="color: #000000;">DIRECTORY_SEPARATOR); </span><span style="color: #008080;">define</span>('VENDOR_DIR', <span style="color: #008080;">realpath</span>(__DIR__.'/../vendor/') .<span style="color: #000000;">DIRECTORY_SEPARATOR); </span><span style="color: #008080;">define</span>('ROOT_DIR', <span style="color: #008080;">realpath</span>(__DIR__.'/../') .DIRECTORY_SEPARATOR);
<span style="color: #800080;">$app</span> = \Minor\Framework\App::<span style="color: #000000;">getInstance( </span><span style="color: #800080;">$config</span> = ['app' => <span style="color: #0000ff;">require</span> APP_DIR . 'Config/app.php', 'test' => <span style="color: #0000ff;">require</span> APP_DIR . 'Config/test.php'], <span style="color: #800080;">$providers</span> = <span style="color: #0000ff;">require</span> APP_DIR . 'Config/providers.php', <span style="color: #800080;">$routes</span> = <span style="color: #0000ff;">require</span> APP_DIR . 'Config/routes.php', <span style="color: #800080;">$events</span> = <span style="color: #0000ff;">require</span> APP_DIR . 'Config/events.php'<span style="color: #000000;"> );</span>
<span style="color: #800080;">$response</span> = <span style="color: #800080;">$app</span>-><span style="color: #000000;">handle( </span><span style="color: #800080;">$request</span> = \Minor\HttpKernel\MinorRequestBuilder::<span style="color: #000000;">buildMinorRequest() );</span>
<span style="color: #800080;">$response</span>->send();
1.4.2 App是如何处理请求的
<span style="color: #0000ff;"> public</span> <span style="color: #0000ff;">function</span> handle(MinorRequest <span style="color: #800080;">$minorRequest</span><span style="color: #000000;">) { </span><span style="color: #800080;">$minorResponse</span> = MinorResponse::<span style="color: #000000;">getInstance(); </span><span style="color: #800080;">$this</span>->minorRequest = <span style="color: #800080;">$minorRequest</span><span style="color: #000000;">; </span><span style="color: #0000ff;">list</span>(<span style="color: #800080;">$controllerName</span>, <span style="color: #800080;">$actionName</span>, <span style="color: #800080;">$params</span>) = <span style="color: #800080;">$this</span>->router->dispatcher(<span style="color: #800080;">$minorRequest</span>-><span style="color: #000000;">getUrl()); </span><span style="color: #0000ff;">if</span> (!(<span style="color: #800080;">$controllerName</span> && <span style="color: #800080;">$actionName</span> && <span style="color: #008080;">is_array</span>(<span style="color: #800080;">$params</span><span style="color: #000000;">))) { </span><span style="color: #0000ff;">if</span> (!Config::get(['app' => 'DEBUG']) && (<span style="color: #800080;">$handler</span> = Config::get(['app' => '404_HANDLER'])) && (<span style="color: #800080;">$handler</span><span style="color: #000000;"> instanceof \Closure)) { </span><span style="color: #800080;">$handler</span>(<span style="color: #800080;">$minorRequest</span>-><span style="color: #000000;">getRequestUrl()); } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> RouteException('404 Not Found'<span style="color: #000000;">); } } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$minorResponse</span> = <span style="color: #800080;">$this</span>->invoke(<span style="color: #800080;">$controllerName</span>, <span style="color: #800080;">$actionName</span>, <span style="color: #800080;">$params</span><span style="color: #000000;">); } </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$minorResponse</span><span style="color: #000000;">; }</span>
<span style="color: #800080;">$minorResponse = MinorResponse::getInstance();</span>
<span style="color: #0000ff;">list(<span style="color: #800080;">$controllerName, <span style="color: #800080;">$actionName, <span style="color: #800080;">$params) = <span style="color: #800080;">$this->router->dispatcher(<span style="color: #800080;">$minorRequest->getUrl());</span></span></span></span></span></span>
<span style="color: #800080;">$minorResponse = <span style="color: #800080;">$this->invoke(<span style="color: #800080;">$controllerName, <span style="color: #800080;">$actionName, <span style="color: #800080;">$params<span style="color: #000000;">); <span style="color: #0000ff;">return <span style="color: #800080;">$minorResponse;</span></span></span></span></span></span></span></span>
1.5 请忽视以上吹牛逼字段
恩!就是请忽视。别怪我没提醒