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


PHP DI::setDefault方法代码示例

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


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

示例1: tearDownAfterClass

 public static function tearDownAfterClass()
 {
     if (self::$previousDependencyInjector instanceof DI) {
         DI::setDefault(self::$previousDependencyInjector);
     }
     spl_autoload_unregister(array(__CLASS__, 'autoloadModels'));
 }
开发者ID:nejtr0n,项目名称:incubator,代码行数:7,代码来源:EagerLoadingTest.php

示例2: setUp

 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     $config = DI::getDefault()->get('config');
     $bootstrap = new Bootstrap($config);
     $bootstrap->setup();
     $this->di = $bootstrap->getDI();
     $this->bootstrap = $bootstrap;
     DI::setDefault($bootstrap->getDI());
 }
开发者ID:arius86,项目名称:core,代码行数:12,代码来源:TestCase.php

示例3: run

 /**
  * Bootstraps the application.
  */
 public function run($args = array())
 {
     // initialize our required services
     $this->initConfig();
     $this->initLoader();
     foreach ($this->services as $service) {
         $function = 'init' . ucfirst($service);
         $this->{$function}();
     }
     \Phalcon\DI::setDefault($this->di);
 }
开发者ID:NavinPanchu,项目名称:phalcon-boilerplate,代码行数:14,代码来源:Base.php

示例4: doRequest

 /**
  *
  * @param \Symfony\Component\BrowserKit\Request $request
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 public function doRequest($request)
 {
     $application = $this->getApplication();
     $di = $application->getDI();
     DI::reset();
     DI::setDefault($di);
     $_SERVER = array();
     foreach ($request->getServer() as $key => $value) {
         $_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
     }
     if (!$application instanceof \Phalcon\MVC\Application && !$application instanceof \Phalcon\MVC\Micro) {
         throw new \Exception('Unsupported application class');
     }
     $_COOKIE = $request->getCookies();
     $_FILES = $this->remapFiles($request->getFiles());
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_REQUEST = $this->remapRequestParameters($request->getParameters());
     if (strtoupper($request->getMethod()) == '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'), [], array('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 = array();
     }
     $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:itillawarra,项目名称:cmfive,代码行数:60,代码来源:Phalcon1.php

示例5: testRequiredServicesVerification

 public function testRequiredServicesVerification()
 {
     $di = \Phalcon\DI::getDefault();
     $emptyDI = new \Phalcon\DI\FactoryDefault();
     \Phalcon\DI::setDefault($emptyDI);
     $exception = null;
     try {
         new Scaffolding(new Scaffolding\Adapter\Mongo());
     } catch (NoRequiredServiceException $e) {
         $exception = $e;
     }
     $this->assertInstanceOf('\\Vegas\\Db\\Exception\\NoRequiredServiceException', $exception);
     //reverts DI
     \Phalcon\DI::setDefault($di);
 }
开发者ID:arius86,项目名称:core,代码行数:15,代码来源:ScaffoldingTest.php

示例6: testRegister

 /**
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::register
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::__construct
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::getProfiler
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::setProfiler
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::setDI
  * @covers Fabfuel\Prophiler\Plugin\Manager\Phalcon::getDI
  * @uses Fabfuel\Prophiler\Plugin\PluginAbstract
  * @uses Fabfuel\Prophiler\Plugin\Phalcon\Mvc\DispatcherPlugin
  */
 public function testRegister()
 {
     DI::setDefault(new FactoryDefault());
     $profiler = $this->getMockBuilder('Fabfuel\\Prophiler\\Profiler')->disableOriginalConstructor()->getMock();
     $pluginManager = new Phalcon($profiler);
     $dispatcher = $this->getMockBuilder('Phalcon\\Mvc\\Dispatcher')->getMock();
     $pluginManager->dispatcher = $dispatcher;
     $this->assertFalse($pluginManager->eventsManager->hasListeners('dispatch'));
     $this->assertFalse($pluginManager->eventsManager->hasListeners('view'));
     $this->assertFalse($pluginManager->eventsManager->hasListeners('db'));
     $pluginManager->register();
     $this->assertTrue($pluginManager->eventsManager->hasListeners('dispatch'));
     $this->assertTrue($pluginManager->eventsManager->hasListeners('view'));
     $this->assertTrue($pluginManager->eventsManager->hasListeners('db'));
 }
