Skip to content

Commit

Permalink
Squashed 'src/Pingpong/Generators/' changes from 944f457..23f9e23
Browse files Browse the repository at this point in the history
23f9e23 update title
8ebfbd6 CS Fixes
d7ab18a Fix stub path issue when using pingpong/modules & pingpong/generators. ref pingpong-modules#158

git-subtree-dir: src/Pingpong/Generators
git-subtree-split: 23f9e237741d65a9435ba93b3d2c470334b4f26d
  • Loading branch information
Gravitano committed May 27, 2015
1 parent 64ef53e commit 5843463
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 145 deletions.
10 changes: 5 additions & 5 deletions Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function setFilesystem(Filesystem $filesystem)
*/
public function getStub()
{
return (new Stub(
__DIR__ . '/Stubs/' . $this->stub . '.stub',
$this->getReplacements()
)
)->render();
$stub = new Stub($this->stub . '.stub', $this->getReplacements());

$stub->setBasePath(__DIR__ . '/Stubs/');

return $stub->render();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Laravel Generators
Laravel 5 Generators
==============

Official documentation is located [here](http://sky.pingpong-labs.com/docs/2.0/generators)
140 changes: 1 addition & 139 deletions Stub.php
Original file line number Diff line number Diff line change
@@ -1,143 +1,5 @@
<?php namespace Pingpong\Generators;

class Stub
class Stub extends \Pingpong\Support\Stub
{

/**
* The stub path.
*
* @var string
*/
protected $path;

/**
* The base path of stub file.
*
* @var null|string
*/
protected static $basePath = null;

/**
* The replacements array.
*
* @var array
*/
protected $replaces = [];

/**
* The contructor.
*
* @param string $path
* @param array $replaces
*/
public function __construct($path, array $replaces = [])
{
$this->path = $path;
$this->replaces = $replaces;
}

/**
* Create new self instance.
*
* @param string $path
* @param array $replaces
* @return self
*/
public static function create($path, array $replaces = [])
{
return new static($path, $replaces);
}

/**
* Set stub path.
*
* @param string $path
* @return self
*/
public function setPath($path)
{
$this->path = $path;

return $this;
}

/**
* Get stub path.
*
* @return string
*/
public function getPath()
{
return static::$basePath . $this->path;
}

/**
* Set base path.
*
* @param string $path
* @return void
*/
public static function setBasePath($path)
{
static::$basePath = $path;
}

/**
* Get stub contents.
*
* @return mixed|string
*/
public function getContents()
{
$contents = file_get_contents($this->getPath());

foreach ($this->replaces as $search => $replace) {
$contents = str_replace('$' . strtoupper($search) . '$', $replace, $contents);
}

return $contents;
}

/**
* Get stub contents.
*
* @return string
*/
public function render()
{
return $this->getContents();
}

/**
* Set replacements array.
*
* @param array $replaces
* @return $this
*/
public function replace(array $replaces = [])
{
$this->replaces = $replaces;

return $this;
}

/**
* Get replacements.
*
* @return array
*/
public function getReplaces()
{
return $this->replaces;
}

/**
* Handle magic method __toString.
*
* @return string
*/
public function __toString()
{
return $this->render();
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"php": ">=5.4.0",
"illuminate/filesystem": "5.0.*",
"illuminate/support": "5.0.*",
"pingpong/support": "~2.0",
"doctrine/dbal": "~2.5"
},
"require-dev": {
Expand Down

0 comments on commit 5843463

Please sign in to comment.