5 * Contains \Drupal\Console\Core\Generator\Generator.
8 namespace Drupal\Console\Core\Generator;
10 use Drupal\Console\Core\Utils\TwigRenderer;
11 use Drupal\Console\Core\Utils\FileQueue;
12 use Drupal\Console\Core\Utils\CountCodeLines;
13 use Drupal\Console\Core\Utils\DrupalFinder;
14 use Drupal\Console\Core\Style\DrupalStyle;
19 * @package Drupal\Console\Core\Generator
21 abstract class Generator
36 protected $countCodeLines;
41 protected $drupalFinder;
51 public function setRenderer(TwigRenderer $renderer)
53 $this->renderer = $renderer;
59 public function setFileQueue(FileQueue $fileQueue)
61 $this->fileQueue = $fileQueue;
65 * @param $countCodeLines
67 public function setCountCodeLines(CountCodeLines $countCodeLines)
69 $this->countCodeLines = $countCodeLines;
73 * @param DrupalFinder $drupalFinder
75 public function setDrupalFinder($drupalFinder)
77 $this->drupalFinder = $drupalFinder;
81 * @return \Drupal\Console\Core\Style\DrupalStyle
83 public function getIo() {
88 * @param \Drupal\Console\Core\Style\DrupalStyle $io
90 public function setIo($io) {
95 * @param string $template
96 * @param string $target
97 * @param array $parameters
102 protected function renderFile(
108 if (!is_dir(dirname($target))) {
109 if (!mkdir(dirname($target), 0777, true)) {
110 throw new \InvalidArgumentException(
112 'Path "%s" is invalid. You need to provide a valid path.',
120 if (!empty($flag) && file_exists($target)) {
121 $currentLine = count(file($target));
123 $content = $this->renderer->render($template, $parameters);
125 if (file_put_contents($target, $content, $flag)) {
126 $this->fileQueue->addFile($target);
128 $newCodeLine = count(file($target));
130 if ($currentLine > 0) {
131 $newCodeLine = ($newCodeLine-$currentLine);
134 $this->countCodeLines->addCountCodeLines($newCodeLine);
142 public function addSkeletonDir($skeletonDir)
144 $this->renderer->addSkeletonDir($skeletonDir);