本文整理汇总了PHP中Phalcon\DI::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP DI::getDefault方法的具体用法?PHP DI::getDefault怎么用?PHP DI::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DI
的用法示例。
在下文中一共展示了DI::getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onConstruct
/**
* Includes the default Dependency Injector and loads the Entity.
*/
public function onConstruct()
{
$di = DI::getDefault();
$this->setDI($di);
// initialize entity and set to class property (doing the same to the model property)
$this->getEntity();
}
示例2: getDi
/**
* Get DI
*
* @return DI
*/
public function getDi()
{
if (empty($this->di)) {
$this->di = DI::getDefault();
}
return $this->di;
}
示例3: testSerialization
public function testSerialization()
{
$router = \Phalcon\DI::getDefault()->getShared('router');
$serialized = serialize($router);
$unserialized = unserialize($serialized);
$this->assertEquals($unserialized, $router);
}
示例4: send
public function send()
{
$di = \Phalcon\DI::getDefault();
$res = $di->get('response');
$req = $di->get('request');
//query string, filter, default
if (!$req->get('suppress_response_codes', null, null)) {
$res->setStatusCode($this->getCode(), $this->response)->sendHeaders();
} else {
$res->setStatusCode('200', 'OK')->sendHeaders();
}
$error = array('errorCode' => $this->getCode(), 'userMessage' => $this->getMessage(), 'devMessage' => $this->devMessage, 'more' => $this->additionalInfo, 'applicationCode' => $this->errorCode);
if (!$req->get('type') || $req->get('type') == 'json' | $req->get('type') == 'option') {
$response = new JSONResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'xml') {
$response = new XMLResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'csv') {
$response = new CSVResponse();
$response->send(array($error));
return;
}
}
}
error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
return true;
}
示例5: getTableName
/**
* Get table name.
*
* @return string
*/
public static function getTableName()
{
$reader = DI::getDefault()->get('annotations');
$reflector = $reader->get(get_called_class());
$annotations = $reflector->getClassAnnotations();
return $annotations->get('Source')->getArgument(0);
}
示例6: transaction
/**
* @param $param1 AdapterInterface|Closure
* @param $param2 Closure|null
*
* @throws Exception
* @return mixed
*/
public static function transaction()
{
switch (func_num_args()) {
case 1:
$db = DI::getDefault()['db'];
$callback = func_get_arg(0);
break;
case 2:
$db = func_get_arg(0);
$callback = func_get_arg(1);
break;
default:
throw new Exception("Bad parameter count");
}
/** @var $db AdapterInterface */
/** @var $callback Closure */
//Assert::true($db instanceof AdapterInterface);
Assert::true($callback instanceof Closure);
$db->begin();
try {
$ret = $callback($db);
$db->commit();
return $ret;
} catch (Exception $e) {
$db->rollback();
throw $e;
}
}
示例7: setUp
public function setUp()
{
parent::setUp();
$config = DI::getDefault()->get('config');
require_once $config->application->moduleDir . '/Test/forms/Fake.php';
$this->prepareFakeObject();
}
示例8: testCreateAdapterByItsClass
public function testCreateAdapterByItsClass()
{
$di = DI::getDefault();
$oauth = new OAuth($di);
$linkedin = new \Vegas\Security\OAuth\Service\Linkedin($di, $oauth->getDefaultSessionStorage());
$this->assertInstanceOf('\\Vegas\\Security\\OAuth\\Service\\Linkedin', $linkedin);
}
示例9: __construct
/**
* Constructor, calls the parse method for the query string by default.
*
* @param boolean $parseQueryString
* true Can be set to false if a controller needs to be called
* from a different controller, bypassing the $allowedFields parse
* @return void
*/
public function __construct($parseQueryString = true)
{
$di = \Phalcon\DI::getDefault();
$this->setDI($di);
// initialize entity and set to class property
$this->getEntity();
}
示例10: import
public static function import($data)
{
// id字段创建唯一索引
// db.movie.createIndex({id:1}, {unique:1});
$di = \Phalcon\DI::getDefault();
$di->get('mongo')->subject->batchInsert($data, ['continueOnError' => true]);
}
示例11: validate
/**
* Executes the validation
*
* @param Validation $validator Validator object.
* @param string $attribute Attribute name.
*
* @return Group
*/
public function validate($validator, $attribute)
{
$this->_currentValidator = $validator;
$this->_currentAttribute = $attribute;
/** @var Request $request */
$request = DI::getDefault()->get('request');
$isValid = true;
if ($request->hasFiles(true)) {
$fInfo = finfo_open(FILEINFO_MIME_TYPE);
$types = [];
if ($this->isSetOption('type')) {
$types = $this->getOption('type');
if (!is_array($types)) {
$types = [$types];
}
}
foreach ($request->getUploadedFiles(true) as $file) {
if ($file->getKey() != $attribute) {
continue;
}
if (!empty($types)) {
$mime = finfo_file($fInfo, $file->getTempName());
if (!in_array($mime, $types)) {
$isValid = false;
$this->_addMessage('Incorrect file type, allowed types: %s', implode(',', $types));
}
}
}
}
return $isValid;
}
示例12: filter
public function filter($value)
{
return preg_replace_callback('/(phalcon(\\\\\\w+)*)(\\[\\])?/i', function ($matches) {
$tag = \Phalcon\DI::getDefault()->get('tag');
return $tag->linkToApi(array($matches[1], $matches[0]));
}, $value);
}
示例13: __construct
function __construct($key)
{
$di = \Phalcon\DI::getDefault();
$this->di = $di;
// init stripe access
\Stripe\Stripe::setApiKey($key);
}
示例14: testAuthenticateInvalidUser
public function testAuthenticateInvalidUser()
{
$user = $this->createTempUser();
$auth = DI::getDefault()->get('auth');
$this->setExpectedException('\\Vegas\\Security\\Authentication\\Exception\\InvalidCredentialException');
$auth->authenticate($user, 'pass1234');
}
示例15: _
/**
* @param $string
* @param array $params
* @return string
*/
public static function _($string, array $params = [])
{
if (static::$translate == null) {
global $config;
//Ask browser what is the best language
$locale = DI::getDefault()->get('request')->get('lang', 'string', DI::getDefault()->get('request')->getBestLanguage());
if (empty($config->application->langDir) || !file_exists($config->application->langDir)) {
$config->application->langDir = __DIR__ . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR;
}
//Check if we have a translation file for that lang
if (!file_exists($config->application->langDir . $locale)) {
$locale = 'en_US';
}
// clear cache in dev environment
$default_domain = 'auth';
if (defined('ENVIRONMENT') && ENVIRONMENT == 'development') {
$default_domain = sprintf('%s.%s', $default_domain, time());
if (file_exists($default_domain)) {
}
}
//Init translate object
static::$translate = new \Phalcon\Translate\Adapter\Gettext(['locale' => $locale, 'defaultDomain' => $default_domain, 'directory' => $config->application->langDir]);
}
return static::$translate->_($string, $params);
}