当前位置: 首页>>代码示例>>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;未经允许,请勿转载。