开发者ID:stanislav-web,项目名称:phalcon-development,代码行数:25,代码来源:PhalconTest.php

示例7: setUp

 public function setUp()
 {
     $this->di = new \Phalcon\DI\FactoryDefault();
     $this->di->setShared('db', function () {
         $db = new TestDatabase();
         $db->cleanUp();
         $db->constructUsers();
         return $db;
     });
     $this->di->setShared('session', function () {
         $adapter = new TestSession();
         $adapter->start();
         return $adapter;
     });
     $this->di->set('auth', new \AD\Auth\Security\Auth(new \Phalcon\Config(array('session_key' => 'testkey', 'hash_key' => 'hashkey', 'hash_method' => 'sha256')), '\\TestUser'));
     \Phalcon\DI::setDefault($this->di);
 }
开发者ID:amazingdreams,项目名称:phalcon-auth,代码行数:17,代码来源:AuthTest.php

示例8: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     $config = DI::getDefault()->get('config');
     $di = DI::getDefault();
     /**
      * Start the session the first time some component request the session service
      */
     $di->set('session', function () use($config) {
         $sessionAdapter = new SessionAdapter($config->session->toArray());
         if (!$sessionAdapter->isStarted()) {
             $sessionAdapter->start();
         }
         return $sessionAdapter;
     }, true);
     $di->set('sessionManager', function () use($di) {
         $session = new \Vegas\Session($di->get('session'));
         return $session;
     }, true);
     \Phalcon\DI::setDefault($di);
 }
开发者ID:vegas-cmf,项目名称:session,代码行数:20,代码来源:SessionTest.php

示例9: _before

 public function _before(\Codeception\TestCase $test)
 {
     $bootstrap = \Codeception\Configuration::projectDir() . $this->config['bootstrap'];
     $application = (require $bootstrap);
     if (!$application instanceof \Phalcon\DI\Injectable) {
         throw new \Exception('Bootstrap must return \\Phalcon\\DI\\Injectable object');
     }
     $this->di = $application->getDi();
     \Phalcon\DI::reset();
     \Phalcon\DI::setDefault($this->di);
     if (isset($this->di['session'])) {
         $this->di['session'] = new PhalconMemorySession();
     }
     if (isset($this->di['cookies'])) {
         $this->di['cookies']->useEncryption(false);
     }
     if ($this->config['cleanup'] && isset($this->di['db'])) {
         if ($this->config['savepoints']) {
             $this->di['db']->setNestedTransactionsWithSavepoints(true);
         }
         $this->di['db']->begin();
     }
     $this->client->setApplication(function () use($bootstrap) {
         $currentDi = \Phalcon\DI::getDefault();
         $application = (require $bootstrap);
         $di = $application->getDi();
         if (isset($currentDi['db'])) {
             $di['db'] = $currentDi['db'];
         }
         if (isset($currentDi['session'])) {
             $di['session'] = $currentDi['session'];
         }
         if (isset($di['cookies'])) {
             $di['cookies']->useEncryption(false);
         }
         return $application;
     });
 }
开发者ID:lenninsanchez,项目名称:donadores,代码行数:38,代码来源:Phalcon1.php

示例10: setUp

 /**
  * Initialize testing object
  *
  * @uses Auth
  * @uses \ReflectionClass
  */
 public function setUp()
 {
     $this->di = new FactoryDefault();
     $this->di->reset();
     // Setup DI
     $this->di = new DI();
     $this->di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->di->set('tag', function () {
         $tag = new \Phalcon\Tag();
         return $tag;
     });
     $this->di->set('escaper', function () {
         $escaper = new \Phalcon\Escaper();
         return $escaper;
     });
     DI::setDefault($this->di);
     $this->reflection = new \ReflectionClass('ULogin\\Auth');
     $this->auth = new Auth();
 }
