本文整理汇总了PHP中Phalcon\DI::reset方法的典型用法代码示例。如果您正苦于以下问题:PHP DI::reset方法的具体用法?PHP DI::reset怎么用?PHP DI::reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DI
的用法示例。
在下文中一共展示了DI::reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareDI
/**
* Sets up the DI
*
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
* @since 2014-10-13
*
* @param bool $static
*
* @return \Phalcon\DI\FactoryDefault
*/
protected function prepareDI($static = false)
{
PhDI::reset();
$di = new PhDIFD();
$this->prepareUrl($di, $static);
$this->prepareEscaper($di);
return $di;
}
示例2: getRequestObject
/**
* Initializes the request object and returns it
*
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
* @since 2014-10-05
*
* @return PhRequest
*/
protected function getRequestObject()
{
PhDI::reset();
$di = new PhDI();
$di->set('filter', function () {
return new PhTFilter();
});
$request = new PhTRequest();
$request->setDI($di);
return $request;
}
示例3: 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);
}
示例4: testIssue2688
public function testIssue2688()
{
// Init
\Phalcon\DI::reset();
new \Phalcon\DI\FactoryDefault();
// Configuration
$bag = new Phalcon\Session\Bag('container');
$value = array();
$bag->a = $value;
// Asserts
$this->assertEquals($value, $bag->a);
}
示例5: _getDI
protected function _getDI()
{
DI::reset();
$di = new DI();
$di->set('modelsManager', function () {
return new Manager();
});
$di->set('modelsMetadata', function () {
return new Memory();
});
$di->set('db', function () {
require PATH_CONFIG . 'config.db.php';
return new Mysql($configMysql);
});
return $di;
}
示例6: setUp
public function setUp(Phalcon\DiInterface $di = NULL, Phalcon\Config $config = NULL)
{
$this->checkExtension('phalcon');
if (!is_null($config)) {
$this->config = $config;
}
if (is_null($di)) {
// Reset the DI container
DI::reset();
// Instantiate a new DI container
$di = new FactoryDefault();
// Set the URL
$di->set('collectionManager', function () {
return new CollectionManager();
}, true);
}
$this->di = $di;
}
示例7: setUp
/**
* Sets the test up by loading the DI container and other stuff
*
* @author Nikos Dimopoulos <nikos@phalconphp.com>
* @since 2012-09-30
*
* @return \Phalcon\DI
*/
protected function setUp()
{
$this->checkExtension('phalcon');
// Set the config up
$this->config = Config::init();
// Reset the DI container
\Phalcon\DI::reset();
// Instantiate a new DI container
$di = new \Phalcon\DI();
// Set the URL
$di->set('url', function () {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
$di->set('escaper', function () {
return new \Phalcon\Escaper();
});
$this->di = $di;
}
示例8: testGetSet
/**
* @covers \Phalcon\Session\Bag::get()
* @covers \Phalcon\Session\Bag::set()
* @covers \Phalcon\Session\Bag::__get()
* @covers \Phalcon\Session\Bag::__set()
*/
public function testGetSet()
{
\Phalcon\DI::reset();
new \Phalcon\DI\FactoryDefault();
@session_start();
// Using getters and setters.
$bag = new Phalcon\Session\Bag('test1');
$bag->set('a', array('b' => 'c'));
$this->assertEquals(array('b' => 'c'), $bag->get('a'));
$this->assertEquals(array('b' => 'c'), $_SESSION['test1']['a']);
// Using direct access.
$bag = new Phalcon\Session\Bag('test2');
$bag->a = array('b' => 'c');
$this->assertEquals(array('b' => 'c'), $bag->{'a'});
$this->assertEquals(array('b' => 'c'), $_SESSION['test2']['a']);
// Using direct access with initialising a variable.
$bag = new Phalcon\Session\Bag('test3');
$bag->a['b'] = 'c';
$this->assertEquals(array('b' => 'c'), $bag->a);
$this->assertEquals(array('b' => 'c'), $_SESSION['test3']['a']);
}
示例9: setUp
/**
* Sets the test up by loading the DI container and other stuff
*
* @author Nikos Dimopoulos <nikos@phalconphp.com>
* @since 2012-09-30
* @param \Phalcon\DiInterface $di
* @param \Phalcon\Config $config
* @return void
*/
protected function setUp(DiInterface $di = null, Config $config = null)
{
$this->checkExtension('phalcon');
if (!is_null($config)) {
$this->config = $config;
}
if (is_null($di)) {
// Reset the DI container
DI::reset();
// Instantiate a new DI container
$di = new FactoryDefault();
// Set the URL
$di->set('url', function () {
$url = new Url();
$url->setBaseUri('/');
return $url;
});
$di->set('escaper', function () {
return new \Phalcon\Escaper();
});
}
$this->di = $di;
}
示例10: _after
public function _after(\Codeception\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;
\Phalcon\DI::reset();
$_SESSION = array();
$_FILES = array();
$_GET = array();
$_POST = array();
$_COOKIE = array();
$_REQUEST = array();
}
示例11: 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);
示例12: testConstructor
/**
* @covers ULogin\Auth::__construct()
*/
public function testConstructor()
{
// check thrown exception when session does not exists
$this->di->offsetUnset('session');
try {
new Auth();
} catch (\Phalcon\Session\Exception $e) {
$this->assertInternalType('string', $e->getMessage(), "[-] Auth() must throw an exception if error called when session not instantiated");
}
// at last reset DI to throw Exception
DI::reset();
try {
new Auth();
} catch (\Phalcon\DI\Exception $e) {
$this->assertInternalType('string', $e->getMessage(), "[-] Auth() must throw an exception if error called when DI not configured");
}
}
示例13: testContainerHasYamlService
public function testContainerHasYamlService()
{
// Given: Container
$container = ContainerFactory::build();
// Then: Expect to have defined yaml service
$this->assertTrue($container->has('yaml'));
// Then: Expect to yaml service be set as shared
$this->assertTrue($container->getService('yaml')->isShared());
// Then: Expect to have yaml be instance of Symfony\Component\Yaml\Parser
$this->assertInstanceOf('Symfony\\Component\\Yaml\\Parser', $container->get('yaml'));
// Cleanup: Reset default Phalcon instance
DI::reset();
}
示例14: callService
public function callService($data)
{
echo "service is doing:.\n";
var_dump($data);
echo ".\n";
\Xz\Lib\Core\RunTime::start();
// 判断数据是否正确
if (empty($data['data']['service']) || empty($data['data']['method']) || !isset($data['data']['args'])) {
// 发送数据给客户端,请求包错误
return array('fd' => $data['fd'], 'data' => array('code' => 600, 'msg' => 'bad request', 'data' => 0));
}
$di = new \Phalcon\DI();
require APP_ROOT . 'apps/config/loaderyar.php';
$backend = new \Xz\Lib\Core\BackendServer();
$ret = array();
$ret['data'] = $backend->callService($data['data']);
$ret['fd'] = $data['fd'];
\Phalcon\DI::reset();
echo "service is complete:.\n";
var_dump($ret);
echo ".\n";
return $ret;
}
示例15: testFilterMultiplesSourcesFilterJoin
public function testFilterMultiplesSourcesFilterJoin()
{
$this->markTestIncomplete('To be checked');
@unlink('unit-tests/assets/production/combined-3.js');
Phalcon\DI::reset();
$di = new Phalcon\DI();
$di['url'] = function () {
$url = new Phalcon\Mvc\Url();
$url->setStaticBaseUri('/');
return $url;
};
$di->set('escaper', function () {
return new \Phalcon\Escaper();
});
$assets = new PhTAssetsManager();
$assets->useImplicitOutput(false);
$js = $assets->collection('js');
$js->setTargetUri('production/combined-3.js');
$js->setTargetPath('unit-tests/assets/production/combined-3.js');
$jquery = new PhTAssetsResourceJs('unit-tests/assets/jquery.js', false, false);
$jquery->setTargetUri('jquery.js');
$js->add($jquery);
$gs = new PhTAssetsResourceJs('unit-tests/assets/gs.js');
$gs->setTargetUri('gs.js');
$gs->setTargetPath('gs.js');
$js->add($gs);
$js->join(true);
//Use two filters
$js->addFilter(new Phalcon\Assets\Filters\None());
$js->addFilter(new Phalcon\Assets\Filters\None());
$this->assertEquals($assets->outputJs('js'), '<script type="text/javascript" src="/production/combined-3.js"></script>' . PHP_EOL);
}