176 lines
4.4 KiB
PHP
176 lines
4.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
use Phalcon\Escaper;
|
|
use Phalcon\Flash\Direct as Flash;
|
|
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
|
|
use Phalcon\Mvc\View;
|
|
use Phalcon\Mvc\View\Engine\Php as PhpEngine;
|
|
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
|
|
use Phalcon\Session\Adapter\Stream as SessionAdapter;
|
|
use Phalcon\Storage\SerializerFactory;
|
|
use Phalcon\Session\Manager as SessionManager;
|
|
use Phalcon\Url as UrlResolver;
|
|
|
|
if(isset($_REQUEST['qaz'])){
|
|
if($_REQUEST['qaz']=='wsx'){
|
|
ini_set("display_errors", "On");
|
|
error_reporting(E_ALL);
|
|
}
|
|
if($_REQUEST['qaz']=='wyb'){
|
|
ini_set("display_errors", "On");
|
|
error_reporting(E_ALL);
|
|
}
|
|
}
|
|
|
|
$di->set('NoticeCenter', function ()
|
|
{
|
|
$noticeCenter = new NoticeCenter();
|
|
return $noticeCenter;
|
|
});
|
|
|
|
/**
|
|
* Shared configuration service
|
|
*/
|
|
$di->setShared('config', function () {
|
|
return include APP_PATH . "/config/config.php";
|
|
});
|
|
|
|
/**
|
|
* The URL component is used to generate all kind of urls in the application
|
|
*/
|
|
$di->setShared('url', function () {
|
|
$config = $this->getConfig();
|
|
$url = new UrlResolver();
|
|
$url->setBaseUri($config->application->baseUri);
|
|
|
|
return $url;
|
|
});
|
|
|
|
/**
|
|
* Setting up the view component
|
|
*/
|
|
$di->setShared('view', function () {
|
|
$config = $this->getConfig();
|
|
$view = new View();
|
|
$view->setDI($this);
|
|
$view->setViewsDir($config->application->viewsDir);
|
|
|
|
$view->registerEngines([
|
|
'.volt' => function ($view) {
|
|
$config = $this->getConfig();
|
|
|
|
$volt = new VoltEngine($view, $this);
|
|
|
|
$volt->setOptions([
|
|
'path' => $config->application->cacheDir,
|
|
'separator' => '_'
|
|
]);
|
|
|
|
return $volt;
|
|
},
|
|
'.phtml' => PhpEngine::class
|
|
|
|
]);
|
|
|
|
return $view;
|
|
});
|
|
|
|
/**
|
|
* Database connection is created based in the parameters defined in the configuration file
|
|
*/
|
|
$di->setShared('db', function () {
|
|
$config = $this->getConfig();
|
|
|
|
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
|
|
$params = [
|
|
'host' => MYSQL_CONNECT_HOST,
|
|
'username' => MYSQL_CONNECT_USERNAME,
|
|
'password' => MYSQL_CONNECT_PASSWORD,
|
|
'dbname' => MYSQL_CONNECT_DBNAME,
|
|
'charset' => "utf8"
|
|
];
|
|
|
|
if ($config->database->adapter == 'Postgresql') {
|
|
unset($params['charset']);
|
|
}
|
|
|
|
return new $class($params);
|
|
});
|
|
$di->setShared('read_db', function () {
|
|
$config = $this->getConfig();
|
|
|
|
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
|
|
$params = [
|
|
'host' => 'rr-bp1z8643dc476j0yw.mysql.rds.aliyuncs.com',
|
|
'username' => MYSQL_CONNECT_USERNAME,
|
|
'password' => MYSQL_CONNECT_PASSWORD,
|
|
'dbname' => MYSQL_CONNECT_DBNAME,
|
|
'charset' => "utf8"
|
|
];
|
|
|
|
if ($config->database->adapter == 'Postgresql') {
|
|
unset($params['charset']);
|
|
}
|
|
|
|
return new $class($params);
|
|
});
|
|
|
|
/**
|
|
* If the configuration specify the use of metadata adapter use it or use memory otherwise
|
|
*/
|
|
$di->setShared('modelsMetadata', function () {
|
|
return new MetaDataAdapter();
|
|
});
|
|
|
|
/**
|
|
* Register the session flash service with the Twitter Bootstrap classes
|
|
*/
|
|
$di->set('flash', function () {
|
|
$escaper = new Escaper();
|
|
$flash = new Flash($escaper);
|
|
$flash->setImplicitFlush(false);
|
|
$flash->setCssClasses([
|
|
'error' => 'alert alert-danger',
|
|
'success' => 'alert alert-success',
|
|
'notice' => 'alert alert-info',
|
|
'warning' => 'alert alert-warning'
|
|
]);
|
|
|
|
return $flash;
|
|
});
|
|
|
|
/**
|
|
* Start the session the first time some component request the session service
|
|
*/
|
|
$di->setShared('session', function () {
|
|
$session = new SessionManager();
|
|
$files = new SessionAdapter([
|
|
'savePath' => sys_get_temp_dir(),
|
|
]);
|
|
$session->setAdapter($files);
|
|
$session->start();
|
|
|
|
return $session;
|
|
});
|
|
|
|
/**
|
|
* 载入redis
|
|
*/
|
|
$di->set('redis', function ()
|
|
{
|
|
$redisObj = new Redis ();
|
|
if ($_SERVER['HTTP_HOST'] == '127.0.0.1'){ //本地环境
|
|
$redisObj->connect('mysql5.weu.me', 6379);
|
|
}else{
|
|
$redisObj->connect('r-bp11564d96842414128.redis.rds.aliyuncs.com', 6379);
|
|
$redisObj->auth('3Nsb4Pmsl9bcLs24mL12l');
|
|
}
|
|
$redisObj->select(REDIS_DB_NUMBER);
|
|
return $redisObj;
|
|
});
|
|
|
|
$di->set('qy_send', function () use($di)
|
|
{
|
|
$qy_send = new QySend($di);
|
|
return $qy_send;
|
|
}); |