From c3c7c78e465a23dbb3776a22ff6be9adc46eb152 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 09:25:07 +0100 Subject: [PATCH 01/14] :white_check_mark: Test Assets::getCss() and Assets::getJs() --- tests/unit/Grav/Common/AssetsTest.php | 77 ++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index ec6508a15..a3272610b 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -38,22 +38,59 @@ class AssetsTest extends \Codeception\TestCase\Test $css = $assets->css(); $this->assertSame($css, '' . PHP_EOL); + $array = $assets->getCss(); + $this->assertSame(reset($array), [ + 'asset' => '/test.css', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'group' => 'head' + ]); + $assets->add('test.js'); $js = $assets->js(); $this->assertSame($js, '' . PHP_EOL); + $array = $assets->getCss(); + $this->assertSame(reset($array), [ + 'asset' => '/test.css', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'group' => 'head' + ]); + //test addCss(). Test adding asset to a separate group $assets->reset(); $assets->addCSS('test.css'); $css = $assets->css(); $this->assertSame($css, '' . PHP_EOL); + $array = $assets->getCss(); + $this->assertSame(reset($array), [ + 'asset' => '/test.css', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'group' => 'head' + ]); + //test addJs() $assets->reset(); $assets->addJs('test.js'); $js = $assets->js(); $this->assertSame($js, '' . PHP_EOL); + $array = $assets->getJs(); + $this->assertSame(reset($array), [ + 'asset' => '/test.js', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'loading' => '', + 'group' => 'head' + ]); + //Test CSS Groups $assets->reset(); $assets->addCSS('test.css', null, true, 'footer'); @@ -62,6 +99,15 @@ class AssetsTest extends \Codeception\TestCase\Test $css = $assets->css('footer'); $this->assertSame($css, '' . PHP_EOL); + $array = $assets->getCss(); + $this->assertSame(reset($array), [ + 'asset' => '/test.css', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'group' => 'footer' + ]); + //Test JS Groups $assets->reset(); $assets->addJs('test.js', null, true, null, 'footer'); @@ -70,17 +116,46 @@ class AssetsTest extends \Codeception\TestCase\Test $js = $assets->js('footer'); $this->assertSame($js, '' . PHP_EOL); + $array = $assets->getJs(); + $this->assertSame(reset($array), [ + 'asset' => '/test.js', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'loading' => '', + 'group' => 'footer' + ]); + //Test async / defer $assets->reset(); $assets->addJs('test.js', null, true, 'async', null); $js = $assets->js(); $this->assertSame($js, '' . PHP_EOL); + + $array = $assets->getJs(); + $this->assertSame(reset($array), [ + 'asset' => '/test.js', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'loading' => 'async', + 'group' => 'head' + ]); + $assets->reset(); $assets->addJs('test.js', null, true, 'defer', null); $js = $assets->js(); $this->assertSame($js, '' . PHP_EOL); - + $array = $assets->getJs(); + $this->assertSame(reset($array), [ + 'asset' => '/test.js', + 'priority' => 10, + 'order' => 0, + 'pipeline' => true, + 'loading' => 'defer', + 'group' => 'head' + ]); } public function testAddingAssetPropertiesWithArray() From 74fdca79f064c5b54d8ccbc612d774fe3c153bae Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:24:47 +0100 Subject: [PATCH 02/14] :white_check_mark: Test Assets::getCollections() --- tests/unit/Grav/Common/AssetsTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index a3272610b..b7f2d1f6c 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -330,6 +330,16 @@ class AssetsTest extends \Codeception\TestCase\Test $assets->addInlineJs('alert("test")'); $js = $assets->js(); $this->assertSame($js, PHP_EOL. '' . PHP_EOL); + + public function testGetCollections() + { + $assets = $this->assets(); + + $this->assertTrue(is_array($assets->getCollections())); + $this->assertTrue(in_array('jquery', array_keys($assets->getCollections()))); + $this->assertTrue(in_array('system://assets/jquery/jquery-2.x.min.js', $assets->getCollections())); + } + } } \ No newline at end of file From 60876f2f0902a8f3740fa80b776ba40d259a8bb6 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:24:57 +0100 Subject: [PATCH 03/14] :white_check_mark: Test Assets::exists() --- tests/unit/Grav/Common/AssetsTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index b7f2d1f6c..577ed479a 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -340,6 +340,12 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertTrue(in_array('system://assets/jquery/jquery-2.x.min.js', $assets->getCollections())); } + public function testExists() + { + $assets = $this->assets(); + + $this->assertTrue($assets->exists('jquery')); + $this->assertFalse($assets->exists('another-unexisting-library')); } } \ No newline at end of file From 2a06cfc5e28647aa7caa065d5e5c5befe8664859 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:25:53 +0100 Subject: [PATCH 04/14] :white_check_mark: Test Assets::reset() --- tests/unit/Grav/Common/AssetsTest.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index 577ed479a..b8aea496d 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -348,4 +348,27 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertFalse($assets->exists('another-unexisting-library')); } -} \ No newline at end of file +} + public function testReset() + { + $assets = $this->assets(); + + $assets->addInlineJs('alert("test")'); + $assets->reset(); + $this->assertTrue(count($assets->js()) == 0); + + $assets->addAsyncJs('jquery'); + $assets->reset(); + + $this->assertTrue(count($assets->js()) == 0); + + $assets->addInlineCss('body { color: black }'); + $assets->reset(); + + $this->assertTrue(count($assets->css()) == 0); + + $assets->add('/system/assets/debugger.css', null, true); + $assets->reset(); + + $this->assertTrue(count($assets->css()) == 0); + } From 4ef5236a53034d2acff627517eb03958747467a6 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:26:03 +0100 Subject: [PATCH 05/14] :white_check_mark: Test Assets::registerCollection() --- tests/unit/Grav/Common/AssetsTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index b8aea496d..eef6a7148 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -348,7 +348,15 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertFalse($assets->exists('another-unexisting-library')); } -} + public function testRegisterCollection() + { + $assets = $this->assets(); + + $assets->registerCollection('debugger', ['/system/assets/debugger.css']); + $this->assertTrue($assets->exists('debugger')); + $this->assertTrue(in_array('debugger', array_keys($assets->getCollections()))); + } + public function testReset() { $assets = $this->assets(); @@ -372,3 +380,4 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertTrue(count($assets->css()) == 0); } +} From 15043e1a113d33ba524a1bc2c5cd474ec75bde74 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:27:24 +0100 Subject: [PATCH 06/14] :bug: In Assets::reset() also reset the inline CSS and inline JS arrays --- system/src/Grav/Common/Assets.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 5790370fc..2887cb577 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -834,6 +834,7 @@ class Assets public function resetJs() { $this->js = []; + $this->inline_js = []; return $this; } @@ -846,6 +847,7 @@ class Assets public function resetCss() { $this->css = []; + $this->inline_css = []; return $this; } From 7ab75811adb1d3ae84d0124370506a4903d34475 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:27:49 +0100 Subject: [PATCH 07/14] :books: Drop old link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01ce1fb0d..df4706876 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ What you mainly want to know is that: * [What is Grav?](http://learn.getgrav.org/basics/what-is-grav) * [Install](http://learn.getgrav.org/basics/installation) Grav in few seconds * Understand the [Configuration](http://learn.getgrav.org/basics/grav-configuration) -* Take a peek at our available free [Skeletons](http://getgrav.org/downloads/skeletons#extras) +* Take a peek at our available free [Skeletons](http://getgrav.org/downloads/skeletons) * If you have questions, jump on our [Gitter Room](https://gitter.im/getgrav/grav)! * Have fun! From dec78b9cbd0906a9a0b72f9c527ab46d402fa158 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 10:51:04 +0100 Subject: [PATCH 08/14] :white_check_mark: Test Assets::resetJs() and Assets::resetCss() Also fix closing parentheses. Added PHPDoc --- tests/unit/Grav/Common/AssetsTest.php | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index eef6a7148..e41b85c0c 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -2,6 +2,9 @@ use Codeception\Util\Fixtures; +/** + * Class AssetsTest + */ class AssetsTest extends \Codeception\TestCase\Test { /** @@ -329,7 +332,9 @@ class AssetsTest extends \Codeception\TestCase\Test $assets->reset(); $assets->addInlineJs('alert("test")'); $js = $assets->js(); - $this->assertSame($js, PHP_EOL. '' . PHP_EOL); + $this->assertSame($js, + PHP_EOL . '' . PHP_EOL); + } public function testGetCollections() { @@ -380,4 +385,35 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertTrue(count($assets->css()) == 0); } + + public function testResetJs() + { + $assets = $this->assets(); + + $assets->addInlineJs('alert("test")'); + $assets->resetJs(); + $this->assertTrue(count($assets->js()) == 0); + + $assets->addAsyncJs('jquery'); + $assets->resetJs(); + + $this->assertTrue(count($assets->js()) == 0); + } + + public function testResetCss() + { + $assets = $this->assets(); + + $this->assertTrue(count($assets->js()) == 0); + + $assets->addInlineCss('body { color: black }'); + $assets->resetCss(); + + $this->assertTrue(count($assets->css()) == 0); + + $assets->add('/system/assets/debugger.css', null, true); + $assets->resetCss(); + + $this->assertTrue(count($assets->css()) == 0); + } } From 8a41b2e08d17bc7075a8feab6b8802ebaf1d490d Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 11:23:48 +0100 Subject: [PATCH 09/14] :art: Move similar methods near each other. --- system/src/Grav/Common/Assets.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 2887cb577..d7e30256f 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -853,7 +853,19 @@ class Assets } /** - * Add all CSS assets within $directory (relative to public dir). + * Add all JavaScript assets within $directory. + * + * @param string $directory Relative to $this->public_dir + * + * @return $this + */ + public function addDirJs($directory) + { + return $this->addDir($directory, self::JS_REGEX); + } + + /** + * Add all CSS assets within $directory (relative to the Grav root path). * * @param string $directory Relative to $this->public_dir * @@ -1129,18 +1141,6 @@ class Assets return $files; } - /** - * Add all JavaScript assets within $directory. - * - * @param string $directory Relative to $this->public_dir - * - * @return $this - */ - public function addDirJs($directory) - { - return $this->addDir($directory, self::JS_REGEX); - } - /** * Sets the state of CSS Pipeline * From 2721e681ef4ac917c4788a27c4c2651083e43dc2 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 11:46:53 +0100 Subject: [PATCH 10/14] :white_check_mark: Test Assets::addDirCss(), Assets::addDirJs(), Assets::addDir() --- tests/unit/Grav/Common/AssetsTest.php | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index e41b85c0c..37d306318 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -416,4 +416,49 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertTrue(count($assets->css()) == 0); } + + public function testAddDirCss() + { + $assets = $this->assets(); + $assets->reset(); + $assets->addDirCss('/system'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) > 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) == 0); + + $assets->reset(); + $assets->addDirCss('/system/assets'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) > 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) == 0); + + $assets->reset(); + $assets->addDirJs('/system'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) == 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) > 0); + + $assets->reset(); + $assets->addDirJs('/system/assets'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) == 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) > 0); + + $assets->reset(); + $assets->addDir('/system/assets'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) > 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) > 0); + + } } From 8a3636d10ff3722c43729f270d1e321948115660 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 12:08:41 +0100 Subject: [PATCH 11/14] :bug: Fix Assets::addDir() (add addCssDir/addJsDir) to work as expected Was looking up assets in the /assets folder, which is reserved for Grav-compiled assets. Now - Looks up paths from the Grav ROOT_DIR or from a stream location - Internally uses Assets::addJs() and Assets::addJs() instead of directly accessing the assets arrays - Removed the file extension determination effort already done in Assets::add(), use Assets::add() instead --- system/src/Grav/Common/Assets.php | 40 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index d7e30256f..abc0e84f9 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -853,9 +853,9 @@ class Assets } /** - * Add all JavaScript assets within $directory. + * Add all JavaScript assets within $directory * - * @param string $directory Relative to $this->public_dir + * @param string $directory Relative to the Grav root path, or a stream identifier * * @return $this */ @@ -865,9 +865,9 @@ class Assets } /** - * Add all CSS assets within $directory (relative to the Grav root path). + * Add all CSS assets within $directory * - * @param string $directory Relative to $this->public_dir + * @param string $directory Relative to the Grav root path, or a stream identifier * * @return $this */ @@ -879,7 +879,7 @@ class Assets /** * Add all assets matching $pattern within $directory. * - * @param string $directory Relative to $this->public_dir + * @param string $directory Relative to the Grav root path, or a stream identifier * @param string $pattern (regex) * * @return $this @@ -887,13 +887,15 @@ class Assets */ public function addDir($directory, $pattern = self::DEFAULT_REGEX) { - // Check if public_dir exists - if (!is_dir($this->assets_dir)) { - throw new Exception('Assets: Public dir not found'); + $root_dir = rtrim(ROOT_DIR, '/'); + + // Check if $directory is a stream. + if (strpos($directory, '://')) { + $directory = self::$grav['locator']->findResource($directory, null); } // Get files - $files = $this->rglob($this->assets_dir . DIRECTORY_SEPARATOR . $directory, $pattern, $this->assets_dir); + $files = $this->rglob($root_dir . DIRECTORY_SEPARATOR . $directory, $pattern, $root_dir . '/'); // No luck? Nothing to do if (!$files) { @@ -902,27 +904,23 @@ class Assets // Add CSS files if ($pattern === self::CSS_REGEX) { - $this->css = array_unique(array_merge($this->css, $files)); + foreach ($files as $file) { + $this->addCss($file); + } return $this; } // Add JavaScript files if ($pattern === self::JS_REGEX) { - $this->js = array_unique(array_merge($this->js, $files)); + foreach ($files as $file) { + $this->addJs($file); + } return $this; } - // Unknown pattern. We must poll to know the extension :( + // Unknown pattern. foreach ($files as $asset) { - $info = pathinfo($asset); - if (isset($info['extension'])) { - $ext = strtolower($info['extension']); - if ($ext === 'css' && !in_array($asset, $this->css)) { - $this->css[] = $asset; - } elseif ($ext === 'js' && !in_array($asset, $this->js)) { - $this->js[] = $asset; - } - } + $this->add($asset); } return $this; From cbb1cc2b858db678c68667ea7e56b7ead8d62ed9 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 12:09:04 +0100 Subject: [PATCH 12/14] :white_check_mark: Test using Streams in Assets::addDir() --- tests/unit/Grav/Common/AssetsTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index 37d306318..82f37ba22 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -460,5 +460,14 @@ class AssetsTest extends \Codeception\TestCase\Test $this->assertTrue(is_array($assets->getJs())); $this->assertTrue(count($assets->getJs()) > 0); + //Use streams + $assets->reset(); + $assets->addDir('system://assets'); + + $this->assertTrue(is_array($assets->getCss())); + $this->assertTrue(count($assets->getCss()) > 0); + $this->assertTrue(is_array($assets->getJs())); + $this->assertTrue(count($assets->getJs()) > 0); + } } From 78c6d6065525a9e1fbfae237f20f885454a705a3 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 15:49:14 +0100 Subject: [PATCH 13/14] :art: Fix the return type for better type hinting --- system/src/Grav/Common/Page/Page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index d394b769c..b04ddd57f 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -986,8 +986,8 @@ class Page /** * Gets and sets the expires field. If not set will return the default * - * @param string $var The name of this page. - * @return string The name of this page. + * @param int $var The new expires value. + * @return int The expires value */ public function expires($var = null) { From e576b05078adccd9d978b5ddf64f3766832e6576 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 27 Jan 2016 15:57:39 +0100 Subject: [PATCH 14/14] :art: Add `use` statements. Add docblocks. Improve code readability and type hints --- system/src/Grav/Common/Browser.php | 3 + system/src/Grav/Common/Cache.php | 23 +++---- system/src/Grav/Common/Composer.php | 5 ++ system/src/Grav/Common/Debugger.php | 93 ++++++++++++++++++++++++++--- system/src/Grav/Common/Getters.php | 2 +- system/src/Grav/Common/Grav.php | 32 ++++++++-- 6 files changed, 133 insertions(+), 25 deletions(-) diff --git a/system/src/Grav/Common/Browser.php b/system/src/Grav/Common/Browser.php index f39ac1539..cf29ae62d 100644 --- a/system/src/Grav/Common/Browser.php +++ b/system/src/Grav/Common/Browser.php @@ -13,6 +13,9 @@ class Browser { protected $useragent = []; + /** + * Browser constructor. + */ public function __construct() { try { diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index f7a6d4bae..d3da1cc4a 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -1,7 +1,7 @@ connect($this->config->get('system.cache.memcache.server','localhost'), $this->config->get('system.cache.memcache.port', 11211)); - $driver = new \Doctrine\Common\Cache\MemcacheCache(); + $driver = new DoctrineCache\MemcacheCache(); $driver->setMemcache($memcache); break; @@ -180,12 +181,12 @@ class Cache extends Getters $redis->connect($this->config->get('system.cache.redis.server','localhost'), $this->config->get('system.cache.redis.port', 6379)); - $driver = new \Doctrine\Common\Cache\RedisCache(); + $driver = new DoctrineCache\RedisCache(); $driver->setRedis($redis); break; default: - $driver = new \Doctrine\Common\Cache\FilesystemCache($this->cache_dir); + $driver = new DoctrineCache\FilesystemCache($this->cache_dir); break; } diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index 5efde8912..804bc4c15 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -35,6 +35,11 @@ class Composer return $path; } + /** + * Return the composer executable file path + * + * @return string + */ public static function getComposerExecutor() { $executor = PHP_BINARY . ' '; diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index 64824ff69..3a91ca502 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -1,8 +1,10 @@ debugbar = new StandardDebugBar(); $this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true)); } + /** + * Initialize the debugger + * + * @return $this + * @throws \DebugBar\DebugBarException + */ public function init() { $this->grav = Grav::instance(); + $this->config = $this->grav['config']; if ($this->enabled()) { - $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$this->grav['config']->get('system'), 'Config')); - $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$this->grav['config']->get('plugins'), 'Plugins')); + $this->debugbar->addCollector(new ConfigCollector((array)$this->config->get('system'), 'Config')); + $this->debugbar->addCollector(new ConfigCollector((array)$this->config->get('plugins'), 'Plugins')); } return $this; } + /** + * Set/get the enabled state of the debugger + * + * @param bool $state If null, the method returns the enabled value. If set, the method sets the enabled state + * @return null + */ public function enabled($state = null) { if (isset($state)) { $this->enabled = $state; } else { if (!isset($this->enabled)) { - $this->enabled = $this->grav['config']->get('system.debugger.enabled'); + $this->enabled = $this->config->get('system.debugger.enabled'); } } return $this->enabled; } + /** + * Add the debugger assets to the Grav Assets + * + * @return $this + */ public function addAssets() { if ($this->enabled()) { + /** @var Assets $assets */ $assets = $this->grav['assets']; // Add jquery library @@ -72,17 +105,36 @@ class Debugger return $this; } + /** + * Adds a data collector + * + * @param $collector + * @return $this + * @throws \DebugBar\DebugBarException + */ public function addCollector($collector) { $this->debugbar->addCollector($collector); return $this; } + /** + * Returns a data collector + * + * @param $collector + * @return \DebugBar\DataCollector\DataCollectorInterface + * @throws \DebugBar\DebugBarException + */ public function getCollector($collector) { return $this->debugbar->getCollector($collector); } + /** + * Displays the debug bar + * + * @return $this + */ public function render() { if ($this->enabled()) { @@ -91,31 +143,58 @@ class Debugger return $this; } + /** + * Sends the data through the HTTP headers + * + * @return $this + */ public function sendDataInHeaders() { $this->debugbar->sendDataInHeaders(); return $this; } + /** + * Start a timer with an associated name and description + * + * @param $name + * @param string|null $description + * + * @return $this + */ public function startTimer($name, $description = null) { - if ($name[0] == '_' || $this->grav['config']->get('system.debugger.enabled')) { + if ($name[0] == '_' || $this->config->get('system.debugger.enabled')) { $this->debugbar['time']->startMeasure($name, $description); $this->timers[] = $name; } return $this; } + /** + * Stop the named timer + * + * @param string $name + * @return $this + */ public function stopTimer($name) { - if (in_array($name, $this->timers) && ($name[0] == '_' || $this->grav['config']->get('system.debugger.enabled'))) { + if (in_array($name, $this->timers) && ($name[0] == '_' || $this->config->get('system.debugger.enabled'))) { $this->debugbar['time']->stopMeasure($name); } return $this; } - + /** + * Dump variables into the Messages tab of the Debug Bar + * + * @param $message + * @param string $label + * @param bool $isString + * + * @return $this + */ public function addMessage($message, $label = 'info', $isString = true) { if ($this->enabled()) { diff --git a/system/src/Grav/Common/Getters.php b/system/src/Grav/Common/Getters.php index 857dccaba..5e2372a34 100644 --- a/system/src/Grav/Common/Getters.php +++ b/system/src/Grav/Common/Getters.php @@ -140,7 +140,7 @@ abstract class Getters implements \ArrayAccess, \Countable return $this->{$var}; } else { $properties = (array) $this; - $list = array(); + $list = []; foreach ($properties as $property => $value) { if ($property[0] != "\0") $list[$property] = $value; } diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 1642211d2..df3e2d99f 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -1,8 +1,10 @@ isExternal($route)) { $url = $route; } else { - if ($this['config']->get('system.pages.redirect_trailing_slash', true)) - $url = rtrim($uri->rootUrl(), '/') .'/'. trim($route, '/'); // Remove trailing slash - else - $url = rtrim($uri->rootUrl(), '/') .'/'. ltrim($route, '/'); // Support trailing slash default routes + $url = rtrim($uri->rootUrl(), '/') .'/'; + + if ($this['config']->get('system.pages.redirect_trailing_slash', true)) { + $url .= trim($route, '/'); // Remove trailing slash + } else { + $url .= ltrim($route, '/'); // Support trailing slash default routes + } } header("Location: {$url}", true, $code);