X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FGenerator%2FGenerator.php;h=4957a9a1c29171d299421160dc9cf1408ba59203;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hp=42fc305b98c472d82796753ce7f5ad9213c4cbee;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/drupal/console-core/src/Generator/Generator.php b/vendor/drupal/console-core/src/Generator/Generator.php index 42fc305b9..4957a9a1c 100644 --- a/vendor/drupal/console-core/src/Generator/Generator.php +++ b/vendor/drupal/console-core/src/Generator/Generator.php @@ -9,9 +9,13 @@ 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; +use Drupal\Console\Core\Style\DrupalStyle; /** * Class Generator + * * @package Drupal\Console\Core\Generator */ abstract class Generator @@ -26,6 +30,21 @@ abstract class Generator */ protected $fileQueue; + /** + * @var CountCodeLines + */ + protected $countCodeLines; + + /** + * @var DrupalFinder + */ + protected $drupalFinder; + + /** + * @var DrupalStyle + */ + protected $io; + /** * @param $renderer */ @@ -42,6 +61,36 @@ 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; + } + + /** + * @return \Drupal\Console\Core\Style\DrupalStyle + */ + public function getIo() { + return $this->io; + } + + /** + * @param \Drupal\Console\Core\Style\DrupalStyle $io + */ + public function setIo($io) { + $this->io = $io; + } + /** * @param string $template * @param string $target @@ -57,17 +106,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); + } }