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


PHP Phalcon\DiInterface类代码示例

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


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

示例1: registerServices

 /**
  * Register specific services for the module
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     $config = $this->_config;
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Imports');
         return $dispatcher;
     });
     //Registering the view component
     $vDI = $di;
     $di->set('volt', function ($view, $vDI) use($config) {
         $volt = new Volt($view, $vDI);
         $volt->setOptions(array('compiledPath' => APP_PATH . $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->volt->stat));
         $compiler = $volt->getCompiler();
         //Add funcao
         $compiler->addFunction('is_a', 'is_a');
         return $volt;
     });
     /**
      * Configura o serviço de view
      */
     $di->set('view', function () use($config, $vDI) {
         $view = new View();
         $view->setViewsDir(APP_PATH . $config->application->viewsDir);
         $view->registerEngines(array('.volt' => 'volt'));
         return $view;
     });
     return $di;
 }
开发者ID:denners777,项目名称:api-phalcon,代码行数:34,代码来源:Module.php

示例2: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     /**
      * Read configuration
      */
     /**
      * Setting up the view component
      */
     $config = $this->config;
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->backendViewsDir);
         $view->registerEngines(array(".volt" => 'volt'));
         return $view;
     }, true);
     /**
      * Setting up volt
      */
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new Volt($view, $di);
         $volt->setOptions(array("compiledPath" => APP_PATH . "/app/cache/volt/", "compiledSeparator" => "_", "compileAlways" => $config->application->debug));
         $volt->getCompiler()->addFunction('tr', function ($key) {
             return "messetool\\Modules\\Modules\\Backend\\Controllers\\ControllerBase::translate({$key})";
         });
         $volt->getCompiler()->addFunction('number_format', function ($resolvedArgs) {
             return 'number_format(' . $resolvedArgs . ')';
         });
         $volt->getCompiler()->addFunction('linkAllowed', function ($args) {
             return "messetool\\Acl\\Acl::linkAllowed({$args})";
         });
         return $volt;
     }, true);
 }
开发者ID:phil-schreiber,项目名称:messewebsite,代码行数:38,代码来源:Module.php

示例3: register

 /**
  * {@inheritdoc}
  * @see http://docs.phalconphp.com/pl/latest/reference/odm.html
  */
 public function register(DiInterface $di)
 {
     $di->set(self::SERVICE_NAME, function () use($di) {
         $mongoConfig = $di->get('config')->mongo->toArray();
         if (isset($mongoConfig['dsn'])) {
             $hostname = $mongoConfig['dsn'];
             unset($mongoConfig['dsn']);
         } else {
             //obtains hostname
             if (isset($mongoConfig['host'])) {
                 $hostname = 'mongodb://' . $mongoConfig['host'];
             } else {
                 $hostname = 'mongodb://localhost';
             }
             if (isset($mongoConfig['port'])) {
                 $hostname .= ':' . $mongoConfig['port'];
             }
             //removes options that are not allowed in MongoClient constructor
             unset($mongoConfig['host']);
             unset($mongoConfig['port']);
         }
         $dbName = $mongoConfig['dbname'];
         unset($mongoConfig['dbname']);
         $mongo = new \MongoClient($hostname, $mongoConfig);
         return $mongo->selectDb($dbName);
     }, true);
 }
开发者ID:maniolek,项目名称:vegaser,代码行数:31,代码来源:MongoServiceProvider.php

示例4: defineRoutes

 public static function defineRoutes(DiInterface $di)
 {
     /* @var $router \Phalcon\Mvc\Router */
     $router = $di->get('router');
     $default = $router->getDefaults()['module'];
     $router->add("/customroute/foo/:params", array('module' => self::$modname, 'controller' => 'index', 'action' => 'foo', 'params' => 1))->setName(self::$modname . '_foo');
 }
开发者ID:logikostech,项目名称:core,代码行数:7,代码来源:Module.php

示例5: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new Mysql(array("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'", \PDO::ATTR_CASE => \PDO::CASE_LOWER, \PDO::ATTR_EMULATE_PREPARES => false)));
     };
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Mall\\Admin\\Controllers");
         return $dispatcher;
     });
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
开发者ID:nicklos17,项目名称:littlemall,代码行数:36,代码来源:Module.php

