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


PHP Di::reset方法代码示例

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


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

示例1: modulesClosure

 public function modulesClosure(IntegrationTester $I)
 {
     $I->wantTo('handle request and get content by using single modules strategy (closure)');
     Di::reset();
     $_GET['_url'] = '/login';
     $di = new FactoryDefault();
     $di->set('router', function () {
         $router = new Router(false);
         $router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
         $router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
         return $router;
     });
     $application = new Application();
     $view = new View();
     $application->registerModules(['frontend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/backend/views/');
             return $view;
         });
     }]);
     $application->setDI($di);
     $I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:30,代码来源:ApplicationCest.php

示例2: _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

示例3: 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

示例4: 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

示例5: clearData

 public function clearData()
 {
     $count = Cars::count();
     if ($count > 0) {
         $cars = Cars::find();
         foreach ($cars as $car) {
             $car->delete();
         }
     }
     Di::reset();
 }
开发者ID:phalcon,项目名称:incubator,代码行数:11,代码来源:MongoCollectionTest.php

示例6: getRequestObject

 /**
  * Initializes the request object and returns it
  *
  * @author Nikolaos Dimopoulos <nikos@phalconphp.com>
  * @since  2014-10-05
  *
  * @return Request
  */
 protected function getRequestObject()
 {
     Di::reset();
     $di = new Di();
     $di->set('filter', function () {
         return new Filter();
     });
     $request = new Request();
     $request->setDI($di);
     return $request;
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:19,代码来源:HttpBase.php

示例7: setUp

 /**
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->checkExtension('phalcon');
     // Reset the DI container
     Di::reset();
     // Instantiate a new DI container
     $di = new Di();
     // Set the URL
     $di->set('url', function () {
         $url = new Url();
         $url->setBaseUri('/');
         return $url;
     });
     $di->set('escaper', function () {
         return new Escaper();
     });
     $this->di = $di;
 }
开发者ID:lisong,项目名称:incubator,代码行数:21,代码来源:UnitTestCase.php

示例8: _after

 /**
  * HOOK: after scenario
  *
  * @param TestCase $test
  */
 public function _after(TestCase $test)
 {
     if ($this->config['cleanup'] && isset($this->di['db'])) {
         while ($this->di['db']->isUnderTransaction()) {
             $level = $this->di['db']->getTransactionLevel();
             try {
                 $this->di['db']->rollback(true);
             } catch (PDOException $e) {
             }
             if ($level == $this->di['db']->getTransactionLevel()) {
                 break;
             }
         }
     }
     $this->di = null;
     Di::reset();
     $_SESSION = $_FILES = $_GET = $_POST = $_COOKIE = $_REQUEST = [];
 }
开发者ID:codeception,项目名称:base,代码行数:23,代码来源:Phalcon1.php

示例9: 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

示例10: setupDI

 /**
  * Set up the environment.
  *
  * @return Di
  */
 private function setupDI()
 {
     Di::reset();
     $di = new Di();
     $di->setShared('session', function () {
         return new PhalconMemorySession();
     });
     $di->setShared('request', function () {
         return new Request();
     });
     return $di;
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:17,代码来源:SecurityTest.php

示例11: setupDI

 /**
  * Sets the environment
  */
 private function setupDI()
 {
     Di::reset();
     $di = new Di();
     $di->set('router', function () {
         $router = new Router(false);
         $router->add('/admin/:controller/p/:action', ['controller' => 1, 'action' => 2])->setName('adminProducts');
         $router->add('/api/classes/{class}')->setName('classApi');
         $router->add('/{year}/{month}/{title}')->setName('blogPost');
         $router->add('/wiki/{article:[a-z]+}')->setName('wikipedia');
         $router->add('/news/{country:[a-z]{2}}/([a-z+])/([a-z\\-+])/{page}', ['section' => 2, 'article' => 3])->setName('news');
         $router->add('/([a-z]{2})/([a-zA-Z0-9_-]+)(/|)', ['lang' => 1, 'module' => 'main', 'controller' => 2, 'action' => 'index'])->setName('lang-controller');
         $router->removeExtraSlashes(true);
         return $router;
     });
     return $di;
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:20,代码来源:UrlTest.php

示例12: 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

示例13: reset

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

示例14: testVoltMacrosIssue11771

    public function testVoltMacrosIssue11771()
    {
        $this->specify("Volt macros can't accept objects", function () {
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
            Di::reset();
            $view = new View();
            $di = new Di();
            $di->set('escaper', function () {
                return new Escaper();
            });
            $di->set('tag', function () {
                return new Tag();
            });
            $di->set('url', function () {
                return (new Url())->setBaseUri('/');
            });
            $view->setDI($di);
            $view->setViewsDir(PATH_DATA . 'views/');
            $view->registerEngines(array('.volt' => function ($view, $di) {
                return new Volt($view, $di);
            }));
            $object = new \stdClass();
            $object->foo = "bar";
            $object->baz = "buz";
            $object->pi = 3.14;
            $object->ary = ["some array"];
            $object->obj = clone $object;
            $view->setVar('object', $object);
            $view->start();
            $view->render('macro', 'list');
            $view->finish();
            ob_start();
            var_dump($object);
            $actual = ob_get_clean();
            // Trim xdebug first line (file path)
            $actual = substr($actual, strpos($actual, 'class'));
            $expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
            expect($actual)->equals($expected);
            $form = new Form();
            $form->add(new Password('password'));
            $view->setVar('formLogin', $form);
            $view->start();
            $view->render('macro', 'form_row');
            $view->finish();
            $actual = <<<FORM
<div class="form-group">
    <label class="col-sm-2 control-label" for="password">password:</label>
    <div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
            expect($actual)->equals($view->getContent());
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
        });
    }
开发者ID:phalcon,项目名称:cphalcon,代码行数:54,代码来源:CompilerTest.php

示例15: _before

 /**
  * executed before each test
  */
 protected function _before()
 {
     parent::_before();
     Di::reset();
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:8,代码来源:DispatcherTest.php


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