开发者ID:stanislav-web,项目名称:phalcon-ulogin,代码行数:29,代码来源:AuthTest.php

示例11: define

<?php

//Test Suite bootstrap
include __DIR__ . "/../vendor/autoload.php";
define('TESTS_ROOT_DIR', dirname(__FILE__));
$configArray = (require_once dirname(__FILE__) . '/config.php');
$config = new \Phalcon\Config($configArray);
$di = new \Phalcon\DI\FactoryDefault();
\Phalcon\DI::setDefault($di);
开发者ID:maniolek,项目名称:demo,代码行数:9,代码来源:bootstrap.php

示例12: it

    });
    it("should create a from a empty QueryBuilder", function () {
        $builder = $this->di->get('modelsManager')->createBuilder()->columns('id, name, email, balance')->from('Spec\\Models\\User')->where('balance < 0');
        $dataTables = new DataTable();
        $response = $dataTables->fromBuilder($builder)->getResponse();
        expect($response)->toBe(['draw' => null, 'recordsTotal' => 0, 'recordsFiltered' => 0, 'data' => []]);
    });
    it("should create a QueryBuilder", function () {
        $builder = $this->di->get('modelsManager')->createBuilder()->columns('id, name, email, balance')->from('Spec\\Models\\User');
        $dataTables = new DataTable();
        $response = $dataTables->fromBuilder($builder)->getResponse();
        expect(count($response['data']))->toBe(20);
        expect(array_keys($response))->toBe(['draw', 'recordsTotal', 'recordsFiltered', 'data']);
        foreach ($response['data'] as $data) {
            expect(array_keys($data))->toBe(['id', 'name', 'email', 'balance', 'DT_RowId']);
            expect($data['DT_RowId'])->toBe($data['id']);
        }
    });
    it("should disable view & send response", function () {
        $this->di->set('view', function () {
            $view = Stub::create();
            return $view;
        });
        \Phalcon\DI::setDefault($this->di);
        $builder = $this->di->get('modelsManager')->createBuilder()->columns('id, name, email, balance')->from('Spec\\Models\\User');
        $dataTables = new DataTable();
        expect(function () use($dataTables, $builder) {
            $dataTables->fromBuilder($builder)->sendResponse();
        })->toEcho("{\"draw\":null,\"recordsTotal\":100,\"recordsFiltered\":100,\"data\":[{\"id\":\"0\",\"name\":\"wolff.jamel\",\"email\":\"rkuhn@dicki.com\",\"balance\":\"500\",\"DT_RowId\":\"0\"},{\"id\":\"1\",\"name\":\"violet36\",\"email\":\"imedhurst@paucek.com\",\"balance\":\"100\",\"DT_RowId\":\"1\"},{\"id\":\"2\",\"name\":\"beahan.abbigail\",\"email\":\"kenna23@mertz.biz\",\"balance\":\"200\",\"DT_RowId\":\"2\"},{\"id\":\"3\",\"name\":\"rickie05\",\"email\":\"echamplin@terry.com\",\"balance\":\"200\",\"DT_RowId\":\"3\"},{\"id\":\"4\",\"name\":\"runolfsdottir.evert\",\"email\":\"vern.goldner@rau.org\",\"balance\":\"200\",\"DT_RowId\":\"4\"},{\"id\":\"5\",\"name\":\"judson99\",\"email\":\"homenick.angeline@greenfelder.com\",\"balance\":\"200\",\"DT_RowId\":\"5\"},{\"id\":\"6\",\"name\":\"walter.eliseo\",\"email\":\"eleanore.gusikowski@yahoo.com\",\"balance\":\"100\",\"DT_RowId\":\"6\"},{\"id\":\"7\",\"name\":\"monserrate.lebsack\",\"email\":\"abraham.hane@gmail.com\",\"balance\":\"500\",\"DT_RowId\":\"7\"},{\"id\":\"8\",\"name\":\"llangworth\",\"email\":\"anderson.delphia@gmail.com\",\"balance\":\"100\",\"DT_RowId\":\"8\"},{\"id\":\"9\",\"name\":\"krajcik.rylee\",\"email\":\"franecki.conor@gmail.com\",\"balance\":\"500\",\"DT_RowId\":\"9\"},{\"id\":\"10\",\"name\":\"vsauer\",\"email\":\"maia14@conroy.com\",\"balance\":\"100\",\"DT_RowId\":\"10\"},{\"id\":\"11\",\"name\":\"green.german\",\"email\":\"hegmann.jane@hotmail.com\",\"balance\":\"200\",\"DT_RowId\":\"11\"},{\"id\":\"12\",\"name\":\"gebert\",\"email\":\"sdicki@gmail.com\",\"balance\":\"200\",\"DT_RowId\":\"12\"},{\"id\":\"13\",\"name\":\"michale68\",\"email\":\"qblock@yahoo.com\",\"balance\":\"200\",\"DT_RowId\":\"13\"},{\"id\":\"14\",\"name\":\"ismitham\",\"email\":\"hirthe.marjory@hotmail.com\",\"balance\":\"200\",\"DT_RowId\":\"14\"},{\"id\":\"15\",\"name\":\"jarrell09\",\"email\":\"cedrick04@gmail.com\",\"balance\":\"100\",\"DT_RowId\":\"15\"},{\"id\":\"16\",\"name\":\"iharvey\",\"email\":\"jude.christiansen@hotmail.com\",\"balance\":\"100\",\"DT_RowId\":\"16\"},{\"id\":\"17\",\"name\":\"bode.maxine\",\"email\":\"tmosciski@yahoo.com\",\"balance\":\"100\",\"DT_RowId\":\"17\"},{\"id\":\"18\",\"name\":\"murray.jeff\",\"email\":\"fjacobs@strosin.com\",\"balance\":\"200\",\"DT_RowId\":\"18\"},{\"id\":\"19\",\"name\":\"gmertz\",\"email\":\"marquardt.nicolas@williamson.com\",\"balance\":\"100\",\"DT_RowId\":\"19\"}]}");
    });
});
开发者ID:aisuhua,项目名称:phalcon-datatables,代码行数:31,代码来源:DataTableSpec.php

