本文整理匯總了PHP中Phalcon\Mvc\Application::setDI方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::setDI方法的具體用法?PHP Application::setDI怎麽用?PHP Application::setDI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\Application
的用法示例。
在下文中一共展示了Application::setDI方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
/**
* @param array $config 配置文件
*/
public function run(array $config)
{
$this->di = new FactoryDefault();
$this->app = new Application();
if (defined('APP_ENV') && APP_ENV == 'product') {
$this->debug = false;
error_reporting(0);
} else {
$this->debug = true;
error_reporting(E_ALL);
}
$this->initConfig($config);
try {
$this->onBefore();
$this->initRouters();
$this->initUrl();
$this->initView();
$this->initDatabase();
$this->initModelsMetadata();
$this->initCookie();
$this->initCrypt();
$this->initLogger();
$this->onAfter();
$this->app->setDI($this->di);
$this->registerModules();
echo $this->app->handle()->getContent();
} catch (\Exception $e) {
echo $e->getMessage();
}
}
示例2: registerApplication
/**
* Init application
*
* @return Application
*/
public function registerApplication()
{
$this->registerConfig();
$this->registerServices();
$this->registerModules();
$this->application->setDI($this->di);
return $this->application;
}
示例3: setUp
/**
*
*/
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$dispatcher = new Dispatcher();
$dispatcher->setDI($di);
$this->dispatcher = $dispatcher;
$cache = new BackendCache(new FrontendCache());
$di->set('viewCache', $cache);
$config = new Config(array('cache' => array('enable' => true)));
$di->set('config', $config);
$eventsManager = new Manager();
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('dispatcher', $dispatcher, true);
$di->set('eventsManager', $eventsManager);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例4: setUp
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$this->response = $response;
$eventsManager = new Manager();
$cors = new Cors(array(array('domain' => 'bar.com')));
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('eventsManager', $eventsManager);
$di->set('cors', $cors);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例5: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache', 'markdown');
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
return $application->handle($_SERVER['REQUEST_URI'])->getContent();
}
示例6: __construct
/**
* HMVCApplication Constructor
*
* @param Phalcon\DiInterface
*/
public function __construct(DiInterface $di)
{
$loader = new Loader();
//Application Loader
$loader->registerDirs(array('../app/controllers/'))->register();
//Register the view service
$di['view'] = function () {
$view = new View();
$view->setViewsDir('../app/views/');
return $view;
};
//Register the app itself as a service
$di['app'] = $this;
//Sets the parent Id
parent::setDI($di);
}
示例7: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache');
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
if (PHP_OS == 'Linux') {
$uri = $_SERVER['REQUEST_URI'];
} else {
$uri = null;
}
return $application->handle($uri)->getContent();
}
示例8: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('config', 'session', 'loader', 'url', 'router', 'database', 'view', 'cache', 'log', 'utils', 'debug');
try {
// Handing missing controller errors
$this->di->set('dispatcher', function () {
//Create an EventsManager
$eventsManager = new EventsManager();
// Attach a listener
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
// Handle 404 exceptions
if ($exception instanceof DispatchException) {
$dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
return false;
}
// Alternative way, 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' => 'internalServerError'));
return false;
}
}
});
// Instantiate the Security plugin
$security = new Security($di);
// Listen for events produced in the dispatcher using the Security plugin
$eventsManager->attach('dispatch', $security);
$dispatcher = new \Phalcon\Mvc\Dispatcher();
// Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
return $application->handle()->getContent();
} catch (PhException $e) {
echo $e->getMessage();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
示例9: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('session', 'config', 'loader', 'url', 'router', 'view', 'cache');
try {
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}();
}
$application = new PhApplication();
$application->setDI($this->di);
return $application->handle()->getContent();
} catch (PhException $e) {
echo $e->getMessage();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
示例10: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = array('config', 'loader', 'environment', 'timezone', 'debug', 'flash', 'url', 'dispatcher', 'view', 'logger', 'database', 'session', 'cache', 'behaviors');
try {
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}($options);
}
$application = new PhApplication();
$application->setDI($this->_di);
return $application->handle()->getContent();
} catch (PhException $e) {
echo $e->getMessage();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
示例11: __construct
/**
* Application Constructor
*
* @param \Phalcon\DiInterface $di
*/
public function __construct(DiInterface $di)
{
/**
* Sets the parent DI and register the app itself as a service,
* necessary for redirecting HMVC requests
*/
parent::setDI($di);
$di->set('app', $this);
/**
* Register application wide accessible services
*/
$this->_registerServices();
/**
* Register the installed/configured modules
*/
$this->registerModules(require __DIR__ . '/../../../config/modules.php');
}
示例12: initApplication
protected function initApplication()
{
$di = $this->getDI();
if (!$this->getUserOption('app') instanceof Application) {
$this->setUserOption('app', new Application());
}
$this->app = $this->getUserOption('app');
$this->app->setDI($di);
$this->app->setEventsManager($di->get('eventsManager'));
// disable implicit views if using simple views
if ($di->has('view') && !$di->get('view') instanceof ViewInterface) {
$this->app->useImplicitView(false);
}
$di->setShared('app', $this->app);
if (!defined('APP_ENV')) {
define('APP_ENV', getenv('APP_ENV') ?: static::ENV_PRODUCTION);
}
}
示例13: __construct
/**
* 構建網站服務入口(Constructor)
*
* @param $di
*/
public function __construct(\Phalcon\DiInterface $di)
{
$this->_di = $di;
$loaders = array('loader', 'config', 'timezone', 'db', 'crypt', 'cache', 'language', 'url', 'router');
// 注冊各載入服務(Register services)
try {
foreach ($loaders as $service) {
$this->{$service}();
}
} catch (\Exception $e) {
exit('網站模塊注冊出錯!請通知管理員盡快恢複正常運行,謝謝!');
}
// 注冊服務模塊(Register modules)
$this->registerModules(array('home' => array('className' => 'App\\Home\\Module', 'path' => APP_PATH . '/home/Module.php'), 'admin' => array('className' => 'App\\Admin\\Module', 'path' => APP_PATH . '/admin/Module.php'), 'backend' => array('className' => 'App\\Backend\\Module', 'path' => APP_PATH . '/backend/Module.php')));
// 注冊本類為應用服務(Register the app itself as a service)
$this->_di->set('app', $this);
// 調用父類注冊入口(Sets the parent Di)
parent::setDI($this->_di);
}
示例14: run
/**
* Runs the application performing all initializations
*
* @param $options
*
* @return mixed
*/
public function run($options)
{
$loaders = ['config', 'loader', 'session', 'permission', 'url', 'database', 'logger', 'environment', 'flash', 'flashsession', 'router', 'dispatcher', 'modelsmanager', 'metadata', 'annotations', 'view', 'cache', 'security', 'crypt', 'cookie', 'beanstalkd', 'acl', 'filemanager', 'authentication'];
foreach ($loaders as $service) {
$function = 'init' . ucfirst($service);
$this->{$function}($options);
}
$application = new PhApplication();
$application->setDI($this->di);
$modules = $this->getModules();
$application->registerModules($modules);
$eventsManager = new PhEventsManager();
$application->setEventsManager($eventsManager);
$eventsManager->attach('application:beforeHandleRequest', function ($event, $application) {
$config = $this->di->get('config');
$response = $this->di->get('response');
$dispatcher = $this->di->get('dispatcher');
$cookie = $this->di->get('cookie');
//Detect mobile device
$detect = new \Fly\Mobile_Detect();
if ($config->app_mobile == true && $detect->isMobile() && SUBDOMAIN != 'm' && $dispatcher->getModuleName() == 'common') {
//begin redirect link to mobile version
$curPageURL = \Fly\Helper::getCurrentUrl();
$curPageURL = str_replace(array('http://', 'https://'), array('http://m.', 'https://m.'), $curPageURL);
$response->redirect($curPageURL, true);
}
//Setting language service
$this->di->setShared('lang', function () use($dispatcher, $cookie) {
$language = '';
// Detect language via cookie
if ($cookie->has('language')) {
$language = $cookie->get('language')->getValue();
} else {
//Get default language
$language = $this->config->defaultLanguage;
}
return new FlyTranslate(['module' => strtolower($dispatcher->getModuleName()), 'controller' => $dispatcher->getControllerName(), 'language' => $language]);
});
});
return $application->handle()->getContent();
}
示例15: run
/**
* 開始運行
*/
public function run()
{
try {
$this->onBefore();
$this->initLoader();
$this->initRouters();
$this->initUrl();
$this->initDatabase();
$this->initModelsMetadata();
$this->initCookie();
$this->initLogger();
$this->initShortFunc();
\Phalcon\Mvc\Model::setup(['notNullValidations' => false]);
$this->onAfter();
$this->app->setDI($this->di);
$this->registerModules();
echo $this->app->handle()->getContent();
} catch (\Exception $e) {
echo $e->getMessage();
}
}