-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'src/Pingpong/Generators/' changes from 944f457..23f9e23
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
Showing
4 changed files
with
8 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters