當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Di::getDefault方法代碼示例

本文整理匯總了PHP中Phalcon\Di::getDefault方法的典型用法代碼示例。如果您正苦於以下問題:PHP Di::getDefault方法的具體用法?PHP Di::getDefault怎麽用?PHP Di::getDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phalcon\Di的用法示例。


在下文中一共展示了Di::getDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addComment

 public function addComment($data)
 {
     /** @var myModel $this */
     $comment = new Comments();
     $comment->content = $data['content'];
     $comment->commentable_id = $this->id;
     $comment->commentable_type = get_class($this);
     //        $comment->user_id = $this->getDI()->getShared('session')->get('auth')['id'];//獲得當前登錄對象的id
     $user = \Phalcon\Di::getDefault()->get('auth');
     $comment->user_id = $user->id;
     //獲得當前登錄對象的id
     //        dd($comment);
     $comment->save();
     /** @var myModel $this */
     if (method_exists($this, 'increaseCount')) {
         $this->increaseCount('commentCount');
     } else {
         $this->save();
         //更新時間
     }
     if (is_a($this, 'Tags')) {
         $meta = $this->getTagmetaOrNew();
         $meta->save();
     }
     return $this;
 }
開發者ID:huoybb,項目名稱:standard,代碼行數:26,代碼來源:commentableTrait.php

示例2: run

 public static function run()
 {
     $di = \Phalcon\Di::getDefault();
     $em = $di->get('em');
     // Clear out any non-daily statistics.
     $em->createQuery('DELETE FROM Entity\\Analytics a WHERE a.type != :type')->setParameter('type', 'day')->execute();
     // Pull statistics in from influx.
     $influx = $di->get('influx');
     $daily_stats = $influx->setDatabase('pvlive_stations')->query('SELECT * FROM /1d.*/ WHERE time > now() - 14d', 's');
     $new_records = array();
     $earliest_timestamp = time();
     foreach ($daily_stats as $stat_series => $stat_rows) {
         $series_split = explode('.', $stat_series);
         $station_id = $series_split[1] == 'all' ? NULL : $series_split[2];
         foreach ($stat_rows as $stat_row) {
             if ($stat_row['time'] < $earliest_timestamp) {
                 $earliest_timestamp = $stat_row['time'];
             }
             $new_records[] = array('station_id' => $station_id, 'type' => 'day', 'timestamp' => $stat_row['time'], 'number_min' => (int) $stat_row['min'], 'number_max' => (int) $stat_row['max'], 'number_avg' => round($stat_row['value']));
         }
     }
     $em->createQuery('DELETE FROM Entity\\Analytics a WHERE a.timestamp >= :earliest')->setParameter('earliest', $earliest_timestamp)->execute();
     foreach ($new_records as $new_record) {
         $row = new \Entity\Analytics();
         $row->fromArray($new_record);
         $em->persist($row);
     }
     $em->flush();
 }
開發者ID:Lavoaster,項目名稱:PVLive,代碼行數:29,代碼來源:AnalyticsManager.php

示例3: getConnection

 /**
  * @return Client
  */
 public function getConnection()
 {
     if (static::$connection === null) {
         static::$connection = Di::getDefault()->getShared('Neo4jClient');
     }
     return static::$connection;
 }
開發者ID:boorlyk,項目名稱:friendsApi,代碼行數:10,代碼來源:UsersNeo4jRepository.php

示例4: getDbName

 public static function getDbName()
 {
     if (!isset(self::$_db)) {
         self::$_db = Di::getDefault()->get('config')->mongodb->database;
     }
     return self::$_db;
 }
開發者ID:DenchikBY,項目名稱:Phalcon-MongoDB-ODM,代碼行數:7,代碼來源:Model.php

