<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 依賴容器 ***** Slim使用一個可選的依賴項容器來準備、管理和注入應用程序依賴項。Slim支持像PHP-DI一樣實現PSR-11的容器。 Slim uses an optional dependency container to prepare, manage, and inject application dependencies. Slim supports containers that implement[PSR-11](http://www.php-fig.org/psr/psr-11/)like[PHP-DI](http://php-di.org/doc/frameworks/slim.html). ## PHP-DI的示例用法 You don’t*have*to provide a dependency container. If you do, however, you must provide an instance of the container to`AppFactory`before creating an`App`. 您不必提供依賴容器。但是,如果這樣做,則必須在創建 **$app** 之前向`AppFactory`提供容器的實例。 ~~~php <?php use DI\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/../vendor/autoload.php'; // Create Container using PHP-DI $container = new Container(); // Set container to create App with on AppFactory AppFactory::setContainer($container); $app = AppFactory::create(); ~~~ 添加一個服務到您的容器: Add a service to your container: ~~~php $container->set('myService', function () { $settings = [...]; return new MyService($settings); }); ~~~ You can fetch services from your container explicitly as well as from inside a Slim application route like this: 你可以顯式地從你的容器中獲取服務,也可以從類似這樣的slim應用程序路由中獲取服務: ~~~php /** * Example GET route * * @param ServerRequestInterface $request PSR-7 request * @param ResponseInterface $response PSR-7 response * @param array $args Route parameters * * @return ResponseInterface */ $app->get('/foo', function (Request $request, Response $response, $args) { $myService = $this->get('myService'); // ...do something with $myService... return $response; }); ~~~ To test if a service exists in the container before using it, use the`has()`method, like this: 要在使用服務之前測試它是否存在于容器中,可以使用`has()`方法,如下所示: ~~~php /** * Example GET route * * @param ServerRequestInterface $request PSR-7 request * @param ResponseInterface $response PSR-7 response * @param array $args Route parameters * * @return ResponseInterface */ $app->get('/foo', function (Request $request, Response $response, $args) { if ($this->has('myService')) { $myService = $this->get('myService'); } return $response; }); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看