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


PHP DiInterface::getConfig方法代码示例

本文整理汇总了PHP中Phalcon\DiInterface::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getConfig方法的具体用法?PHP DiInterface::getConfig怎么用?PHP DiInterface::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\DiInterface的用法示例。


在下文中一共展示了DiInterface::getConfig方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 public function get(\Phalcon\Mvc\Model\Query\Builder $builder, $page)
 {
     $config = $this->di->getConfig()->pager;
     // TODO: obkumać dlaczego przestało działać, może pojawi się nowa wersja inkubatora.
     $adapter = new \Phalcon\Paginator\Adapter\QueryBuilder(array('builder' => $builder, 'limit' => $config->limit, 'page' => $page));
     $adapter = new \Phalcon\Paginator\Adapter\Model(array('data' => $builder->getQuery()->execute(), 'limit' => intval($config->limit), 'page' => $page));
     return new \Phalcon\Paginator\Pager($adapter, array('layoutClass' => 'Phalcon\\Paginator\\Pager\\Layout\\Bootstrap', 'rangeLength' => intval($config->length), 'urlMask' => '?page={%page_number}'));
 }
开发者ID:siciarek,项目名称:suggester,代码行数:8,代码来源:Pager.php

示例2: registerServices

 /**
  * Registers the module-only services
  *
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices($di)
 {
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->set('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getShared('eventsManager'));
         $dispatcher->setDefaultNamespace('App\\Modules\\Frontend\\');
         return $dispatcher;
     });
     $di->setShared('request', function () use($appConfig) {
         return new \Phalcon\Http\Request();
     });
     /**
      * Include config per environment
      */
     include __DIR__ . '/config/config_' . $appConfig->application->environment . '.php';
     $database = $di->getConfig()->application->site . $di->get('request')->getQuery("country_code");
     /**
      * Simple database connection to localhost
      */
     $di->setShared('mongo', function ($config, $database) {
         $mongo = new \Mongo();
         return $mongo->selectDb($config->{$database}->dbname);
     }, true);
     $di->setShared('collectionManager', function () {
         return new \Phalcon\Mvc\Collection\Manager();
     }, true);
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:49,代码来源:Module.php

示例3: registerGlobalServices

 /**
  * 注册全局的服务,需在 app 或者 其他 module 中的 registerServices 手动调用。
  *
  * @param \Phalcon\DiInterface $di
  */
 public static function registerGlobalServices($di)
 {
     $config = $di->getConfig();
     // 当用户系统和
     if (!empty($config->user->dbAdapter)) {
         $di->set('userDbMaster', function () use($di, $config) {
             $slaves = $config->user->dbAdapter->slave;
             $slaveKey = array_rand($slaves->toArray());
             if (!isset($slaves->{$slaveKey}) || count($slaves) < 1) {
                 throw new Exception\RuntimeException(sprintf('No DB slave options found'));
             }
             return Engine::diDbAdapter($slaves->{$slaveKey}->adapter, $slaves->{$slaveKey}->toArray(), $di);
         });
         $di->set('userDbSlave', function () use($di, $config) {
             $slaves = $config->user->dbAdapter->slave;
             $slaveKey = array_rand($slaves->toArray());
             if (!isset($slaves->{$slaveKey}) || count($slaves) < 1) {
                 throw new Exception\RuntimeException(sprintf('No DB slave options found'));
             }
             return Engine::diDbAdapter($slaves->{$slaveKey}->adapter, $slaves->{$slaveKey}->toArray(), $di);
         });
     }
 }
开发者ID:skybird,项目名称:EvaUser,代码行数:28,代码来源:Module.php

