本文整理汇总了PHP中core\Config::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getInstance方法的具体用法?PHP Config::getInstance怎么用?PHP Config::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\Config
的用法示例。
在下文中一共展示了Config::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initDb
/**
* Init database
*/
private static function _initDb()
{
$config = \Core\Config::getInstance();
$dbConnection = new PDO($config->database['driver'] . ':host=' . $config->database['host'] . ';dbname=' . $config->database['dbname'], $config->database['user'], $config->database['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
\Core\Db\Connector::getInstance()->setConnection($dbConnection);
}
示例2: getURL
public function getURL($params, $clean = true)
{
$request = \Core\Http\Request::getInstance();
if ($clean) {
$params = array_merge(array('module' => $request->getModule(), 'controller' => $request->getController(), 'action' => $request->getAction()), $params);
} else {
$p = $request->getParams();
$names = array_keys($_POST);
foreach ($p as $n => $v) {
if (in_array($n, $names)) {
unset($p[$n]);
}
}
$params = array_merge(array('module' => $request->getModule(), 'controller' => $request->getController(), 'action' => $request->getAction()), $p, $params);
}
$module = $params['module'];
$controller = $params['controller'];
$action = $params['action'];
unset($params['module']);
unset($params['controller']);
unset($params['action']);
$uri = \Core\Config::getInstance()->app['baseUrl'] . $module . '/' . $controller . '/' . $action . '/';
if (!empty($params)) {
$ps = array_keys($params);
foreach ($ps as $param) {
if ($param == session_name()) {
continue;
}
if (!is_null($params[$param])) {
$uri .= $param . '/' . $params[$param] . '/';
}
}
}
return $uri;
}
示例3: getConfig
/**
* Retourne l'instance de Config
* @param $key
* @return \Core\Config
*/
public function getConfig($key)
{
if (is_null($this->config_instance)) {
$this->config_instance = Config::getInstance();
}
return $this->config_instance->get($key);
}
示例4: getDb
public function getDb()
{
$config = Config::getInstance(ROOT . '/config/config.php');
if (is_null($this->db_instance)) {
$this->db_instance = new MysqlDatabase($config->get('db_name'), $config->get('db_user'), $config->get('db_pass'), $config->get('db_host'));
}
return $this->db_instance;
}
示例5: getUrl
public function getUrl($params)
{
$path = $this->path;
foreach ($params as $k => $v) {
$path = str_replace(":{$k}:", $v, $path);
}
return Config::getInstance()->get('url') . $path;
}
示例6: getDb
public function getDb()
{
$config = Config::getInstance(ROOT . '/config/config.php');
if (is_null($this->db_instance)) {
$this->db_instance = new MySQLDatabase($config->get("db_name"), $config->get("db_user"), $config->get("db_pass"), $config->get("db_host"));
}
return $this->db_instance;
}
示例7: Router
/**
* Controller constructor.
* @param Request|NULL $request
*/
function __construct(Request $request = NULL)
{
$this->request = is_null($request) ? Request::getInstance() : $request;
$this->config = Config::getInstance();
$this->router = new Router();
$this->route = $this->router;
$this->load = new Load();
$this->startConnection();
$this->checkPermission();
Model::$controller = $this;
}
示例8: __construct
private function __construct()
{
$config = \Core\Config::getInstance();
if (!empty($config->memcache)) {
$this->_host = !empty($config->memcache['host']) ? $config->memcache['host'] : $this->_host;
$this->_post = !empty($config->memcache['port']) ? $config->memcache['port'] : $this->_port;
$this->_compressed = !empty($config->memcache['compressed']) ? $config->memcache['compressed'] : $this->_compressed;
$this->_expire = !empty($config->memcache['host']) ? $config->memcache['host'] : $this->_host;
}
parent::connect($this->_host, $this->_port);
}
示例9: __toString
public function __toString()
{
usort(self::$_data, array($this, 'sort'));
$content = '<ul class="admin_menu">' . PHP_EOL;
$conf = \Core\Config::getInstance();
foreach (self::$_data as $item) {
$url = $conf->app['baseUrl'] . $item['module'] . '/' . $item['controller'] . '/' . $item['action'];
$content .= '<li><a href="' . $url . '">' . $item['label'] . '</a></li>';
}
$content .= '</ul>' . PHP_EOL;
return $content;
}
示例10: dispatch
/**
* Dispatch
* @return string
*/
public function dispatch()
{
$this->_requestURI = str_replace($this->_baseUrl, '', $this->_requestURI);
$uri = explode('/', trim($this->_requestURI, '/'));
$i = 0;
$mvcData = array();
while ($i < 3) {
$tmp = array_shift($uri);
switch ($i) {
case 0:
$mvcData['module'] = empty($tmp) ? 'main' : $tmp;
break;
case 1:
$mvcData['controller'] = empty($tmp) ? 'index' : $tmp;
break;
case 2:
$mvcData['action'] = empty($tmp) ? 'index' : $tmp;
break;
}
$i++;
}
if (!$this->_isDispatchable($mvcData)) {
$mvcData = array('module' => 'main', 'controller' => 'error', 'action' => 'notfound');
} elseif (!$this->_isAclAllow($mvcData)) {
if (\Core\Auth\Auth::getInstance()->hasIdentity()) {
$mvcData = array('module' => 'main', 'controller' => 'error', 'action' => 'accessdenied');
} else {
$mvcData = array('module' => 'main', 'controller' => 'user', 'action' => 'login');
}
}
$request = \Core\Http\Request::getInstance();
while (!empty($uri)) {
$param = array_shift($uri);
$value = array_shift($uri);
$request->setParam($param, $value);
}
$request->setModule($mvcData['module'])->setController($mvcData['controller'])->setAction($mvcData['action']);
$loader = \Core\Loader::getInstance();
$response = $loader->runController($mvcData);
if ($loader->needRenderLayout) {
$config = \Core\Config::getInstance();
if (!empty($config->layout[$mvcData['module']])) {
$layout_script = APP_PATH . 'layouts/' . $config->layout[$mvcData['module']] . '.phtml';
} else {
$layout_script = APP_PATH . 'layouts/main.phtml';
}
$layout = new \Core\View\Layout();
$layout->setContent($response);
return $layout->render($layout_script);
} else {
return $response;
}
}
示例11: connect
public function connect()
{
$database = Config::getInstance()->get('database');
// Set DSN
$dsn = 'mysql:host=' . $database['host'] . ';dbname=' . $database['database'];
// Set options
$options = array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
// Create a new PDO instance
try {
$this->dbh = new PDO($dsn, $database['user'], $database['password'], $options);
} catch (PDOException $e) {
$this->error = $e->getMessage();
}
}
示例12: __construct
public function __construct()
{
$config = Config::getInstance();
$view_engine = $config->get('views.engine');
$view_folder = $config->get('views.path_views');
$view_cache = $config->get('views.path_cache');
$paths = new \SplPriorityQueue();
$paths->insert($view_folder, 100);
switch ($view_engine) {
case 'blade':
$this->renderer = new BladeRenderer($paths, ['cache_path' => $view_cache]);
break;
case 'twig':
$this->renderer = new TwigRenderer($paths);
break;
default:
$this->renderer = new BladeRenderer($paths, $view_cache);
break;
}
}
示例13: foreach
/**
*
* Construtor do Router
*
* @param Request $request Objeto da Requisição
*
* @param array|null $routes
*
* @return void
*
*/
function __construct($routes = NULL)
{
if (empty(self::$request)) {
self::$request = Request::getInstance();
}
if (empty(self::$config)) {
self::$config = Config::getInstance();
}
if (!empty($routes)) {
if (is_array($routes)) {
foreach ($routes as $i => $route) {
self::register($route);
}
} else {
self::register($routes);
}
}
$this->matcher = new Matcher();
self::$instance = $this;
}
示例14: render
public function render($content)
{
if ($this->getOption('sortable')) {
$fieldName = $this->getOption('currentField');
$request = \Core\Http\Request::getInstance();
$sortby = $request->getParam('sortby', false);
$img = '';
if ($sortby == $fieldName) {
$sort = $request->getParam('sortorder', false);
$img = '<img class="fv_sort_order" src="' . \Core\Config::getInstance()->app['baseUrl'] . 'i/s_' . $sort . '.png" alt="sort" />';
} else {
$sort = false;
}
$sort = $sort == false || $sort == 'desc' ? 'asc' : 'desc';
$url = $this->getDecorator()->view->_helperUrl->getUrl(array('sortby' => $fieldName, 'sortorder' => $sort), false);
$decorator = new \Core\Grid\Decorator\HtmlTag(array('tag' => 'a', 'attrs' => array('href' => $url)));
$content .= $img;
$content = $decorator->render($content);
}
return parent::render($content);
}
示例15: getallheaders
/**
* Construtor
* @return void
*/
function __construct()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$this->method = $_SERVER['REQUEST_METHOD'];
$this->setVar('post');
$this->setVar('get');
$this->setVar('request');
$this->setVar('session', FALSE);
$this->ajax = $this->isAjax();
$this->headers = getallheaders();
if (!empty($_SERVER['SCRIPT_URI'])) {
$this->url = $_SERVER['SCRIPT_URI'];
} else {
$this->url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
}
$this->uri = '/' . trim(!empty($_GET['URI']) ? $_GET['URI'] : str_replace(Config::getInstance()->url, '', $this->url), '/');
self::$instance = $this;
}