Skip to content

Commit

Permalink
HHVM fixes due to issues with traits and static variables #138
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 5, 2015
1 parent d4e1744 commit fb97058
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 58 deletions.
10 changes: 5 additions & 5 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
}

Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/GPM/Local/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/GPM/Local/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/GPM/Remote/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions system/src/Grav/Common/GravTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trait GravTrait
*/
public function getGrav()
{
if (!self::$grav) {
self::$grav = Grav::instance();
}
return self::$grav;
}

Expand Down
8 changes: 4 additions & 4 deletions system/src/Grav/Common/Markdown/ParsedownGravTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -159,7 +159,7 @@ protected function inlineImage($excerpt)

} else {
// Create the custom lightbox element

$attributes = $data['a_attributes'];
$attributes['href'] = $data['a_href'];

Expand Down
14 changes: 7 additions & 7 deletions system/src/Grav/Common/Page/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct($path)
$medium = $this->get("{$basename}.{$ext}");

if (!$alternative) {

$medium = $medium ? $medium : $this->createMedium($info->getPathname());

if (!$medium) {
Expand All @@ -70,7 +70,7 @@ public function __construct($path)
} else {

$altMedium = $this->createMedium($info->getPathname());

if (!$altMedium) {
continue;
}
Expand All @@ -86,7 +86,7 @@ public function __construct($path)
}

$medium = $medium ? $medium : $this->scaleMedium($altMedium, $alternative, 1);

$medium->addAlternative($this->parseRatio($alternative), $altMedium);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public function files()
* Create a Medium object from a file
*
* @param string $file
*
*
* @return Medium|null
*/
protected function createMedium($file)
Expand All @@ -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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions system/src/Grav/Common/Page/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
Loading

0 comments on commit fb97058

Please sign in to comment.