国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ??? ?? PHP ???? 學習Slim Framework for PHP v3 (1)

學習Slim Framework for PHP v3 (1)

Jun 13, 2016 pm 12:28 PM
function return this

學習Slim Framework for PHP v3 (一)

  因為公司的項目用到是slim 框架,所以想把它學習一下。在公司用到是Slim2版本,現(xiàn)在官網(wǎng)已經(jīng)到達 Slim3的版本了。官網(wǎng)地址:http://www.cnblogs.com/lmenglliren89php/。

  首先按照官網(wǎng)的教程,安裝Slim:

    1.curl -sS https://getcomposer.org/installer | sudo php --?--install-dir=/usr/local/bin --filename=composer

    2.composer require slim/slim "^3.0"

  這樣一個Slim就安裝好了。還有Apache的DirectDocumentroot設置:AllowOverride All。

  同時它自帶的Example的例子也是可以運行的,需要調(diào)整下文件夾的位置就好。

  

  如何才能理解一個框架呢?是很順利的使用嗎?還是從一步步去跟進去它的流程?

?

  我的思路是這樣的,我把這個Example改成自己的項目,然后在不知道如何去的時候去深挖一下,不知道這樣的邏輯是否正確,暫且就這樣做吧。

  項目邏輯要求是這樣的,頁面提交數(shù)據(jù)--->>接收數(shù)據(jù)--->>存入數(shù)據(jù)庫--->>記入日志--->>返回寫入成功

  接收數(shù)據(jù)的route:

    

$app->get('/replace/', function ($request, $response, $args) {         Example\Module\Replace::instance()->setBody($request, $response);    });

  

  要說的是Slim就是基于route概念的,它將所有的request都轉給不同的route,然后每個route完成功能,最后設定response,請求完畢。

  get方法就是去設定一個route,以后的‘replace’就會匹配到那個閉包函數(shù)中。

  

  而這個route是放在哪里呢?在APP.php中有個contianer。這個container是個什么東西呢,來看代碼:

  

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$container</span> =<span style="color: #000000;"> []){    </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$container</span><span style="color: #000000;">)) {        </span><span style="color: #800080;">$container</span> = <span style="color: #0000ff;">new</span> Container(<span style="color: #800080;">$container</span><span style="color: #000000;">);    }    </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$container</span><span style="color: #000000;"> instanceof ContainerInterface) {        </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> InvalidArgumentException('Expected a ContainerInterface'<span style="color: #000000;">);    }    </span><span style="color: #800080;">$this</span>->container = <span style="color: #800080;">$container</span><span style="color: #000000;">;}</span>

  來看Container怎么做的:

public function __construct(array $values = []){    parent::__construct($values);    $userSettings = isset($values['settings']) ? $values['settings'] : [];    $this->registerDefaultServices($userSettings);}private function registerDefaultServices($userSettings){    $defaultSettings = $this->defaultSettings;    /**     * This service MUST return an array or an     * instance of \ArrayAccess.     *     * @return array|\ArrayAccess     */    $this['settings'] = function () use ($userSettings, $defaultSettings) {        return new Collection(array_merge($defaultSettings, $userSettings));    };    if (!isset($this['environment'])) {        /**         * This service MUST return a shared instance         * of \Slim\Interfaces\Http\EnvironmentInterface.         *         * @return EnvironmentInterface         */        $this['environment'] = function () {            return new Environment($_SERVER);        };    }    if (!isset($this['request'])) {        /**         * PSR-7 Request object         *         * @param Container $c         *         * @return ServerRequestInterface         */        $this['request'] = function ($c) {            return Request::createFromEnvironment($c->get('environment'));        };    }    if (!isset($this['response'])) {        /**         * PSR-7 Response object         *         * @param Container $c         *         * @return ResponseInterface         */        $this['response'] = function ($c) {            $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);            $response = new Response(200, $headers);            return $response->withProtocolVersion($c->get('settings')['httpVersion']);        };    }    if (!isset($this['router'])) {        /**         * This service MUST return a SHARED instance         * of \Slim\Interfaces\RouterInterface.         *         * @return RouterInterface         */        $this['router'] = function () {            return new Router;        };    }    if (!isset($this['foundHandler'])) {        /**         * This service MUST return a SHARED instance         * of \Slim\Interfaces\InvocationStrategyInterface.         *         * @return InvocationStrategyInterface         */        $this['foundHandler'] = function () {            return new RequestResponse;        };    }    if (!isset($this['errorHandler'])) {        /**         * This service MUST return a callable         * that accepts three arguments:         *         * 1. Instance of \Psr\Http\Message\ServerRequestInterface         * 2. Instance of \Psr\Http\Message\ResponseInterface         * 3. Instance of \Exception         *         * The callable MUST return an instance of         * \Psr\Http\Message\ResponseInterface.         *         * @param Container $c         *         * @return callable         */        $this['errorHandler'] = function ($c) {            return new Error($c->get('settings')['displayErrorDetails']);        };    }    if (!isset($this['notFoundHandler'])) {        /**         * This service MUST return a callable         * that accepts two arguments:         *         * 1. Instance of \Psr\Http\Message\ServerRequestInterface         * 2. Instance of \Psr\Http\Message\ResponseInterface         *         * The callable MUST return an instance of         * \Psr\Http\Message\ResponseInterface.         *         * @return callable         */        $this['notFoundHandler'] = function () {            return new NotFound;        };    }    if (!isset($this['notAllowedHandler'])) {        /**         * This service MUST return a callable         * that accepts three arguments:         *         * 1. Instance of \Psr\Http\Message\ServerRequestInterface         * 2. Instance of \Psr\Http\Message\ResponseInterface         * 3. Array of allowed HTTP methods         *         * The callable MUST return an instance of         * \Psr\Http\Message\ResponseInterface.         *         * @return callable         */        $this['notAllowedHandler'] = function () {            return new NotAllowed;        };    }    if (!isset($this['callableResolver'])) {        /**         * Instance of \Slim\Interfaces\CallableResolverInterface         *         * @param Container $c         *         * @return CallableResolverInterface         */        $this['callableResolver'] = function ($c) {            return new CallableResolver($c);        };    }}

  會看到這段代碼就是初始化container中的router key,以后的route都加到這個里面就好了。

