diff --git a/composer.json b/composer.json index 1eaa000..23aa5d7 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,6 @@ "force/shortcode" : "*", "force/arr" : "*", "force/http" : "*", - "force/filesystem" : "*", "force/token" : "*", "force/url" : "*" }, diff --git a/monstra/Cache.php b/monstra/Cache.php index 3a6a5ac..7e75a96 100755 --- a/monstra/Cache.php +++ b/monstra/Cache.php @@ -1,4 +1,5 @@ monstra = $c; + // Set current time static::$now = time(); // Cache key allows us to invalidate all cache on configuration changes. - static::$key = (Config::get('site.cache.prefix') ? Config::get('site.cache.prefix') : 'monstra') . '-' . md5(ROOT_DIR . Monstra::VERSION); + static::$key = ($this->monstra['config']->get('site.cache.prefix') ? $this->monstra['config']->get('site.cache.prefix') : 'monstra') . '-' . md5(ROOT_DIR . 'Monstra::VERSION'); // Get Cache Driver - static::$driver = static::getCacheDriver(); + static::$driver = $this->getCacheDriver(); // Set the cache namespace to our unique key static::$driver->setNamespace(static::$key); + + // Return + return static::$driver; } /** @@ -82,9 +76,9 @@ class Cache * @access public * @return object */ - public static function getCacheDriver() + public function getCacheDriver() { - $driver_name = Config::get('site.cache.driver'); + $driver_name = $this->monstra['config']->get('site.cache.driver'); if (!$driver_name || $driver_name == 'auto') { if (extension_loaded('apc')) { @@ -110,21 +104,21 @@ class Cache break; case 'memcache': $memcache = new \Memcache(); - $memcache->connect(Config::get('site.cache.memcache.server', 'localhost'), - Config::get('site.cache.memcache.port', 11211)); + $memcache->connect($this->monstra['config']->get('site.cache.memcache.server', 'localhost'), + $this->monstra['config']->get('site.cache.memcache.port', 11211)); $driver = new \Doctrine\Common\Cache\MemcacheCache(); $driver->setMemcache($memcache); break; case 'redis': $redis = new \Redis(); - $redis->connect(Config::get('site.cache.redis.server', 'localhost'), - Config::get('site.cache.redis.port', 6379)); + $redis->connect($this->monstra['config']->get('site.cache.redis.server', 'localhost'), + $this->monstra['config']->get('site.cache.redis.port', 6379)); $driver = new \Doctrine\Common\Cache\RedisCache(); $driver->setRedis($redis); break; default: // Create doctrine cache directory if its not exists - !Dir::exists($cache_directory = CACHE_PATH . '/doctrine/') and Dir::create($cache_directory); + !$this->monstra['filesystem']->exists($cache_directory = CACHE_PATH . '/doctrine/') and $this->monstra['filesystem']->mkdir($cache_directory); $driver = new \Doctrine\Common\Cache\FilesystemCache($cache_directory); break; } @@ -138,7 +132,7 @@ class Cache * @access public * @return object */ - public static function driver() + public function driver() { return static::$driver; } @@ -149,7 +143,7 @@ class Cache * @access public * @return string */ - public static function getKey() + public function getKey() { return static::$key; } @@ -163,7 +157,7 @@ class Cache */ public function fetch($id) { - if (Config::get('site.cache.enabled')) { + if ($this->monstra['config']->get('site.cache.enabled')) { return static::$driver->fetch($id); } else { return false; @@ -182,7 +176,7 @@ class Cache */ public function save($id, $data, $lifetime = null) { - if (Config::get('site.cache.enabled')) { + if ($this->monstra['config']->get('site.cache.enabled')) { if ($lifetime === null) { $lifetime = static::getLifetime(); } @@ -193,10 +187,9 @@ class Cache /** * Clear Cache */ - public static function clear() + public function clear() { - Dir::delete(CACHE_PATH . '/doctrine/'); - Dir::delete(CACHE_PATH . '/fenom/'); + $this->monstra['filesystem']->remove(CACHE_PATH . '/doctrine/'); } /** @@ -205,7 +198,7 @@ class Cache * @access public * @param int $future timestamp */ - public static function setLifetime($future) + public function setLifetime($future) { if (!$future) { return; @@ -224,10 +217,10 @@ class Cache * @access public * @return mixed */ - public static function getLifetime() + public function getLifetime() { if (static::$lifetime === null) { - static::$lifetime = Config::get('site.cache.lifetime') ?: 604800; + static::$lifetime = $this->monstra['config']->get('site.cache.lifetime') ?: 604800; } return static::$lifetime; } @@ -242,8 +235,8 @@ class Cache * @access public * @return object */ - public static function init() + public function init() { - return !isset(self::$instance) and self::$instance = new Cache(); + } } diff --git a/monstra/Monstra.php b/monstra/Monstra.php index 5fdd8ad..fdaab6d 100755 --- a/monstra/Monstra.php +++ b/monstra/Monstra.php @@ -51,10 +51,17 @@ class Monstra extends Container return new Finder(); }; + $container['cache'] = function ($c) { + return new Cache($c); + }; + $container['config'] = function ($c) { return new Config($c); }; + // Start the session + //\Session::start(); + $container['markdown'] = function ($c) { return new ParsedownExtra(); }; diff --git a/monstra/Page.php b/monstra/Page.php index bc8ea29..8771c71 100755 --- a/monstra/Page.php +++ b/monstra/Page.php @@ -103,13 +103,8 @@ class Page */ public function renderPage($page) { - if (empty($page['template'])) { - $template_name = 'index'; - } else { - $template_name = $page['template']; - } - $template_ext = '.php'; + $template_name = empty($page['template']) ? 'index' : $page['template']; include THEMES_PATH . '/' . $this->monstra['config']->get('site.theme') . '/' . $template_name . $template_ext; }