示例13: setup

 /**
  * Executes all bootstrap initialization methods
  * This method can be overloaded to load own initialization method.
  * @return mixed
  */
 public function setup()
 {
     $this->di->set('config', $this->config);
     $this->initEnvironment($this->config);
     $this->initLoader($this->config);
     $this->initServices($this->config);
     $this->initModules($this->config);
     $this->initRoutes($this->config);
     $this->initRequest();
     $this->initDispatcher();
     $this->application->setDI($this->di);
     DI::setDefault($this->di);
     return $this;
 }
开发者ID:arius86,项目名称:core,代码行数:19,代码来源:Bootstrap.php

示例14: FactoryDefault

  <?php 
use Phalcon\DI, Phalcon\DI\FactoryDefault;
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('ROOT_PATH', __DIR__);
define('PATH_LIBRARY', __DIR__ . '/../app/library/');
define('PATH_SERVICES', __DIR__ . '/../app/services/');
define('PATH_RESOURCES', __DIR__ . '/../app/resources/');
set_include_path(ROOT_PATH . PATH_SEPARATOR . get_include_path());
// required for phalcon/incubator
include __DIR__ . "/../vendor/autoload.php";
// use the application autoloader to autoload the classes
// autoload the dependencies found in composer
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(ROOT_PATH));
$loader->register();
$di = new FactoryDefault();
DI::reset();
// add any needed services to the DI here
DI::setDefault($di);
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:20,代码来源:unit-testing-52.php

示例15: function

 *
 */
$container->set('db', function () use($config) {
    return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
});
/**
 * Models metadata
 *
 */
$container->set('modelsMetadata', function () use($config) {
    return new MetaDataAdapter();
});
/**
 * Session
 *
 */
$container->set('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Dispatcher
 *
 */
$container->set('dispatcher', function () {
    $dispatcher = new Dispatcher();
    return $dispatcher;
});
DI::setDefault($container);
return $container;
开发者ID:danzabar,项目名称:phalcon-starter,代码行数:31,代码来源:environment.php


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