当前位置: 首页>>代码示例>>PHP>>正文


PHP Di::setDefault方法代码示例

本文整理汇总了PHP中Phalcon\Di::setDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::setDefault方法的具体用法?PHP Di::setDefault怎么用?PHP Di::setDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Di的用法示例。


在下文中一共展示了Di::setDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sqlite

 public function sqlite(UnitTester $I)
 {
     $I->wantToTest("Model validation by using SQLite as RDBMS");
     /** @var \Phalcon\Di\FactoryDefault $di */
     $di = Di::getDefault();
     $connection = $di->getShared('db');
     $di->remove('db');
     $di->setShared('db', function () {
         $connection = new Sqlite(['dbname' => TEST_DB_SQLITE_NAME]);
         /** @var \PDO $pdo */
         $pdo = $connection->getInternalHandler();
         $pdo->sqliteCreateFunction('now', function () {
             return date('Y-m-d H:i:s');
         });
         return $connection;
     });
     Di::setDefault($di);
     $this->success($I);
     $this->presenceOf($I);
     $this->email($I);
     $this->emailWithDot($I);
     $this->exclusionIn($I);
     $this->inclusionIn($I);
     $this->uniqueness1($I);
     $this->uniqueness2($I);
     $this->regex($I);
     $this->tooLong($I);
     $this->tooShort($I);
     $di->remove('db');
     $di->setShared('db', $connection);
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:31,代码来源:ValidationCest.php

示例2: setDI

 public function setDI(DiInterface $di)
 {
     $di->setShared('config', static::$config);
     $this->initEventsManager($di);
     parent::setDI($di);
     Di::setDefault($di);
 }
开发者ID:logikostech,项目名称:core,代码行数:7,代码来源:Bootstrap.php

示例3: _after

 /**
  * executed after each test
  */
 protected function _after()
 {
     if ($this->previousDependencyInjector instanceof DiInterface) {
         Di::setDefault($this->previousDependencyInjector);
     } else {
         Di::reset();
     }
 }
开发者ID:lisong,项目名称:incubator,代码行数:11,代码来源:EagerLoadingTest.php

示例4: _before

 /**
  * Executed before each test
  *
  * @param IntegrationTester $I
  */
 public function _before(IntegrationTester $I)
 {
     Di::setDefault($I->getApplication()->getDI());
     $this->modelsManager = $I->getApplication()->getDI()->getShared('modelsManager');
     $I->haveServiceInDi('modelsMetadata', function () {
         return new Memory();
     }, true);
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:13,代码来源:ControllersCest.php

示例5: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     $opts = ["schema" => "sql/myapp/schema.sql", "db" => ["host" => "127.0.0.1", "username" => "root", "password" => "", "dbname" => "myapp_testing"]];
     DbHelper::populateDb($opts);
     $di = DbHelper::createDi($opts["db"]);
     Di::reset();
     Di::setDefault($di);
 }
开发者ID:aforward,项目名称:phpweb,代码行数:8,代码来源:AccountsTest.php

示例6: doRequest

 /**
  * Makes a request.
  *
  * @param \Symfony\Component\BrowserKit\Request $request
  *
  * @return \Symfony\Component\BrowserKit\Response
  * @throws \RuntimeException
  */
 public function doRequest($request)
 {
     $application = $this->getApplication();
     $di = $application->getDI();
     Di::reset();
     Di::setDefault($di);
     $_SERVER = [];
     foreach ($request->getServer() as $key => $value) {
         $_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
     }
     if (!$application instanceof Application && !$application instanceof MicroApplication) {
         throw new RuntimeException('Unsupported application class.');
     }
     $_COOKIE = $request->getCookies();
     $_FILES = $this->remapFiles($request->getFiles());
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_REQUEST = $this->remapRequestParameters($request->getParameters());
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $_GET = $_REQUEST;
     } else {
         $_POST = $_REQUEST;
     }
     $uri = str_replace('http://localhost', '', $request->getUri());
     $_SERVER['REQUEST_URI'] = $uri;
     $_GET['_url'] = strtok($uri, '?');
     $_SERVER['QUERY_STRING'] = http_build_query($_GET);
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $di['request'] = Stub::construct($di->get('request'), [], ['getRawBody' => $request->getContent()]);
     $response = $application->handle();
     $headers = $response->getHeaders();
     $status = (int) $headers->get('Status');
     $headersProperty = new ReflectionProperty($headers, '_headers');
     $headersProperty->setAccessible(true);
     $headers = $headersProperty->getValue($headers);
     if (!is_array($headers)) {
         $headers = [];
     }
     $cookiesProperty = new ReflectionProperty($di['cookies'], '_cookies');
     $cookiesProperty->setAccessible(true);
     $cookies = $cookiesProperty->getValue($di['cookies']);
     if (is_array($cookies)) {
         $restoredProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
         $restoredProperty->setAccessible(true);
         $valueProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
         $valueProperty->setAccessible(true);
         foreach ($cookies as $name => $cookie) {
             if (!$restoredProperty->getValue($cookie)) {
                 $clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
                 $headers['Set-Cookie'][] = (string) $clientCookie;
             }
         }
     }
     return new Response($response->getContent(), $status ? $status : 200, $headers);
 }
