本文整理汇总了PHP中Config::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::instance方法的具体用法?PHP Config::instance怎么用?PHP Config::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
public static function getInstance()
{
if (!self::$instance instanceof Config) {
self::$instance = new Config();
}
return self::$instance;
}
示例2: __construct
public function __construct()
{
$config = Config::instance();
// Check if logging is enabled. Default: enabled
$this->_enabled = $config->item('log', 'enabled') !== null ? (bool) $config->item('log', 'enabled') : true;
if ($this->_enabled) {
// Assign a default log path if not specified in config
$this->_log_path = $config->item('log', 'path') !== '' ? $config->item('log', 'path') : APPPATH . 'logs/';
// Assign a default log extension if not specified in config
$this->_file_ext = $config->item('log', 'file_extension') && $config->item('log', 'file_extension') !== '' ? ltrim($config->item('log', 'file_extension'), '.') : 'php';
// Create the log directory if it doesn't exist
file_exists($this->_log_path) or mkdir($this->_log_path, DIR_WRITE_MODE, true);
// Wait what? We failed to create the directory. Abort!
if (!is_dir($this->_log_path)) {
Exception::trace('Could not create the logging directory');
}
if (is_numeric($config->item('log', 'threshold'))) {
$this->_threshold = (int) $config->item('log', 'threshold');
} elseif (is_array($config->item('log', 'threshold'))) {
$this->_threshold = $this->_threshold_max;
$this->_threshold_array = array_flip($config->item('log', 'threshold'));
}
if ($config->item('log', 'date_format') !== '') {
$this->_date_fmt = $config->item('log', 'date_format');
}
}
}
示例3: getInstance
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new Config($_SESSION['user_id']);
}
return self::$instance;
}
示例4: logException
function logException(Exception $e, $mail = true)
{
Logger::messages()->exception($e);
if (Config::instance()->production) {
if (Phalcon\DI::getDefault()->has('request')) {
/** @var \Phalcon\Http\Request $request */
$request = Phalcon\DI::getDefault()->getShared('request');
$message = sprintf("%s %s: %s\n" . "UserAgent: %s\n" . "HTTP Referer: %s\n" . "%s URL: %s://%s\n" . "LoggedUser: %s\n" . "%s", date('Y-m-d H:i:s'), get_class($e), $e->getMessage(), $request->getUserAgent(), urldecode($request->getHTTPReferer()), $request->getClientAddress(), $request->getScheme(), $request->getHttpHost() . urldecode(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>'), $e->getTraceAsString());
} else {
$message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
}
switch (true) {
// case $e instanceof PageNotFound:
// case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
// break;
default:
if (Config::instance()->mail_exceptions && $mail) {
MailQueue::push2admin('Exception', $message);
}
break;
}
} else {
throw $e;
}
}
示例5: openDefaultConnection
public static function openDefaultConnection()
{
if (!self::$initialized) {
self::__init();
}
return self::$instance->dataAccessFactory->openConnection(Config::instance()->DB_NAME, Config::instance()->DB_HOSTNAME, Config::instance()->DB_USERNAME, Config::instance()->DB_PASSWORD, Config::instance()->DB_PERSISTENT_CONNECTION);
}
示例6: getConfig
public static function getConfig($configPath = null)
{
if (!self::$instance) {
self::$instance = new Config($configPath);
}
return self::$instance;
}
示例7: setUp
function setUp()
{
DB::openConnection(Config::instance()->TEST_DB_NAME, "localhost", Config::instance()->TEST_DB_USERNAME, Config::instance()->TEST_DB_PASSWORD, false);
$sql = DB::newDirectSql("CREATE TABLE simple3_table(\n id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id),\n nome VARCHAR(255),\n livello INT,\n properties TEXT);");
$sql->exec();
ActiveRecord::init("Simple3");
}
示例8: before
/**
* Override the before method
* check if ajax and select correct template
*/
public function before()
{
$this->auth_filter();
if (Auth::instance()->logged_in()) {
$this->acl_filter();
}
// create a new Config reader and attach to the Config instance
$config = Config::instance();
$config->attach(new Config_Database());
$this->breadcrumbs();
//check if controller is of innerpage of course and courseid is there in session
// TODO - fix for modular extensibility
if ($this->request->is_initial()) {
// check if this is initial request
$course_pages = array('document', 'flashcard', 'link', 'video', 'lesson', 'quiz', 'assignment', 'question', 'quiz', 'exercise');
$controller = $this->request->controller();
$course_id = Session::instance()->get('course_id');
if (in_array($controller, $course_pages) && !$course_id) {
$this->request->redirect('course');
} elseif (!in_array($controller, $course_pages)) {
Session::instance()->delete('course_id');
}
}
return parent::before();
}
示例9: __construct
protected function __construct()
{
$config = Config::instance();
$this->dbh = new \PDO('mysql:host=' . $config->data['db']['host'] . ';
dbname=' . $config->data['db']['dbname'], $config->data['db']['user'], $config->data['db']['password']);
}
示例10: run
/**
* Running triggers for some actions
*
* @param string $trigger For example <i>admin/System/components/plugins/disable</i>
* @param mixed $data For example ['name' => <i>plugin_name</i>]
*
* @return bool
*/
function run($trigger, $data = null)
{
if (!is_string($trigger)) {
return true;
}
if (!$this->initialized) {
$modules = array_keys(Config::instance()->components['modules']);
foreach ($modules as $module) {
_include_once(MODULES . '/' . $module . '/trigger.php', false);
}
unset($modules, $module);
$plugins = get_files_list(PLUGINS, false, 'd');
if (!empty($plugins)) {
foreach ($plugins as $plugin) {
_include_once(PLUGINS . '/' . $plugin . '/trigger.php', false);
}
}
unset($plugins, $plugin);
$this->initialized = true;
}
if (!isset($this->triggers[$trigger]) || empty($this->triggers[$trigger])) {
return true;
}
$return = true;
foreach ($this->triggers[$trigger] as $closure) {
if ($data === null) {
$return = $return && ($closure() === false ? false : true);
} else {
$return = $return && ($closure($data) === false ? false : true);
}
}
return $return;
}
示例11: Config
public static function &instance()
{
if (empty(Config::$instance)) {
Config::$instance = new Config();
}
return Config::$instance;
}
示例12: getInstance
private static function getInstance()
{
if (!is_object(self::$instance)) {
self::$instance = new Config();
}
return self::$instance;
}
示例13: getInstance
/**
* Fetch instance of this class
*/
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new Config();
}
return self::$instance;
}
示例14: add_to_gallery
function add_to_gallery()
{
$gallery_peer = new GalleryPeer();
$gallery = $gallery_peer->find_by_id(Params::get("id_gallery"));
$collection_peer = new GalleryCollectionPeer();
$gallery_collection = $collection_peer->find_by_id($gallery->id_gallery_collection);
$full_folder_path = GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $gallery_collection->folder . "/" . $gallery->folder;
if (Upload::isUploadSuccessful("file")) {
$filename = Random::newHexString() . "_" . Upload::getRealFilename("file");
$gallery_dir = new Dir($full_folder_path);
$uploaded_img = Upload::saveTo("file", $gallery_dir, $filename);
if (isset(Config::instance()->GALLERY_RESIZE_BY_WIDTH)) {
image_w($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_WIDTH);
} else {
if (isset(Config::instance()->GALLERY_RESIZE_BY_HEIGHT)) {
image_h($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_HEIGHT);
}
}
$peer = new GalleryImagePeer();
$do = $peer->new_do();
$peer->setupByParams($do);
$do->image_name = $filename;
$peer->save($do);
return Redirect::success();
} else {
Flash::error(Upload::getUploadError("file"));
return Redirect::failure();
}
}
示例15: getInstance
/**
*
* Return Config instance or create intitial instance
*
* @access public
*
* @return object
*
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new config();
}
return self::$instance;
}