X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FGenerator%2FGenerator.php;fp=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FGenerator%2FGenerator.php;h=de0826ed69494b02abe67862df626d2de9935364;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=1f559e6eb9530a0f2214f0c1725971cb240b8c8e;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/drupal/console-core/src/Generator/Generator.php b/vendor/drupal/console-core/src/Generator/Generator.php index 1f559e6eb..de0826ed6 100644 --- a/vendor/drupal/console-core/src/Generator/Generator.php +++ b/vendor/drupal/console-core/src/Generator/Generator.php @@ -9,6 +9,8 @@ namespace Drupal\Console\Core\Generator; use Drupal\Console\Core\Utils\TwigRenderer; use Drupal\Console\Core\Utils\FileQueue; +use Drupal\Console\Core\Utils\CountCodeLines; +use Drupal\Console\Core\Utils\DrupalFinder; /** * Class Generator @@ -27,6 +29,16 @@ abstract class Generator */ protected $fileQueue; + /** + * @var CountCodeLines + */ + protected $countCodeLines; + + /** + * @var DrupalFinder + */ + protected $drupalFinder; + /** * @param $renderer */ @@ -43,6 +55,22 @@ abstract class Generator $this->fileQueue = $fileQueue; } + /** + * @param $countCodeLines + */ + public function setCountCodeLines(CountCodeLines $countCodeLines) + { + $this->countCodeLines = $countCodeLines; + } + + /** + * @param DrupalFinder $drupalFinder + */ + public function setDrupalFinder($drupalFinder) + { + $this->drupalFinder = $drupalFinder; + } + /** * @param string $template * @param string $target @@ -58,17 +86,41 @@ abstract class Generator $flag = null ) { if (!is_dir(dirname($target))) { - mkdir(dirname($target), 0777, true); + if (!mkdir(dirname($target), 0777, true)) { + throw new \InvalidArgumentException( + sprintf( + 'Path "%s" is invalid. You need to provide a valid path.', + dirname($target) + ) + ); + } } + $currentLine = 0; + if (!empty($flag) && file_exists($target)) { + $currentLine = count(file($target)); + } $content = $this->renderer->render($template, $parameters); if (file_put_contents($target, $content, $flag)) { $this->fileQueue->addFile($target); + $newCodeLine = count(file($target)); + + if ($currentLine > 0) { + $newCodeLine = ($newCodeLine-$currentLine); + } + + $this->countCodeLines->addCountCodeLines($newCodeLine); + return true; } return false; } + + public function addSkeletonDir($skeletonDir) + { + $this->renderer->addSkeletonDir($skeletonDir); + } }