From 58434635327ab9e4653b6a8194d06c521277467a Mon Sep 17 00:00:00 2001 From: Gravitano Date: Wed, 27 May 2015 14:47:18 +0700 Subject: [PATCH] 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 --- Generator.php | 10 ++-- README.md | 2 +- Stub.php | 140 +------------------------------------------------- composer.json | 1 + 4 files changed, 8 insertions(+), 145 deletions(-) diff --git a/Generator.php b/Generator.php index d82864f9..cd8b86ca 100644 --- a/Generator.php +++ b/Generator.php @@ -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(); } /** diff --git a/README.md b/README.md index 1fcdb40e..df165adf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Laravel Generators +Laravel 5 Generators ============== Official documentation is located [here](http://sky.pingpong-labs.com/docs/2.0/generators) \ No newline at end of file diff --git a/Stub.php b/Stub.php index 6295b9e8..d7492528 100644 --- a/Stub.php +++ b/Stub.php @@ -1,143 +1,5 @@ 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(); - } } diff --git a/composer.json b/composer.json index ef230bd1..d95faf55 100644 --- a/composer.json +++ b/composer.json @@ -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": {