本文整理汇总了PHP中Phalcon\Di::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::get方法的具体用法?PHP Di::get怎么用?PHP Di::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Di
的用法示例。
在下文中一共展示了Di::get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->di = $this->getDI();
$config = $this->di->get('config');
// // Load any additional services that mock some methods to prevent database unwanted changes
// $this->di->set('modelsManager', new Manager());
// $this->di->set('modelsMetadata', new Files(array('metaDataDir' => $config->application->testsMetadataDir)));
// $con = $this->getMock('\\Phalcon\\Db\\Adapter\\Pdo\\Mysql', array('getDialect', 'query', 'execute'), array(),'',false);
// $this->dialect = $this->getMock('\\Phalcon\\Db\\Dialect\\Mysql', array('select'), array(), '', false);
// $results = $this->getMock('\\Phalcon\\Db\\Result\\Pdo', array('numRows', 'setFetchMode', 'fetchall', 'create'), array(), '', false);
// $results->expects($this->any())
// ->method('numRows')
// ->will($this->returnValue(10));
//
// $results->expects($this->any())
// ->method('create')
// ->willReturn(true);
//
// $results->expects($this->any())
// ->method('fetchall')
// ->will($this->returnValue(0));
//
// $this->dialect->expects($this->any())
// ->method('select');
//
// $con->expects($this->any())
// ->method('getDialect')
// ->will($this->returnValue($this->dialect));
//
// $con->expects($this->any())
// ->method('query')
// ->will($this->returnValue($results));
//
// $con->expects($this->any())
// ->method('execute');
//
// $this->di->set('db', $con);
// parent::setUp($this->di);
$this->_loaded = true;
}
示例2: injectTo
public static function injectTo(Di $di)
{
$di->setShared('logger', function () use($di) {
$logger = new Multiple();
$config = $di->get('config')['loggers'];
foreach ($config as $logConfig) {
$adapter = $logConfig['adapter'];
$options = isset($logConfig['options']) ? $logConfig['options'] : null;
$logger->push(new $adapter($logConfig['name'], $options));
}
return $logger;
});
}
示例3: testResolvingService
/**
* Tests resolving service
*
* @author Serghei Iakovlev <serghei@phalconphp.com>
* @since 2016-01-29
*/
public function testResolvingService()
{
$this->specify("Di does not resolves service correctly", function () {
$di = new Di();
$di->set('resolved', function () {
return new \SomeService();
});
$di->set('notResolved', function () {
return new \SomeService();
});
expect($di->getService('resolved')->isResolved())->false();
expect($di->getService('notResolved')->isResolved())->false();
$di->get('resolved');
expect($di->getService('resolved')->isResolved())->true();
expect($di->getService('notResolved')->isResolved())->false();
});
}
示例4: getTimezoneOffset
/**
* @param Di $di
* @return int
*/
public static function getTimezoneOffset(Di $di)
{
/**
* @var \Phalcon\Http\Request $request
*/
$request = $di->get('request');
$timezoneOffset = $request->getHeader('TimezoneOffset');
return (int) $timezoneOffset;
}
示例5: getDI
/**
* Get the Phalcon dependency injection instance.
*
* @param string $name service name
* @return \Phalcon\Di|mixed
*/
public function getDI($name = null)
{
$name = $name;
return null === $name ? $this->di : $this->di->get($name);
}
示例6: testConfigFileLoaded
public function testConfigFileLoaded()
{
$b = $this->getBootstrap()->run();
$this->assertEquals('bar', static::$di->get('config')->foo);
}
示例7: injectTo
public static function injectTo(Di $di)
{
$di->setShared('logger', $di->get('config')['logger']);
}
示例8: initEventsManager
protected function initEventsManager(Di $di)
{
if (!$di->has('eventsManager') || $di->getService('eventsManager')->getDefinition() == 'Phalcon\\Events\\Manager') {
$di->setShared('eventsManager', $this->getEventsManager());
}
$this->setEventsManager($di->get('eventsManager'));
}
示例9: getSession
/**
* getSession
* @return SessionAdapter
*/
public function getSession()
{
return $this->_di->get('session');
}
示例10: get
public function get($name, $parameters = null)
{
return parent::get($name, $parameters);
}
示例11: getAssetManager
/**
* getAssetManager
* @return \interfaces\AssetManagerInterface
*/
public function getAssetManager()
{
return $this->_di->get('assetManager');
}
示例12: services
private function services()
{
$di = new Di();
// Store the api messages
$di->set('messages', function ($input = null) {
return $input;
});
$di->set('view', function () {
$view = new View();
// $view->setViewsDir('../apps/views/');
return $view;
});
$di->set('dispatcher', function () use($di) {
$eventsManager = new Manager();
$eventsManager->attach('dispatch:afterExecuteRoute', function ($event, $dispatcher) use($di) {
// dd($event->getSource()->getActiveController()->getMessages());
// dd(get_class_methods($event->getSource()->getActiveController()));
// dd(get_class_methods($event->getSource()));
// dd($event->getData());
// dd($event->getSource());
$source = $event->getSource();
$returned = $source->getReturnedValue();
if (is_object($returned)) {
if (!method_exists($returned, 'toArray')) {
throw new ApiException('The returned value can not be parsed, try it manual.');
}
$returned = $returned->toArray();
}
$configs = $di->get('config');
$response = new Response();
if ($configs->api->cors->enabled) {
$response->setHeader('Access-Control-Allow-Origin', $configs->api->cors->hosts);
}
foreach ($configs->api->headers as $name => $value) {
$response->setHeader($name, $value);
}
$json_options = 0;
if ($configs->debug) {
$json_options = JSON_PRETTY_PRINT;
}
foreach ($configs->json->options as $option) {
$json_options |= $option;
}
$activeController = $source->getActiveController();
$status = $activeController->getStatus();
$errors = $activeController->getErrors();
$messages = $activeController->getMessages();
$status_code = $activeController->getCode();
$data = ['status' => $status, 'status_code' => $status_code, 'errors' => $errors, 'messages' => $messages, 'data' => $returned];
$response->setJsonContent($data, $json_options);
$event->getSource()->setReturnedValue($response);
});
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('App\\Controllers\\');
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
///////!!!!!!!!!!!!!!!!
$di->set('modelsMetadata', function () {
return new \Phalcon\Mvc\Model\Metadata\Memory();
});
$di->set('modelsManager', function () {
return new \Phalcon\Mvc\Model\Manager();
});
$this->setDi($di);
}