本文整理汇总了PHP中Config::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::singleton方法的具体用法?PHP Config::singleton怎么用?PHP Config::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($name, $vars = array())
{
//$name es el nombre de nuestra plantilla, por ej, listado.php
//$vars es el contenedor de nuestras variables, es un arreglo del tipo llave => valor, opcional.
//Traemos una instancia de nuestra clase de configuracion.
$config = Config::singleton();
//Armamos la ruta a la plantilla
$path = dirname(__FILE__) . '/../views/' . $name;
//Si no existe el fichero en cuestion, mostramos un 404
if (file_exists($path) == false) {
trigger_error('Template `' . $path . '` does not exist.', E_USER_NOTICE);
return false;
}
//Si hay variables para asignar, las pasamos una a una.
if (is_array($vars)) {
foreach ($vars as $key => $value) {
$key = $value;
}
}
require_once 'helpers.class.php';
$helper = new Helpers();
//incluimos la cabecera
include dirname(__FILE__) . '/../views/templates/header.php';
//Finalmente, incluimos la plantilla.
include $path;
//incluimos el footer
include dirname(__FILE__) . '/../views/templates/footer.php';
}
示例2: getInstance
public static function getInstance()
{
if (is_null(self::$singleton)) {
self::$singleton = new Config();
}
return self::$singleton;
}
示例3: __get
public final function __get($index)
{
switch ($index) {
case 'config':
$this->config = Config::singleton();
return $this->config;
case 'cache':
$this->cache = new Cache($this->config->read('framework/cache/driver', Cache::DISABLED), array('host' => $this->config->read('framework/cache/host', null), 'port' => $this->config->read('framework/cache/port', null)));
return $this->cache;
case 'sql':
$this->config->load('db');
$this->sql = new SQL($this->config->read('db/dsn', ''), $this->config->read('db/user', ''), $this->config->read('db/pass', ''), $this->config->read('db/pool', false));
$this->config->unload('db');
return $this->sql;
case 'secure':
$this->secure = new Secure($this->config->read('framework/secure/seed', 'sampa-framework'));
return $this->secure;
case 'log':
$logfile = __SP_LOG__ . date('Ymd') . '-' . str_replace('_', '-', strtolower(get_class($this))) . '.log';
$this->log = new Log($logfile, $this->config->read('framework/log/level', Log::DISABLED), $this->config->read('framework/log/buffered', true));
return $this->log;
case 'session':
$this->session = Session::singleton($this->config);
return $this->session;
default:
return null;
}
}
示例4: __construct
function __construct($path = null)
{
$this->path = $path === null ? Config::current()->plugins_dir : $path;
$current = Config::current();
self::$config = Config::singleton($this->path);
Config::setCurrent($current->path);
parent::__construct($this->path, array('Sqlite3', 'Xml'));
}
示例5: assets
static function assets($url)
{
$root = Config::singleton()->get('root') . "/assets";
if ($url[0] == "/") {
return $root . $url;
} else {
return $root . "/" . $url;
}
}
示例6: __construct
public function __construct()
{
$config = Config::singleton();
try {
parent::__construct('mysql:host=' . $config->get('dbhost') . ';dbname=' . $config->get('dbname'), $config->get('dbuser'), $config->get('dbpass'));
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
示例7: __construct
public function __construct()
{
$config = Config::singleton();
// parent::__construct('mysql:host=' . $config->get('dbhost') . ';dbname=' . $config->get('dbname'),$config->get('dbuser'), $config->get('dbpass'));
try {
// $pdo = new PDO("mysql:host=".$config->get('dbhost').";dbname=".$config->get('dbname').";charset=utf8", $config->get('dbuser'), $config->get('dbpass'));
parent::__construct('mysql:host=' . $config->get('dbhost') . ';dbname=' . $config->get('dbname'), $config->get('dbuser'), $config->get('dbpass'));
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Se ha producido un error al intentar conectar al servidor MySQL: " . $e->getMessage();
}
}
示例8: singleton
public static function singleton()
{
if (self::$instance == null) {
$config = Config::singleton();
if ($config->get('dbname') != '' or $config->get('dbuser') != '') {
self::$instance = new self();
} else {
return false;
}
}
return self::$instance;
}
示例9: build
private function build($name, $header, $footer, $css_PATH = 'css/', $js_PATH = 'js/')
{
$config = Config::singleton();
$folder = $config->get('viewsFolder_Default');
$this->data["header_path"] = $folder . $header;
$this->data["body_path"] = $folder . $name;
$this->data["footer_path"] = $folder . $footer;
//extra paths
$this->data["base"] = $config->get('baseURL');
$this->data["css_path"] = $folder . $css_PATH;
$this->data["js_path"] = $folder . $js_PATH;
$this->data["img_path"] = $config->get('imgFolder');
}
示例10: getEM
static function getEM()
{
if (is_null(self::$em)) {
// the connection configuration
$dbParams = array('driver' => 'pdo_mysql', 'user' => Config::singleton()->get("dbuser"), 'password' => Config::singleton()->get("dbpass"), 'dbname' => Config::singleton()->get("dbname"), 'database_host' => Config::singleton()->get("dbhost"));
$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array("app/models"), Config::singleton()->get("debug"));
self::$em = Doctrine\ORM\EntityManager::create($dbParams, $config);
$emConfig = self::$em->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\\Query\\Mysql\\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\\Query\\Mysql\\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\\Query\\Mysql\\Day');
$emConfig->addCustomDatetimeFunction('Date', 'Date');
}
return self::$em;
}
示例11: singleton
public static function singleton()
{
if (!isset(self::$instance)) {
$backend = Config::singleton()->Backend;
if(!$backend)
{
throw new BackendNotSpecifiedException("Backend type not specified, please specify one in the config.");
}
// The backend type is supplied by the code, so we don't bother to check if the file exists
// (it will simply throw an error if it doesn't).
require_once($_SERVER["DOCUMENT_ROOT"] . 'includes/framework/backends/class.'.$backend.'Backend.php');
$c = $backend.'Backend';
self::$instance = new $c;
}
return self::$instance;
}
示例12: get
public function get($str, $lang)
{
if (!array_key_exists($lang, $this->lang)) {
$config = Config::singleton();
if (file_exists($config->get("translateDir") . $lang . '.txt')) {
$strings = array_map(array($this, 'splitStrings'), file($config->get("translateDir") . $lang . '.txt'));
foreach ($strings as $k => $v) {
$this->lang[$lang][$v[0]] = $v[1];
}
if (isset($this->lang[$lang])) {
return $this->findString($str, $lang);
} else {
return $str;
}
} else {
return $str;
}
} else {
return $this->findString($str, $lang);
}
}
示例13: return_html
function return_html($template)
{
header('Content-Type: text/html');
$smarty = new Smarty();
$config = Config::singleton();
$root = $config->get('rootAbsolute') . "/app/views/";
/* Set config */
$smarty->template_dir = $root;
$smarty->compile_dir = $root . 'templates_c/';
$smarty->config_dir = $root . 'configs/';
$smarty->cache_dir = $root . 'cache/';
$smarty->plugins_dir = $root . 'customplugins/';
/* Assign smarty vars */
foreach ($this->data as $name => $value) {
$smarty->assign($name, $value);
}
$smarty->display($template);
/* Clean data */
$this->data = array();
exit;
}
示例14: show
public function show($name, $vars = array(), $include_menu = true)
{
//$name es el nombre de nuestra plantilla, por ej, listado.php
//$vars es el contenedor de nuestras variables, es un arreglo del tipo llave => valor, opcional.
//Traemos una instancia de nuestra clase de configuracion.
$config = Config::singleton();
//Armamos la ruta a la plantilla
$path = $config->get('viewsFolder') . $name;
//Si no existe el fichero en cuestion, tiramos un 404
if (file_exists($path) == false) {
trigger_error('Template `' . $path . '` does not exist.', E_USER_NOTICE);
return false;
}
//Si hay variables para asignar, las pasamos una a una.
if (is_array($vars)) {
foreach ($vars as $key => $value) {
${$key} = $value;
}
}
include $path;
}
示例15: newshow
public function newshow($name, $vars = array())
{
$config = Config::singleton();
$path = VIEWS . $name . ".phtml";
if (file_exists($path) == false) {
trigger_error('PLantilla ' . $path . ' NO EXISTE.', E_USER_NOTICE);
return false;
}
if (is_array($vars)) {
foreach ($vars as $key => $value) {
${$key} = $value;
}
}
$default = "views/plantillas/celestium.php";
if (isset($this->template) && !empty($this->template)) {
$rutap = "views/plantillas/" . $this->template . ".phtml";
if (is_file($rutap)) {
include $rutap;
}
} else {
include $default;
}
}