From a2730d678f3558833aad48bf9112cacc399b5857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 20 May 2013 00:23:18 +0200 Subject: [PATCH 1/3] Add option to set top header comment banner text --- src/lib/Herrera/Box/StubGenerator.php | 35 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/lib/Herrera/Box/StubGenerator.php b/src/lib/Herrera/Box/StubGenerator.php index 6ea3db8..4a55760 100644 --- a/src/lib/Herrera/Box/StubGenerator.php +++ b/src/lib/Herrera/Box/StubGenerator.php @@ -79,6 +79,15 @@ class StubGenerator */ private $web = false; + /** + * The top header comment banner text. + * + * @var string. + */ + private $banner = 'Generated by Box. + +@link https://github.com/herrera-io/php-box/'; + /** * Sets the alias to be used in "phar://" URLs. * @@ -146,13 +155,15 @@ public function generate() #!/usr/bin/env php banner !== null) { + $stub .= ' /** - * Generated by Box. - * - * @link https://github.com/herrera-io/php-box/ + * ' . str_replace(" \n", "\n", str_replace("\n", "\n * ", $this->banner)) . ' */ - -STUB; +'; + } if ($this->alias) { if ($this->web) { @@ -268,6 +279,20 @@ public function rewrite($function) return $this; } + /** + * Sets the top header comment banner text. + * + * @param string $banner The banner text. + * + * @return StubGenerator The stub generator. + */ + public function setBanner($banner) + { + $this->banner = $banner; + + return $this; + } + /** * Use Phar::webPhar() instead of Phar::mapPhar()? * From 3449f1a8d280225a2f30679534ca75b0c3fac810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 20 May 2013 00:30:29 +0200 Subject: [PATCH 2/3] Add unit tests for banner text --- .../Herrera/Box/Tests/StubGeneratorTest.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/tests/Herrera/Box/Tests/StubGeneratorTest.php b/src/tests/Herrera/Box/Tests/StubGeneratorTest.php index f1a5b6c..76169ac 100644 --- a/src/tests/Herrera/Box/Tests/StubGeneratorTest.php +++ b/src/tests/Herrera/Box/Tests/StubGeneratorTest.php @@ -170,6 +170,45 @@ public function testRewrite() ); } + public function testSetBanner() + { + $this->generator->setBanner('Phar creation + +does work + + + indented'); + + $this->assertEquals( + 'Phar creation + +does work + + + indented', + $this->getPropertyValue($this->generator, 'banner') + ); + + $this->assertEquals( + <<generator->generate() + ); + } + public function testWeb() { $this->generator->web(true); From 7272bfb7257d051abd9edfb96e0a049ef18e8be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 20 May 2013 09:58:57 +0200 Subject: [PATCH 3/3] Rename setBanner() to just banner() --- src/lib/Herrera/Box/StubGenerator.php | 44 +++++------ .../Herrera/Box/Tests/StubGeneratorTest.php | 78 +++++++++---------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/lib/Herrera/Box/StubGenerator.php b/src/lib/Herrera/Box/StubGenerator.php index 4a55760..cad4cda 100644 --- a/src/lib/Herrera/Box/StubGenerator.php +++ b/src/lib/Herrera/Box/StubGenerator.php @@ -30,6 +30,15 @@ class StubGenerator */ private $alias; + /** + * The top header comment banner text. + * + * @var string. + */ + private $banner = 'Generated by Box. + +@link https://github.com/herrera-io/php-box/'; + /** * The location within the Phar of index script. * @@ -80,24 +89,29 @@ class StubGenerator private $web = false; /** - * The top header comment banner text. + * Sets the alias to be used in "phar://" URLs. * - * @var string. + * @param string $alias The alias. + * + * @return StubGenerator The stub generator. */ - private $banner = 'Generated by Box. + public function alias($alias) + { + $this->alias = $alias; -@link https://github.com/herrera-io/php-box/'; + return $this; + } /** - * Sets the alias to be used in "phar://" URLs. + * Sets the top header comment banner text. * - * @param string $alias The alias. + * @param string $banner The banner text. * * @return StubGenerator The stub generator. */ - public function alias($alias) + public function banner($banner) { - $this->alias = $alias; + $this->banner = $banner; return $this; } @@ -279,20 +293,6 @@ public function rewrite($function) return $this; } - /** - * Sets the top header comment banner text. - * - * @param string $banner The banner text. - * - * @return StubGenerator The stub generator. - */ - public function setBanner($banner) - { - $this->banner = $banner; - - return $this; - } - /** * Use Phar::webPhar() instead of Phar::mapPhar()? * diff --git a/src/tests/Herrera/Box/Tests/StubGeneratorTest.php b/src/tests/Herrera/Box/Tests/StubGeneratorTest.php index 76169ac..11362c8 100644 --- a/src/tests/Herrera/Box/Tests/StubGeneratorTest.php +++ b/src/tests/Herrera/Box/Tests/StubGeneratorTest.php @@ -23,6 +23,45 @@ public function testAlias() ); } + public function testBanner() + { + $this->generator->banner('Phar creation + +does work + + + indented'); + + $this->assertEquals( + 'Phar creation + +does work + + + indented', + $this->getPropertyValue($this->generator, 'banner') + ); + + $this->assertEquals( + <<generator->generate() + ); + } + public function testCreate() { $this->assertInstanceOf( @@ -170,45 +209,6 @@ public function testRewrite() ); } - public function testSetBanner() - { - $this->generator->setBanner('Phar creation - -does work - - - indented'); - - $this->assertEquals( - 'Phar creation - -does work - - - indented', - $this->getPropertyValue($this->generator, 'banner') - ); - - $this->assertEquals( - <<generator->generate() - ); - } - public function testWeb() { $this->generator->web(true);