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


PHP DI::getDefault方法代码示例

本文整理汇总了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();
 }
开发者ID:gte451f,项目名称:phalcon-json-api-package,代码行数:10,代码来源:BaseController.php

示例2: getDi

 /**
  * Get DI
  *
  * @return DI
  */
 public function getDi()
 {
     if (empty($this->di)) {
         $this->di = DI::getDefault();
     }
     return $this->di;
 }
开发者ID:kachit,项目名称:phalcon-lib,代码行数:12,代码来源:InjectableTrait.php

示例3: testSerialization

 public function testSerialization()
 {
     $router = \Phalcon\DI::getDefault()->getShared('router');
     $serialized = serialize($router);
     $unserialized = unserialize($serialized);
     $this->assertEquals($unserialized, $router);
 }
开发者ID:ovide,项目名称:phest,代码行数:7,代码来源:RouterTest.php

示例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;
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:32,代码来源:HTTPException.php

示例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);
 }
开发者ID:biggtfish,项目名称:cms,代码行数:12,代码来源:AbstractModel.php

示例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;
     }
 }
开发者ID:rj28,项目名称:test,代码行数:35,代码来源:Db.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     $config = DI::getDefault()->get('config');
     require_once $config->application->moduleDir . '/Test/forms/Fake.php';
     $this->prepareFakeObject();
 }
开发者ID:szytko,项目名称:core,代码行数:7,代码来源:CrudTest.php

示例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);
 }
开发者ID:vegas-cmf,项目名称:oauth,代码行数:7,代码来源:OAuthTest.php

示例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();
 }
开发者ID:philippgerard,项目名称:phalcon-json-api-package,代码行数:15,代码来源:BaseController.php

示例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]);
 }
开发者ID:nisnaker,项目名称:tu,代码行数:7,代码来源:Subject.php

示例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;
 }
开发者ID:biggtfish,项目名称:cms,代码行数:39,代码来源:MimeType.php

示例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);
 }
开发者ID:rcardoso81,项目名称:phalcon-api-reference,代码行数:7,代码来源:AddApiLinksFilter.php

示例13: __construct

 function __construct($key)
 {
     $di = \Phalcon\DI::getDefault();
     $this->di = $di;
     // init stripe access
     \Stripe\Stripe::setApiKey($key);
 }
开发者ID:jking6884,项目名称:smores-api,代码行数:7,代码来源:StripeAdapter.php

示例14: testAuthenticateInvalidUser

 public function testAuthenticateInvalidUser()
 {
     $user = $this->createTempUser();
     $auth = DI::getDefault()->get('auth');
     $this->setExpectedException('\\Vegas\\Security\\Authentication\\Exception\\InvalidCredentialException');
     $auth->authenticate($user, 'pass1234');
 }
开发者ID:maniolek,项目名称:auth,代码行数:7,代码来源:StandardTest.php

示例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);
 }
开发者ID:tienrocker,项目名称:pauthentication,代码行数:30,代码来源:Tag.php


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