<strong> $this['router'] = function () {   return new Router; };<br /> <br /> </strong> 只是能不加入自己的Key呢?<strong><br /></strong>

  第一次寫,就先這樣吧。

?

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
C ??? return ???? ?? ??? ?? C ??? return ???? ?? ??? ?? Oct 07, 2023 am 10:58 AM

C ???? return? ???? ??? ????. 1. ?? ? ??? void? ??? ?? return ?? ???? ?? ??? ??? ??? ? ????. 2. ?? ? ??? void? ?? ??? ?? return ?? ?? ??? ???? ????. ??? ????? ?????. 3. ?? ??? ??? ?????. ?? ????? return ?? ???? ?? ??? ??? ??? ? ????. ??? ?? ???? ?? ??.

??? ?? ????? ??? ?? ????? Aug 04, 2023 am 10:33 AM

??? ?? ??? ???? ??? ??? ?? ????, ?? ????? ????? ?? ??? ???? ??? ???? ?? ?????. ?? ????? ?? ???? ????? ?????.

Java?? return ? finally ?? ?? ??? ?????? Java?? return ? finally ?? ?? ??? ?????? Apr 25, 2023 pm 07:55 PM

?? ??: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}# ?? ? ??? ??? ??? ??? ?? ? ????. return? finally ?? ?????. ????? ???? ?? ?? ????? ???????. ??? case1 ???? ????? ??? ???? ?? ??? ???? ? ???? ??? ???? ?????.

MySQL.proc ???? ??? ??? ?? ??? ?? MySQL.proc ???? ??? ??? ?? ??? ?? Mar 16, 2024 am 09:03 AM

MySQL.proc ???? ??? ??? ?? ??? ?? MySQL? ?? ???? ??? ?????? ?? ?????, ???? MySQL? ??? ? ?? ????(StoredProcedure)? ???? ???? ??? ????. MySQL.proc ???? ?? ????? ??, ??, ???? ?? ???? ??????? ?? ?? ????? ??? ??? ???? ?? ??? ??? ??????. ?? ???? MySQL.proc ???? ??? ??? ?? ??? ???????.

Python?? 'enumerate()' ??? ??? ?????? Python?? 'enumerate()' ??? ??? ?????? Sep 01, 2023 am 11:29 AM

?? ???? enumerate() ??? Python?? “enumerate()” ??? ??? ?? ?????. enumerate() ??? ?????? Python? enumerate() ??? ??? ???? ????? ????? ??? ??? ?????. ??? ??? ?-? ??? ?????. ?? ? ??? ???? ????? ?? ?????. ?? enumerate(iterable,start) ???? iterable - ??? ??? ???? iterablestart?? ??? ??? ??? ? ????. - ???? ? ? ??? ??? ??? ?? ???? start? ?????. ??? ?????

Vue2? ?? ?? ??? ??? ??? ??? ? ?? ??? ?? ?????????. Vue2? ?? ?? ??? ??? ??? ??? ? ?? ??? ?? ?????????. Dec 08, 2022 pm 08:22 PM

? ?? Vue ?? ??? ???? ? ??? ? ??? ?? ???? Vue2? ??? ???? ??? ???? ? ?? ??? ???? ?? ?? ???? ??? ??? ????!

JavaScript?? return ??? ?? JavaScript?? return ??? ?? Feb 18, 2024 pm 12:45 PM

JavaScript?? return? ????? ?? ?? ??? ?????. JavaScript?? return ?? ???? ???? ?? ???? ? ?????. ?? ??? ???? ? ??? ? ?? ?? ??? ??? ??? ??? ?? ??? ?? ????. return ??? ??? ?? ???? ??? ????. ? ?? return ?? ??? ??? ??? ?? ???? ? ??? ? ????. ??? ??? ????: functionadd(a,b){

PHP?? SOA ??? ???? ?? PHP?? SOA ??? ???? ?? May 18, 2023 pm 01:10 PM

???? ??? ?? SOA(??? ?? ????)? ???? ?? ?? ????? ??? ?? ????? ?????. SOA ????? ???? ???, ??? ? ??? ???? ??? ?? ? ?? ?? ????? ??????. ?? ???? ? ????? ??? PHP? SOA ??? ?? ?? ?? ?????? ?????. ???? PHP?? SOA ??? ???? ??? ??? ???????. 1. SOA? ?? ??? ?? ??? ?? ????? ???????.

See all articles