示例4: initRoutes

 /**
  * Mount the module specific routes before the module is loaded.
  * Add ModuleRoutes Group and annotated controllers for parsing their routing information.
  *
  * @param \Phalcon\DiInterface  $di
  */
 public static function initRoutes(DiInterface $di)
 {
     $loader = new Loader();
     $loader->registerNamespaces(['App\\Modules\\Backend\\Controllers' => __DIR__ . '/Controllers/', 'App\\Modules\\Backend\\Controllers\\API' => __DIR__ . '/Controllers/api/', 'App\\Modules\\Backend\\Models' => __DIR__ . '/Models/', 'App\\Modules\\Backend\\Library' => __DIR__ . '/Lib/', 'App\\Modules\\Frontend\\Controllers' => __DIR__ . '/../Frontend/Controllers/', 'App\\Modules\\Frontend\\Models' => __DIR__ . '/../Frontend/Models/'], TRUE)->register();
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->setShared('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->setShared('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     $di->setShared('request', function () use($appConfig) {
         return new \Phalcon\Http\Request();
     });
     /**
      * Read configuration
      */
     include __DIR__ . "/../../config/env/" . $appConfig->application->environment . ".php";
     $database = $di->getConfig()->application->site . $di->get('request')->getQuery("countryCode");
     /**
      * Module specific database connection
      */
     $di->set('db', function () use($config, $database) {
         $eventsManager = new \Phalcon\Events\Manager();
         //Create a database listener
         $dbListener = new MyDBListener();
         //Listen all the database events
         $eventsManager->attach('db', $dbListener);
         $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(['host' => $config->{$database}->host, 'username' => $config->{$database}->username, 'password' => $config->{$database}->password, 'dbname' => $config->{$database}->dbname, 'options' => array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")]);
         //Assign the eventsManager to the db adapter instance
         $connection->setEventsManager($eventsManager);
         return $connection;
     });
     /**
      * Simple database connection to localhost
      */
     $di->set('mongo', function () use($config, $database) {
         $mongo = new \MongoClient();
         return $mongo->selectDb($config->{$database}->dbname);
     }, true);
     $di->set('collectionManager', function () {
         return new \Phalcon\Mvc\Collection\Manager();
     }, true);
     /**
      * Include composer autoloader
      */
     require __DIR__ . "/../../../vendor/autoload.php";
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('App\\Modules\\Backend\\Controllers\\');
         return $dispatcher;
     });
     $di->set('utils', function () {
         require __DIR__ . "/../../Common/Lib/Application/Plugins/Utils.php";
         $utils = new Utils();
         return $utils;
     });
     /**
      * If our request contains a body, it has to be valid JSON.  This parses the
      * body into a standard Object and makes that available from the DI.  If this service
      * is called from a function, and the request body is not valid JSON or is empty,
      * the program will throw an Exception.
      */
     $di->setShared('requestBody', function () {
         parse_str(file_get_contents("php://input"), $in);
         // JSON body could not be parsed, throw exception
         if ($in === null) {
             throw new HTTPException('There was a problem understanding the data sent to the server by the application.', 409, array('dev' => 'The JSON body sent to the server was unable to be parsed.', 'internalCode' => 'REQ1000', 'more' => ''));
         }
         return $in;
     });
     /**
      * This means we can create listeners that run when an event is triggered.
      */
     $di->setShared('modelsManager', function () use($di, $config, $database) {
         $eventsManager = new \Phalcon\Events\Manager();
         $customModelsManager = new CustomModelsManager();
         /**
          * Attach an anonymous function as a listener for "model" events
          */
         $eventsManager->attach('model', $customModelsManager);
         /**
          * Setting a default EventsManager
          */
//.........这里部分代码省略.........
开发者ID:sarahsampan,项目名称:compare-api,代码行数:101,代码来源:Module.php

示例5: registerServices

 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     //Read configuration
     $config = (include __DIR__ . "/config/config.php");
     $configGlobal = $di->getConfig();
     $di->set('url', function () use($config, $configGlobal) {
         $url = new Url();
         if (APPLICATION_ENV == 'production') {
             $url->setStaticBaseUri($configGlobal->application->production->staticBaseUri);
         } else {
             $url->setStaticBaseUri($configGlobal->application->development->staticBaseUri);
         }
         $url->setBaseUri($config->application->baseUri);
         return $url;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $eventsManager = $this->getEventsManager();
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 $message = $exception->getMessage();
                 $response = $this->getResponse();
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                         $response->redirect();
                         return false;
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $response->redirect('action-not-found?msg=' . $message);
                         return false;
                     case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                         $response->redirect('cyclic-routing?msg=' . $message);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Frontend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($di) {
         $config = $di->get('config');
         $view = new View();
         $view->setViewsDir(ROOT_DIR . 'content/themes/' . $config->theme);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = $this->getEventsManager();
         $eventsManager->attach('view', function ($event, $view) {
             if ($event->getType() == 'notFoundView') {
                 throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
             }
         });
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
         return $view;
     });
 }
开发者ID:SidRoberts,项目名称:phanbook,代码行数:66,代码来源:Module.php


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