示例5: getStatisticsForSchoolAndGrade

 /**
  * 根據學校id歸類獲取信息
  *
  * @param int $school_id
  *
  * @return mixed
  * @author Hunter.<990835774@qq.com>
  */
 public function getStatisticsForSchoolAndGrade($school_id = 0)
 {
     $page = new Page();
     $page_table = $page->getSource();
     $classes = new Classes();
     $classes_table = $classes->getSource();
     $eva_task_log = new EvaTaskLog();
     $eva_task_log_table = $eva_task_log->getSource();
     $sql_query = "select c.grade_id,count(DISTINCT p.id) as countP, 'reading' as type from {$page_table} as p\nleft join (\nSELECT grade_id,GROUP_CONCAT(id) as id_concat FROM {$classes_table}\nwhere school_id=:school_id\ngroup by grade_id\n) c on FIND_IN_SET(p.classes_id,c.id_concat)\nwhere is_finished=0\ngroup by c.grade_id\n\nunion all\n\nselect c.grade_id,count(DISTINCT p.id) as countP, 'reading_finished' as type from {$page_table} as p\nleft join (\nSELECT grade_id,GROUP_CONCAT(id) as id_concat FROM {$classes_table}\nwhere school_id=:school_id\ngroup by grade_id\n) c on FIND_IN_SET(p.classes_id,c.id_concat)\nwhere is_finished=1\ngroup by c.grade_id\n\nunion all\n\nselect c.grade_id,count(DISTINCT p.id) as countP, 'eva_task' as type from {$eva_task_log_table} as p\nleft join (\nSELECT grade_id,GROUP_CONCAT(id) as id_concat FROM {$classes_table}\nwhere school_id=:school_id\ngroup by grade_id\n) c on FIND_IN_SET(p.classes_id,c.id_concat)\ngroup by c.grade_id";
     try {
         if (DEBUG) {
             $logger = Di::getDefault()->getLogger();
             $logger->log($sql_query, \Phalcon\Logger::DEBUG);
         }
         $stmt = $this->di->getDefault()->get('db')->prepare($sql_query);
         $stmt->bindParam(':school_id', $school_id, \PDO::PARAM_INT);
         $stmt->execute();
         $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         return $result;
     } catch (\PDOException $e) {
         if (DEBUG) {
             die($e->getMessage());
         } else {
             $this->di->get('logger_error')->log('PDOException: ' . $e->getMessage(), \Phalcon\Logger::ERROR);
             $this->di->get('dispatcher')->forward(['module' => 'home', 'controller' => 'error', 'action' => 'show_sql_error']);
         }
     }
 }
開發者ID:ylh990835774,項目名稱:phalcon_ydjc,代碼行數:36,代碼來源:RectorService.php

示例6: isVotedBy

 public function isVotedBy(Users $user = null)
 {
     if (null == $user) {
         $user = \Phalcon\Di::getDefault()->get('auth');
     }
     return Vote::query()->where('voteable_type = :type:', ['type' => get_class($this)])->andWhere('voteable_id = :id:', ['id' => $this->id])->andWhere('user_id = :user:', ['user' => $user->id])->execute()->count() > 0;
 }
開發者ID:huoybb,項目名稱:movie,代碼行數:7,代碼來源:voteableTrait.php

示例7: run

    public function run()
    {
        $log = new Stream('php://stdout');
        /** @var Config $config */
        $config = Di::getDefault()->getShared('config');
        $expireDate = new DateTime('now', new DateTimeZone('UTC'));
        $expireDate->modify('+1 month');
        $baseUrl = rtrim($config->get('site')->url, '/');
        $content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap.xml
EOL;
        $adapter = new Local(dirname(dirname(__FILE__)) . '/public');
        $filesystem = new Filesystem($adapter);
        if ($filesystem->has('robots.txt')) {
            $result = $filesystem->update('robots.txt', $content);
        } else {
            $result = $filesystem->write('robots.txt', $content);
        }
        if ($result) {
            $log->info('The robots.txt was successfully updated');
        } else {
            $log->error('Failed to update the robots.txt file');
        }
    }
開發者ID:phalcon,項目名稱:forum,代碼行數:26,代碼來源:gen-robots.php

示例8: log

 public static function log($type, $message = null, array $context = [])
 {
     static::$logger or static::$logger = Di::getDefault()->getShared('log');
     $context['host'] = static::$hostname;
     $context['request'] = fnGet($_SERVER, 'REQUEST_METHOD') . ' ' . fnGet($_SERVER, 'REQUEST_URI');
     static::$logger->log($type, $message, $context);
 }
開發者ID:phwoolcon,項目名稱:phwoolcon,代碼行數:7,代碼來源:Log.php

示例9: sqlite

 public function sqlite(UnitTester $I)
 {
     $I->wantToTest("Model validation by using SQLite as RDBMS");
     /** @var \Phalcon\Di\FactoryDefault $di */
     $di = Di::getDefault();
     $connection = $di->getShared('db');
     $di->remove('db');
     $di->setShared('db', function () {
         $connection = new Sqlite(['dbname' => TEST_DB_SQLITE_NAME]);
         /** @var \PDO $pdo */
         $pdo = $connection->getInternalHandler();
         $pdo->sqliteCreateFunction('now', function () {
             return date('Y-m-d H:i:s');
         });
         return $connection;
     });
     Di::setDefault($di);
     $this->success($I);
     $this->presenceOf($I);
     $this->email($I);
     $this->emailWithDot($I);
     $this->exclusionIn($I);
     $this->inclusionIn($I);
     $this->uniqueness1($I);
     $this->uniqueness2($I);
     $this->regex($I);
     $this->tooLong($I);
     $this->tooShort($I);
     $di->remove('db');
     $di->setShared('db', $connection);
 }
