Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from clue/stub-banner
Browse files Browse the repository at this point in the history
Add option to set top header comment banner text for stub
  • Loading branch information
kherge committed May 20, 2013
2 parents f4e8c31 + 7272bfb commit 69a742e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/lib/Herrera/Box/StubGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -93,6 +102,20 @@ public function alias($alias)
return $this;
}

/**
* Sets the top header comment banner text.
*
* @param string $banner The banner text.
*
* @return StubGenerator The stub generator.
*/
public function banner($banner)
{
$this->banner = $banner;

return $this;
}

/**
* Creates a new instance of the stub generator.
*
Expand Down Expand Up @@ -146,13 +169,15 @@ public function generate()
#!/usr/bin/env php
<?php
STUB;

if ($this->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) {
Expand Down
39 changes: 39 additions & 0 deletions src/tests/Herrera/Box/Tests/StubGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<<<STUB
#!/usr/bin/env php
<?php
/**
* Phar creation
*
* does work
*
*
* indented
*/
__HALT_COMPILER();
STUB
,
$this->generator->generate()
);
}

public function testCreate()
{
$this->assertInstanceOf(
Expand Down

0 comments on commit 69a742e

Please sign in to comment.