diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index b63de9c727..4e940d09ed 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -163,8 +163,8 @@ public function config(array $config) public function init() { /** @var Config $config */ - $config = self::$grav['config']; - $base_url = self::$grav['base_url']; + $config = self::getGrav()['config']; + $base_url = self::getGrav()['base_url']; $asset_config = (array)$config->get('system.assets'); $this->config($asset_config); @@ -358,7 +358,7 @@ public function css($attributes = []) } // Sort array by priorities (larger priority first) - if (self::$grav) { + if (self::getGrav()) { usort($this->css, function ($a, $b) { if ($a['priority'] == $b['priority']) { return $b['order'] - $a['order']; @@ -471,7 +471,7 @@ public function js($attributes = []) protected function pipeline($css = true) { /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $key = '?' . $cache->getKey(); if ($css) { @@ -687,7 +687,7 @@ protected function isRemoteLink($link) protected function buildLocalLink($asset) { try { - $asset = self::$grav['locator']->findResource($asset, false); + $asset = self::getGrav()['locator']->findResource($asset, false); } catch (\Exception $e) { } diff --git a/system/src/Grav/Common/GPM/Local/Plugins.php b/system/src/Grav/Common/GPM/Local/Plugins.php index b5193ad86c..b52efea93b 100644 --- a/system/src/Grav/Common/GPM/Local/Plugins.php +++ b/system/src/Grav/Common/GPM/Local/Plugins.php @@ -17,7 +17,7 @@ class Plugins extends Collection */ public function __construct() { - $grav = self::$grav; + $grav = self::getGrav(); foreach ($grav['plugins']->all() as $name => $data) { $this->items[$name] = new Package($data, $this->type); diff --git a/system/src/Grav/Common/GPM/Local/Themes.php b/system/src/Grav/Common/GPM/Local/Themes.php index 19d68c6a67..673490144c 100644 --- a/system/src/Grav/Common/GPM/Local/Themes.php +++ b/system/src/Grav/Common/GPM/Local/Themes.php @@ -6,7 +6,7 @@ class Themes extends Collection private $type = 'themes'; public function __construct() { - $grav = self::$grav; + $grav = self::getGrav(); foreach ($grav['themes']->all() as $name => $data) { $this->items[$name] = new Package($data, $this->type); diff --git a/system/src/Grav/Common/GPM/Remote/Collection.php b/system/src/Grav/Common/GPM/Remote/Collection.php index 58e2e69425..87c97ffaeb 100644 --- a/system/src/Grav/Common/GPM/Remote/Collection.php +++ b/system/src/Grav/Common/GPM/Remote/Collection.php @@ -31,7 +31,7 @@ public function __construct($repository = null) { throw new \RuntimeException("A repository is required for storing the cache"); } - $cache_dir = self::$grav['locator']->findResource('cache://gpm', true, true); + $cache_dir = self::getGrav()['locator']->findResource('cache://gpm', true, true); $this->cache = new FilesystemCache($cache_dir); $this->repository = $repository; diff --git a/system/src/Grav/Common/GravTrait.php b/system/src/Grav/Common/GravTrait.php index b182583234..215b868486 100644 --- a/system/src/Grav/Common/GravTrait.php +++ b/system/src/Grav/Common/GravTrait.php @@ -13,6 +13,9 @@ trait GravTrait */ public function getGrav() { + if (!self::$grav) { + self::$grav = Grav::instance(); + } return self::$grav; } diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 9ba39e423f..9de9efeef3 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -29,10 +29,10 @@ trait ParsedownGravTrait protected function init($page) { $this->page = $page; - $this->pages = self::$grav['pages']; + $this->pages = self::getGrav()['pages']; $this->BlockTypes['{'] [] = "TwigTag"; - $this->base_url = rtrim(self::$grav['base_url'] . self::$grav['pages']->base(), '/'); - $this->pages_dir = self::$grav['locator']->findResource('page://'); + $this->base_url = rtrim(self::getGrav()['base_url'] . self::getGrav()['pages']->base(), '/'); + $this->pages_dir = self::getGrav()['locator']->findResource('page://'); $this->special_chars = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); } @@ -159,7 +159,7 @@ protected function inlineImage($excerpt) } else { // Create the custom lightbox element - + $attributes = $data['a_attributes']; $attributes['href'] = $data['a_href']; diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index afbdeeca4e..e6438327a7 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -55,7 +55,7 @@ public function __construct($path) $medium = $this->get("{$basename}.{$ext}"); if (!$alternative) { - + $medium = $medium ? $medium : $this->createMedium($info->getPathname()); if (!$medium) { @@ -70,7 +70,7 @@ public function __construct($path) } else { $altMedium = $this->createMedium($info->getPathname()); - + if (!$altMedium) { continue; } @@ -86,7 +86,7 @@ public function __construct($path) } $medium = $medium ? $medium : $this->scaleMedium($altMedium, $alternative, 1); - + $medium->addAlternative($this->parseRatio($alternative), $altMedium); } @@ -186,7 +186,7 @@ public function files() * Create a Medium object from a file * * @param string $file - * + * * @return Medium|null */ protected function createMedium($file) @@ -202,7 +202,7 @@ protected function createMedium($file) $basename = implode('.', $parts); /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; // Check if medium type has been configured. $params = $config->get("media.".strtolower($ext)); @@ -224,7 +224,7 @@ protected function createMedium($file) 'modified' => filemtime($file), ); - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; $lookup = $locator->findResources('image://'); foreach ($lookup as $lookupPath) { @@ -257,7 +257,7 @@ protected function scaleMedium($medium, $from, $to) $medium->set('debug', false); $file = $medium->resize($width, $height)->setPrettyName($basename)->url(); - $file = preg_replace('|'. preg_quote(self::$grav['base_url_relative']) .'$|', '', GRAV_ROOT) . $file; + $file = preg_replace('|'. preg_quote(self::getGrav()['base_url_relative']) .'$|', '', GRAV_ROOT) . $file; $medium->set('debug', $debug); diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index 56bf1cf0a0..224317b795 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -120,7 +120,7 @@ public function __construct($items = array(), Blueprint $blueprint = null) $this->def('mime', 'application/octet-stream'); } - $this->set('debug', self::$grav['config']->get('system.images.debug')); + $this->set('debug', self::getGrav()['config']->get('system.images.debug')); } /** @@ -168,7 +168,7 @@ public function url($reset = true) $output = preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); } - return self::$grav['base_url'] . $output; + return self::getGrav()['base_url'] . $output; } @@ -332,7 +332,7 @@ public function link($width = null, $height = null) } } else { // TODO: we need to find out URI in a bit better way. - $this->linkTarget = self::$grav['base_url'] . preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); + $this->linkTarget = self::getGrav()['base_url'] . preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); } return $this; @@ -422,7 +422,7 @@ public function __call($method, $args) */ public function image($variable = 'thumb') { - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; // TODO: add default file $file = $this->get($variable); @@ -453,7 +453,7 @@ protected function saveImage() $ratio = 1; } - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; $overlay = $locator->findResource("system://assets/responsive-overlays/{$ratio}x.png") ?: $locator->findResource('system://assets/responsive-overlays/unknown.png'); $this->image->merge(ImageFile::open($overlay)); } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 404ce7c426..14281fb2ce 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -96,7 +96,7 @@ class Page public function __construct($array = array()) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $this->routable = true; $this->taxonomy = array(); @@ -123,20 +123,20 @@ public function init($file) $this->modularTwig($this->slug[0] == '_'); // Handle publishing dates if no explict published option set - if (self::$grav['config']->get('system.pages.publish_dates') && !isset($this->header->published)) { + if (self::getGrav()['config']->get('system.pages.publish_dates') && !isset($this->header->published)) { // unpublish if required, if not clear cache right before page should be unpublished if ($this->unpublishDate()) { if ($this->unpublishDate() < time()) { $this->published(false); } else { $this->published(); - self::$grav['cache']->setLifeTime($this->unpublishDate()); + self::getGrav()['cache']->setLifeTime($this->unpublishDate()); } } // publish if required, if not clear cache right before page is published if ($this->publishDate() != $this->modified() && $this->publishDate() > time()) { $this->published(false); - self::$grav['cache']->setLifeTime($this->publishDate()); + self::getGrav()['cache']->setLifeTime($this->publishDate()); } } $this->published(); @@ -300,7 +300,7 @@ public function modifyHeader($key, $value) public function summary($size = null) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $content = $this->content(); // Return summary based on settings in site config file @@ -362,7 +362,7 @@ public function content($var = null) // Load cached content /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $cache_id = md5('page'.$this->id()); $this->content = $cache->fetch($cache_id); @@ -375,7 +375,7 @@ public function content($var = null) // if no cached-content run everything if ($this->content == false) { $this->content = $this->raw_content; - self::$grav->fireEvent('onPageContentRaw', new Event(['page' => $this])); + self::getGrav()->fireEvent('onPageContentRaw', new Event(['page' => $this])); if ($twig_first) { if ($process_twig) { @@ -412,7 +412,7 @@ public function content($var = null) } // Handle summary divider - $delimiter = self::$grav['config']->get('site.summary.delimiter', '==='); + $delimiter = self::getGrav()['config']->get('site.summary.delimiter', '==='); $divider_pos = strpos($this->content, "
{$delimiter}
"); if ($divider_pos !== false) { $this->summary_size = $divider_pos; @@ -430,7 +430,7 @@ public function content($var = null) protected function processMarkdown() { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $defaults = (array) $config->get('system.pages.markdown'); if (isset($this->header()->markdown)) { @@ -463,7 +463,7 @@ protected function processMarkdown() */ private function processTwig() { - $twig = self::$grav['twig']; + $twig = self::getGrav()['twig']; $this->content = $twig->processPage($this, $this->content); } @@ -472,10 +472,10 @@ private function processTwig() */ private function cachePageContent() { - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $cache_id = md5('page'.$this->id()); - self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this])); + self::getGrav()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); $cache->save($cache_id, $this->content); } @@ -650,7 +650,7 @@ public function copy($parent) public function blueprints() { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->blueprints($this->template()); } @@ -729,7 +729,7 @@ public function toJson() public function media($var = null) { /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; if ($var) { $this->media = $var; @@ -958,7 +958,7 @@ public function metadata($var = null) // Safety check to ensure we have a header if ($page_header) { // Merge any site.metadata settings in with page metadata - $defaults = (array) self::$grav['config']->get('site.metadata'); + $defaults = (array) self::getGrav()['config']->get('site.metadata'); if (isset($page_header->metadata)) { $page_header->metadata = array_merge($defaults, $page_header->metadata); @@ -1061,10 +1061,10 @@ public function link($include_host = false) public function url($include_host = false) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; $rootUrl = $uri->rootUrl($include_host) . $pages->base(); $url = $rootUrl.'/'.trim($this->route(), '/'); @@ -1263,7 +1263,7 @@ public function maxCount($var = null) } if (empty($this->max_count)) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $this->max_count = (int) $config->get('system.pages.list.count'); } return $this->max_count; @@ -1338,7 +1338,7 @@ public function parent(Page $var = null) } /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->get($this->parent); } @@ -1351,7 +1351,7 @@ public function parent(Page $var = null) public function children() { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->children($this->path()); } @@ -1418,7 +1418,7 @@ public function adjacentSibling($direction = 1) public function active() { /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; if ($this->url() == $uri->url()) { return true; } @@ -1434,8 +1434,8 @@ public function active() public function activeChild() { /** @var Uri $uri */ - $uri = self::$grav['uri']; - $config = self::$grav['config']; + $uri = self::getGrav()['uri']; + $config = self::getGrav()['config']; // Special check when item is home if ($this->home()) { @@ -1489,7 +1489,7 @@ public function root() public function find($url, $all = false) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->dispatch($url, $all); } @@ -1521,9 +1521,9 @@ public function collection($params = 'content', $pagination = true) // TODO: MOVE THIS INTO SOMEWHERE ELSE? /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; foreach ((array) $config->get('site.taxonomies') as $taxonomy) { if ($uri->param($taxonomy)) { @@ -1559,7 +1559,7 @@ public function collection($params = 'content', $pagination = true) } /** @var Grav $grav */ - $grav = self::$grav['grav']; + $grav = self::getGrav()['grav']; // New Custom event to handle things like pagination. $grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection])); @@ -1639,7 +1639,7 @@ protected function evaluate($value) // @taxonomy: { category: [ blog, featured ], level: 1 } /** @var Taxonomy $taxonomy_map */ - $taxonomy_map = self::$grav['taxonomy']; + $taxonomy_map = self::getGrav()['taxonomy']; if (!empty($parts)) { $params = [implode('.', $parts) => $params]; @@ -1715,7 +1715,7 @@ protected function doRelocation($reorder) // Do reordering. if ($reorder && $this->order() != $this->_original->order()) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; $parent = $this->parent(); diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 8da0896fe4..80c0f9a0f8 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -26,7 +26,7 @@ class User extends Data */ public static function load($username) { - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; // FIXME: validate directory name $blueprints = new Blueprints('blueprints://user'); diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 4ad07bc4b3..42c65d4953 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -35,8 +35,8 @@ trait ConsoleTrait */ public function setupConsole(InputInterface $input, OutputInterface $output) { - if (self::$grav) { - self::$grav['config']->set('system.cache.driver', 'default'); + if (self::getGrav()) { + self::getGrav()['config']->set('system.cache.driver', 'default'); } $this->argv = $_SERVER['argv'][0]; diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php index fdd28a5203..085612c4f7 100644 --- a/system/src/Grav/Console/Gpm/UninstallCommand.php +++ b/system/src/Grav/Console/Gpm/UninstallCommand.php @@ -140,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ private function uninstallPackage($package) { - $path = self::$grav['locator']->findResource($package->package_type . '://' . $package->slug); + $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); Installer::uninstall($path); $errorCode = Installer::lastErrorCode(); @@ -167,7 +167,7 @@ private function uninstallPackage($package) private function checkDestination($package) { - $path = self::$grav['locator']->findResource($package->package_type . '://' . $package->slug); + $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); $questionHelper = $this->getHelper('question'); $skipPrompt = $this->input->getOption('all-yes');