-
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/Support/' changes from f1472eb..9401c19
9401c19 CS Fixes 22b2c64 Added Stub class to pingpong/support component 34bf6e8 Fix conflict 11144af PSR-2 git-subtree-dir: src/Pingpong/Support git-subtree-split: 9401c19b1dbdff01606e7362b931fcffade38fb2
- Loading branch information
Gravitano
committed
May 27, 2015
1 parent
c9bdb12
commit 2d7f040
Showing
5 changed files
with
224 additions
and
75 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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
namespace Pingpong\Support; | ||
|
||
class 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 base path. | ||
* | ||
* @return string|null | ||
*/ | ||
public static function getBasePath() | ||
{ | ||
return static::$basePath; | ||
} | ||
|
||
/** | ||
* 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
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
Oops, something went wrong.