開發者ID:phalcon,項目名稱:cphalcon,代碼行數:31,代碼來源:ValidationCest.php

示例10: list

 /**
  * 跟find()類似,包含總數、頁數、上一頁、下一頁等信息
  *
  * @param $parameters
  * @param int $limit
  * @param int $page
  * @return mixed
  */
 public static function list($parameters = null, $page = 1, $limit = 20)
 {
     // static function.
     $di = Di::getDefault();
     //
     if (!is_array($parameters)) {
         $params[] = $parameters;
     } else {
         $params = $parameters;
     }
     $manager = $di->getShared('modelsManager');
     $builder = $manager->createBuilder($params);
     $builder->from(get_called_class());
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $params = ["builder" => $builder, "limit" => $limit, "page" => $page];
     $paginator = $di->get("Phalcon\\Paginator\\Adapter\\QueryBuilder", [$params]);
     $data = $paginator->getPaginate();
     $items = [];
     foreach ($data->items as $item) {
         $items[] = $item->toArray();
     }
     $data = (array) $data;
     $data['items'] = $items;
     return $data;
 }
開發者ID:xueron,項目名稱:pails,代碼行數:35,代碼來源:Model.php

示例11: connect

 /**
  * Opens a connection to the database, using dependency injection.
  * @see \Phalcon\Queue\Db::diServiceKey
  * @return bool
  */
 public function connect()
 {
     if (!$this->connection) {
         $this->connection = Di::getDefault()->get($this->diServiceKey);
     }
     return true;
 }
開發者ID:igorsantos07,項目名稱:phalcon-queue-db,代碼行數:12,代碼來源:Db.php

示例12: __get

 public function __get($propertyName)
 {
     $dependencyInjector = null;
     $service = null;
     $persistent = null;
     $dependencyInjector = $this->_dependencyInjector;
     if (!$dependencyInjector) {
         $dependencyInjector = Di::getDefault();
     }
     if (!$dependencyInjector) {
         throw new Exception("A dependency injection object is required to access the application services");
     }
     /**
      * Fallback to the PHP userland if the cache is not available
      */
     if ($dependencyInjector->has($propertyName)) {
         $service = $dependencyInjector->getShared($propertyName);
         $this->{$propertyName} = $service;
         return $service;
     }
     if ($propertyName == "di") {
         $this->{"di"} = $dependencyInjector;
         return $dependencyInjector;
     }
     /**
      * A notice is shown if the property is not defined and isn't a valid service
      */
     trigger_error("Access to undefined property " . $propertyName);
     return null;
 }
開發者ID:olivierandriessen,項目名稱:phalcon-rest,代碼行數:30,代碼來源:Transformer.php

示例13: __construct

 /**
  * Class constructor.
  *
  * @param  array $options
  * @param  DbConnection  $db
  * @throws ValidationException
  */
 public function __construct(array $options = [], DbConnection $db = null)
 {
     parent::__construct($options);
     if (!$db) {
         // try to get db instance from default Dependency Injection
         $di = Di::getDefault();
         if ($di instanceof DiInterface && $di->has('db')) {
             $db = $di->get('db');
         }
     }
     if (!$db instanceof DbConnection) {
         throw new ValidationException('Validator Uniqueness require connection to database');
     }
     if (!$this->hasOption('table')) {
         throw new ValidationException('Validator require table option to be set');
     }
     if (!$this->hasOption('column')) {
         throw new ValidationException('Validator require column option to be set');
     }
     if ($this->hasOption('exclude')) {
         $exclude = $this->getOption('exclude');
         if (!isset($exclude['column']) || empty($exclude['column'])) {
             throw new ValidationException('Validator with "exclude" option require column option to be set');
         }
         if (!isset($exclude['value']) || empty($exclude['value'])) {
             throw new ValidationException('Validator with "exclude" option require value option to be set');
         }
     }
     $this->db = $db;
 }
開發者ID:phalcon,項目名稱:incubator,代碼行數:37,代碼來源:Uniqueness.php

示例14: getWatchList

 public function getWatchList()
 {
     if (null == $this->watchList) {
         $user = \Phalcon\Di::getDefault()->get('auth');
         $this->watchList = Watchlist::findOrCreateNew($this, $user);
     }
     return $this->watchList;
 }
開發者ID:huoybb,項目名稱:movie,代碼行數:8,代碼來源:WatchlistTrait.php

示例15:

 function __construct($id = null)
 {
     $this->redis = Di::getDefault()->getShared('redis');
     //這裏是否會出現一大堆connection呢?怎麽能夠查詢出來呢?
     if (method_exists($this, 'init') and null != $id) {
         $this->init($id);
     }
 }
開發者ID:huoybb,項目名稱:movie,代碼行數:8,代碼來源:redisModel.php


注:本文中的Phalcon\Di::getDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。