开发者ID:vladislavl-hyuna,项目名称:crmapp,代码行数:62,代码来源:Phalcon.php

示例7: _before

 /**
  * executed before each test
  */
 protected function _before()
 {
     parent::_before();
     $di = $this->tester->getApplication()->getDI();
     $di->set('modelsManager', function () {
         return new Manager();
     });
     $di->set('modelsMetadata', function () {
         return new Memory();
     });
     Di::setDefault($di);
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:15,代码来源:CriteriaTest.php

示例8: resolve

 public function resolve(\Phalcon\Config $config)
 {
     $di = new \Phalcon\Di\FactoryDefault();
     $di->set('config', $config, true);
     $di->set('mongo', function () use($config) {
         $connectionString = "mongodb://{$config->mongo->host}:{$config->mongo->port}";
         $mongo = new \MongoClient($connectionString);
         return $mongo->selectDb($config->mongo->dbname);
     }, true);
     $di->set('collectionManager', function () {
         return new \Phalcon\Mvc\Collection\Manager();
     }, true);
     \Phalcon\Di::setDefault($di);
 }
开发者ID:vegas-cmf,项目名称:validation,代码行数:14,代码来源:bootstrap.php

示例9: _before

 /**
  * HOOK: before scenario
  *
  * @param TestCase $test
  * @throws ModuleException
  */
 public function _before(TestCase $test)
 {
     $application = (require $this->bootstrapFile);
     if (!$application instanceof Injectable) {
         throw new ModuleException(__CLASS__, 'Bootstrap must return \\Phalcon\\Di\\Injectable object');
     }
     $this->di = $application->getDI();
     if (!$this->di instanceof DiInterface) {
         throw new ModuleException(__CLASS__, 'Dependency injector container must implement DiInterface');
     }
     Di::reset();
     Di::setDefault($this->di);
     if ($this->di->has('session')) {
         $this->di['session'] = new PhalconMemorySession();
     }
     if ($this->di->has('cookies')) {
         $this->di['cookies']->useEncryption(false);
     }
     if ($this->config['cleanup'] && $this->di->has('db')) {
         if ($this->config['savepoints']) {
             $this->di['db']->setNestedTransactionsWithSavepoints(true);
         }
         $this->di['db']->begin();
     }
     // localize
     $bootstrap = $this->bootstrapFile;
     $this->client->setApplication(function () use($bootstrap) {
         $currentDi = Di::getDefault();
         $application = (require $bootstrap);
         $di = $application->getDI();
         if ($currentDi->has('db')) {
             $di['db'] = $currentDi['db'];
         }
         if ($currentDi->has('session')) {
             $di['session'] = $currentDi['session'];
         }
         if ($di->has('cookies')) {
             $di['cookies']->useEncryption(false);
         }
         return $application;
     });
 }
开发者ID:codeception,项目名称:base,代码行数:48,代码来源:Phalcon1.php

示例10: realpath

<?php

error_reporting(E_ALL);
define('APP_PATH', realpath('./../../'));
use Phalcon\Di;
try {
    /**
     * Read the configuration
     */
    $config = (include APP_PATH . "/app/config/config.php");
    /**
     * Read auto-loader
     */
    include APP_PATH . "/app/config/loader.php";
    /**
     * Read services
     */
    include APP_PATH . "/app/config/services.php";
    include_once APP_PATH . "/vendor/autoload.php";
    Di::reset();
    Di::setDefault($di);
} catch (\Exception $e) {
    echo $e->getMessage() . '<br>';
    echo '<pre>' . $e->getTraceAsString() . '</pre>';
}
开发者ID:boorlyk,项目名称:friendsApi,代码行数:25,代码来源:TestHelper.php

示例11: doRequest

 /**
  * Makes a request.
  *
  * @param \Symfony\Component\BrowserKit\Request $request
  *
  * @return \Symfony\Component\BrowserKit\Response
  * @throws \RuntimeException
  */
 public function doRequest($request)
 {
     $application = $this->getApplication();
     if (!$application instanceof Application && !$application instanceof MicroApplication) {
         throw new RuntimeException('Unsupported application class.');
     }
     $di = $application->getDI();
     /** @var \Phalcon\Http\Request $phRequest */
     if ($di->has('request')) {
         $phRequest = $di->get('request');
     }
     if (!$phRequest instanceof RequestInterface) {
         $phRequest = new Request();
     }
     $uri = $request->getUri() ?: $phRequest->getURI();
     $pathString = parse_url($uri, PHP_URL_PATH);
     $queryString = parse_url($uri, PHP_URL_QUERY);
     $_SERVER = $request->getServer();
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = null === $queryString ? $pathString : $pathString . '?' . $queryString;
     $_COOKIE = $request->getCookies();
     $_FILES = $this->remapFiles($request->getFiles());
     $_REQUEST = $this->remapRequestParameters($request->getParameters());
     $_POST = [];
     $_GET = [];
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $_GET = $_REQUEST;
     } else {
         $_POST = $_REQUEST;
     }
     parse_str($queryString, $output);
     foreach ($output as $k => $v) {
         $_GET[$k] = $v;
     }
     $_GET['_url'] = $pathString;
     $_SERVER['QUERY_STRING'] = http_build_query($_GET);
     Di::reset();
     Di::setDefault($di);
     $di['request'] = Stub::construct($phRequest, [], ['getRawBody' => $request->getContent()]);
     $response = $application->handle();
     $headers = $response->getHeaders();
     $status = (int) $headers->get('Status');
     $headersProperty = new ReflectionProperty($headers, '_headers');
     $headersProperty->setAccessible(true);
     $headers = $headersProperty->getValue($headers);
     if (!is_array($headers)) {
         $headers = [];
     }
     $cookiesProperty = new ReflectionProperty($di['cookies'], '_cookies');
     $cookiesProperty->setAccessible(true);
     $cookies = $cookiesProperty->getValue($di['cookies']);
     if (is_array($cookies)) {
         $restoredProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
         $restoredProperty->setAccessible(true);
         $valueProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
         $valueProperty->setAccessible(true);
         foreach ($cookies as $name => $cookie) {
             if (!$restoredProperty->getValue($cookie)) {
                 $clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
                 $headers['Set-Cookie'][] = (string) $clientCookie;
             }
         }
     }
     return new Response($response->getContent(), $status ? $status : 200, $headers);
 }
开发者ID:nsgomez,项目名称:Codeception,代码行数:73,代码来源:Phalcon.php

示例12: setDefault

 public static function setDefault(DiInterface $dependencyInjector)
 {
     parent::setDefault($dependencyInjector);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Di.php

示例13: _before

 /**
  * executed before each test
  */
 protected function _before()
 {
     $di = $this->tester->getApplication()->getDI();
     Di::setDefault($di);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:8,代码来源:ViewTest.php

示例14: setDefault

 public static function setDefault(DiInterface $di)
 {
     Di::setDefault($di);
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:4,代码来源:Factory.php

示例15: di

 /**
  * Get the available container instance.
  *
  * @param  string  $make
  * @param  array   $parameters
  * @return mixed|\Engine\DI\Factory
  */
 function di($make = null, $parameters = [])
 {
     if (is_null($make)) {
         return DI::getDefault();
     } elseif ($make instanceof DI) {
         return DI::setDefault($make);
     }
     return DI::getDefault()->get($make, $parameters);
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:16,代码来源:helpers.php


注:本文中的Phalcon\Di::setDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。