/** * {@inheritdoc} */ public function execute(ArgumentList $args, BuilderInterface $builder, $simulate) { $source = $builder->source($args[0]); $target = $builder->target($args[1]); $variables = $args->get(2, array()); $mode = $args->get(3, 0644); $directory = dirname($target); if (!is_dir($directory)) { $builder->exec('mkdir', [$directory, 0755, true]); } if (file_exists($target)) { throw new ActionFailedException("Target {$target} already exists"); } $variables['args'] = $builder->getArguments(); $content = $this->getTemplateContent($source, $variables); if (!$simulate) { file_put_contents($target, $content); chmod($target, $mode); } $builder->did('generate', $args[1], [decoct($mode)]); }
/** * {@inheritdoc} */ public function execute(ArgumentList $args, BuilderInterface $builder, $simulate) { $file = $builder->target($args[0]); $params = $args->get(2, false); if (is_array($params) || $params === true) { /** @var TemplateAction $templateAction */ $templateAction = $builder->getAction('template'); $template = $builder->source($args[1]); $string = $templateAction->getTemplateContent($template, is_array($params) ? $params : []); } else { $string = $args[1]; } if (!file_exists($file)) { throw new ActionFailedException("Cannot append to non-existing file {$file}"); } $fp = fopen($file, 'a'); if (!$simulate) { fwrite($fp, $string); } fclose($fp); $builder->did('append', $args[0]); }