public static function task($name, $file, $spec) { $out = \pantr\fileNameTransform($file, $spec); $task = new File($name, 'create file ' . basename($out) . ' if it does not exist'); $task->src = $file; $task->target = $out; pantr::getTaskRepository()->registerTask($task); return $task; }
/** * Copies a single file from $src to $target. * Optionally replaces variables as specified in the * associative array $vars where each key is surrounded with '##' and '##' * or, if $vars is callable, it will place the result of invoking * this callable on the content of the source file into the target file. */ function copy($src, $target, $vars = null) { // read content and modify it $package = file_get_contents($src); if (!is_null($vars)) { if (is_callable($vars)) { $package = $vars($package); } else { foreach ($vars as $k => $v) { $package = str_replace('##' . $k . '##', $v, $package); } } } // make path from pattern $target = \pantr\fileNameTransform($src, $target); if (!is_dir(dirname($target))) { mkdirs(dirname($target)); } writeAction('copy', $src . ' to ' . $target); file_put_contents($target, $package); }