示例6: registerServices

 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     // Assign our new tag a definition so we can call it
     $di->set('Utilitarios', function () {
         return new \Ecommerce\Admin\Helpers\UtilitariosHelper();
     });
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Ecommerce\\Admin\\Controllers');
         return $dispatcher;
     });
     // Registering the view component
     $di->set('view', function () {
         $config = (include __DIR__ . "/config/config.php");
         $view = new View();
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir('../apps/admin/views/');
         return $view;
     });
     include "../apps/admin/vendor/autoload.php";
 }
开发者ID:denners777,项目名称:phalcon_ecommerce,代码行数:28,代码来源:Module.php

示例7: register

 /**
  * {@inheritdoc}
  */
 public function register(DiInterface $di)
 {
     $di->set(self::SERVICE_NAME, function () use($di) {
         $session = new Vegas\Session($di->get('session'));
         return $session;
     }, true);
 }
开发者ID:vegas-cmf,项目名称:profiler,代码行数:10,代码来源:SessionManagerServiceProvider.php

示例8: getConsole

 /**
  * @param \Phalcon\DiInterface $di
  *
  * @return \Phalcon\Cli\Console
  */
 protected function getConsole(\Phalcon\DiInterface $di)
 {
     if (!$di->has("console")) {
         return $this->getDefaultConsole($di);
     }
     return $di->get("console");
 }
开发者ID:sidroberts,项目名称:phalcon-application,代码行数:12,代码来源:Cli.php

示例9: register

 /**
  * {@inheritdoc}
  */
 public function register(DiInterface $di)
 {
     $di->set(self::SERVICE_NAME, function () use($di) {
         $mongo = new \MongoClient();
         return $mongo->selectDb($di->get('config')->mongo->db);
     }, true);
 }
开发者ID:vegas-cmf,项目名称:profiler,代码行数:10,代码来源:MongoServiceProvider.php

示例10: registerServices

 /**
  * Register specific services for the module
  */
 function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     });
     $config = $di->getShared('config');
     $di->set('view', function () use($config, $di) {
         $view = new View();
         $router = $di->getShared('router');
         /*
          * @todo 给layouts等目录统一变量
          * */
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('/../../../layouts/');
         // 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
         $view->setLayout('index');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     }, true);
 }
开发者ID:justforleo,项目名称:phalcon-cmf,代码行数:30,代码来源:Module.php

示例11: getApplication

 /**
  * @param \Phalcon\DiInterface $di
  *
  * @return \Phalcon\Mvc\Application
  */
 protected function getApplication(\Phalcon\DiInterface $di)
 {
     if (!$di->has("application")) {
         return $this->getDefaultApplication($di);
     }
     return $di->get("application");
 }
开发者ID:sidroberts,项目名称:phalcon-application,代码行数:12,代码来源:Web.php

示例12: setDI

 public function setDI(DiInterface $di)
 {
     $di->setShared('config', static::$config);
     $this->initEventsManager($di);
     parent::setDI($di);
     Di::setDefault($di);
 }
开发者ID:logikostech,项目名称:core,代码行数:7,代码来源:Bootstrap.php

示例13: registerServices

 /**
  * Register specific services for the module
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $di dependency Injector
  *
  * @return void
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'index', 'action' => 'notFound'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Set default namespace to documentation module
         $dispatcher->setDefaultNamespace("Baseapp\\Documentation\\Controllers");
         //Bind the EventsManager to the dispatcher
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () use($di) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         return $view;
     });
 }
开发者ID:cengizcoskun,项目名称:phonebook,代码行数:43,代码来源:Module.php

示例14: registerServices

 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     /**
      * Read configuration
      */
     $config = (include dirname(dirname(dirname(__DIR__))) . "/apps/config/config.php");
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     }, true);
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, 'charset' => 'utf8'));
     };
 }
开发者ID:EdgarSM91,项目名称:phalcon-angular,代码行数:28,代码来源:Module.php

示例15: registerServices

 /**
  * 注册服务
  * @param type $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     $config = \TConfig::instance()->getModule($this->moduleId);
     if (php_sapi_name() == 'cli') {
         //处理CLI模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Cli\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['task'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']);
             }
             return $dispatcher;
         };
     } else {
         //处理WEB模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['controller'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']['controller']);
             }
             return $dispatcher;
         };
         //添加视图
         $di->set('view', function () use($config) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir($config['autoloadDir']['view']);
             $view->registerEngines(array('.html' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
             return $view;
         });
     }
 }
开发者ID:noikiy,项目名称:public,代码行数:34,代码来源:Module.php


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