1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-02 19:27:52 +02:00

Core Improvements: Next Round

This commit is contained in:
Awilum
2013-01-04 22:52:55 +02:00
parent ef12b7492e
commit c5e5eab4f0
8 changed files with 103 additions and 13 deletions

View File

@@ -114,9 +114,9 @@ class Core
// Init ORM // Init ORM
if (defined('MONSTRA_DB_DSN')) { if (defined('MONSTRA_DB_DSN')) {
ORM::configure(MONSTRA_DB_DSN); Orm::configure(MONSTRA_DB_DSN);
ORM::configure('username', MONSTRA_DB_USER); Orm::configure('username', MONSTRA_DB_USER);
ORM::configure('password', MONSTRA_DB_PASSWORD); Orm::configure('password', MONSTRA_DB_PASSWORD);
} }
// Auto cleanup if MONSTRA_DEBUG is true // Auto cleanup if MONSTRA_DEBUG is true
@@ -129,6 +129,12 @@ class Core
if (count($namespaces = Dir::scan(CACHE)) > 0) foreach ($namespaces as $namespace) Dir::delete(CACHE . DS . $namespace); if (count($namespaces = Dir::scan(CACHE)) > 0) foreach ($namespaces as $namespace) Dir::delete(CACHE . DS . $namespace);
} }
// Set cache dir
Cache::configure('cache_dir', CACHE);
// Load URI module
require_once(ROOT . '/libraries/engine/Security.php');
// Load URI module // Load URI module
require_once(ROOT . '/libraries/engine/Uri.php'); require_once(ROOT . '/libraries/engine/Uri.php');

View File

@@ -20,7 +20,7 @@ class Cache
* *
* @var string * @var string
*/ */
public static $cache_dir = CACHE; public static $cache_dir = '';
/** /**
* Cache file ext * Cache file ext

View File

@@ -0,0 +1,85 @@
<?php
class Config
{
private static $path = '';
/**
* Config array.
*
* @var array
*/
protected static $config;
/**
* Protected constructor since this is a static class.
*
* @access protected
*/
protected function __construct()
{
// Nothing here
}
/**
* Set the location where to save the config file.
*
* @return SpoonLog
* @param string[optional] $path The path where you want to store the logfile. If null it will be saved in 'spoon/log/*'.
*/
public static function setPath($path)
{
Config::$path = $path;
}
/**
* Returns the path to the configuration file.
*
* @access protected
* @param string $file File name
* @return string
*/
protected static function file($file)
{
//$path = MONSTRA_LIBRARIES_PATH.'/'.Config::$path.'/'.$file.'.php';
if (file_exists(Config::$path.'/'.$file.'.php')) {
return Config::$path.'/'.$file.'.php';
}
throw new RuntimeException(vsprintf("%s(): The '%s' config file does not exist.", array(__METHOD__, $file)));
}
/**
* Returns config value or entire config array from a file.
*
* @access public
* @param string $key Config key
* @param mixed $default (optional) Default value to return if config value doesn't exist
* @return mixed
*/
public static function get($key, $default = null)
{
$keys = explode('.', $key, 2);
if (!isset(static::$config[$keys[0]])) {
static::$config[$keys[0]] = include(static::file($keys[0]));
}
if (!isset($keys[1])) {
return static::$config[$keys[0]];
} else {
return Arr::get(static::$config[$keys[0]], $keys[1], $default);
}
}
}

View File

@@ -36,13 +36,13 @@ class Date
* @param string $format Date format * @param string $format Date format
* @return integer * @return integer
*/ */
public static function format($date, $format = '') public static function format($date, $format = 'j.n.Y')
{ {
// Redefine vars // Redefine vars
$format = (string) $format; $format = (string) $format;
$date = (int) $date; $date = (int) $date;
if ($format != '') { return date($format, $date); } else { return date(MONSTRA_DATE_FORMAT, $date); } return date($format, $date);
} }
/** /**

View File

@@ -13,9 +13,6 @@
* @since 1.0.0 * @since 1.0.0
*/ */
/**
* Dir class
*/
class Dir class Dir
{ {
/** /**

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* Monstra Library * Monstra Library
* *

View File

@@ -13,12 +13,12 @@
* @since 1.0.0 * @since 1.0.0
*/ */
/* /**
* Version number for the current version of the Monstra Library. * Version number for the current version of the Monstra Library.
*/ */
define('MONSTRA_LIBRARY_VERSION', '1.0.0'); define('MONSTRA_LIBRARY_VERSION', '1.0.0');
/* /**
* Should we use the Monstra Autoloader to ensure the dependancies are automatically * Should we use the Monstra Autoloader to ensure the dependancies are automatically
* loaded? * loaded?
*/ */
@@ -26,7 +26,9 @@ if ( ! defined('MONSTRA_LIBRARY_AUTOLOADER')) {
define('MONSTRA_LIBRARY_AUTOLOADER', true); define('MONSTRA_LIBRARY_AUTOLOADER', true);
} }
// Register autoload function /**
* Register autoload function
*/
if (MONSTRA_LIBRARY_AUTOLOADER) { if (MONSTRA_LIBRARY_AUTOLOADER) {
spl_autoload_register(array('Monstra', 'autoload')); spl_autoload_register(array('Monstra', 'autoload'));
} }
@@ -44,7 +46,6 @@ class Monstra
*/ */
private static $registry = array(); private static $registry = array();
/** /**
* Autload * Autload
*/ */