Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(ArgumentList $args, BuilderInterface $builder, $simulate)
 {
     $dir = $builder->target($args[0]);
     $mode = $args->get(1, 0777);
     if (file_exists($dir)) {
         throw new ActionFailedException("Target directory {$args[0]} already exists");
     }
     if (!$simulate) {
         mkdir($dir, $mode, $args->get(2, true));
     }
     $builder->did('mkdir', $args[0], [decoct($mode)]);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function execute(ArgumentList $args, BuilderInterface $builder, $simulate)
 {
     $file = $builder->target($args[0]);
     $mode = $args->get(1, 0644);
     if (file_exists($file)) {
         throw new ActionFailedException("Cannot create {$file}, file already exists.");
     }
     if (!$simulate) {
         touch($file);
         chmod($file, $mode);
     }
     $builder->did('create', $args[0], [decoct($mode)]);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function execute(ArgumentList $args, BuilderInterface $builder, $simulate)
 {
     $file = $builder->target($args[0]);
     $mode = $args->get(1, 0644);
     if (!file_exists($file)) {
         $builder->exec('create', [$file, $mode]);
     } else {
         if (!$simulate) {
             touch($file);
         }
         $builder->did('touch', $args[0]);
     }
 }
Exemplo n.º 4
0
 /**
  * {@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)]);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function execute(ArgumentList $args, BuilderInterface $builder, $simulate)
 {
     $file = $builder->target($args[0]);
     $from = $args[1];
     $to = $args[2];
     $regex = $args->get(3, false);
     $limit = $args->get(4, -1);
     $offset = $args->get(5, 0);
     if (!file_exists($file) || !is_readable($file)) {
         throw new ActionFailedException("File {$file} does not exist or is not readable.");
     }
     $content = file_get_contents($file);
     if ($regex) {
         $content = StringUtil::regexReplace($from, $to, $content, $offset, $limit);
     } else {
         $content = StringUtil::stringReplace($from, $to, $content, $offset, $limit);
     }
     if (!$simulate) {
         file_put_contents($file, $content);
     }
     $builder->did('replace', $args[0], [$from, $to]);
 }
Exemplo n.º 6
0
 /**
  * {@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]);
 }