示例#1
2
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (is_null($this->dst) || "" === $this->dst) {
         return Result::error($this, 'You must specify a destination file with to() method.');
     }
     if (!$this->checkResources($this->files, 'file')) {
         return Result::error($this, 'Source files are missing!');
     }
     if (file_exists($this->dst) && !is_writable($this->dst)) {
         return Result::error($this, 'Destination already exists and cannot be overwritten.');
     }
     $dump = '';
     foreach ($this->files as $path) {
         foreach (glob($path) as $file) {
             $dump .= file_get_contents($file) . "\n";
         }
     }
     $this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
     $dst = $this->dst . '.part';
     $write_result = file_put_contents($dst, $dump);
     if (false === $write_result) {
         @unlink($dst);
         return Result::error($this, 'File write failed.');
     }
     // Cannot be cross-volume; should always succeed.
     @rename($dst, $this->dst);
     return Result::success($this);
 }
示例#2
0
文件: ResultTest.php 项目: jjok/Robo
 public function testStopOnFail()
 {
     $exceptionClass = false;
     $task = new ResultDummyTask();
     Result::$stopOnFail = true;
     $result = Result::success($task, "Something that worked");
     try {
         $result = Result::error($task, "Something that did not work");
         // stopOnFail will cause Result::error() to throw an exception,
         // so we will never get here. If we did, the assert below would fail.
         $this->assertTrue($result->wasSuccessful());
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $exceptionClass = get_class($e);
     }
     $this->assertEquals(TaskExitException::class, $exceptionClass);
     $this->assertTrue($result->wasSuccessful());
     /*
     // This gives an error:
     //    Exception of class Robo\Exception\TaskExitException expected to
     //    be thrown, but PHPUnit_Framework_Exception caught
     // This happens whether or not the expected exception is thrown
     $this->guy->expectException(TaskExitException::class, function() {
         // $result = Result::error($task, "Something that did not work");
         $result = Result::success($task, "Something that worked");
     });
     */
     Result::$stopOnFail = false;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->skip()) {
         return $this->exec()->arg('locale-update')->run();
     }
     return Result::success($this);
 }
示例#4
0
 public function run()
 {
     foreach ($this->dirs as $src => $dst) {
         $this->fs->mirror($src, $dst, null, ['override' => true, 'copy_on_windows' => true, 'delete' => true]);
         $this->printTaskInfo("Mirrored from {source} to {destination}", ['source' => $src, 'destination' => $dst]);
     }
     return Result::success($this);
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     Environment::set($this->environment);
     if (Environment::isDevdesktop()) {
         $this->ensureDevdesktopPath();
     }
     return Result::success($this);
 }
示例#6
0
文件: CleanDir.php 项目: rdeutz/Robo
 public function run()
 {
     foreach ($this->dirs as $dir) {
         $this->emptyDir($dir);
         $this->printTaskInfo("Cleaned <info>{$dir}</info>");
     }
     return Result::success($this);
 }
示例#7
0
 public function run()
 {
     foreach ($this->dirs as $src => $dst) {
         $this->fs->mirror($src, $dst, null, ['override' => true, 'copy_on_windows' => true, 'delete' => true]);
         $this->printTaskInfo("Mirrored from <info>{$src}</info> to <info>{$dst}</info>");
     }
     return Result::success($this);
 }
示例#8
0
文件: CopyDir.php 项目: lamenath/fbp
 public function run()
 {
     foreach ($this->dirs as $src => $dst) {
         $this->copyDir($src, $dst);
         $this->printTaskInfo("Copied from <info>{$src}</info> to <info>{$dst}</info>");
     }
     return Result::success($this);
 }
示例#9
0
 public function run()
 {
     foreach ($this->dirs as $dir) {
         $this->fs->remove($dir);
         $this->printTaskInfo("deleted <info>{$dir}</info>...");
     }
     return Result::success($this);
 }
示例#10
0
 public function run()
 {
     $delegate = new \ReflectionClass($this->className);
     $replacements = [];
     $leadingCommentChars = " * ";
     $methodDescriptions = [];
     $methodImplementations = [];
     $immediateMethods = [];
     foreach ($delegate->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         $methodName = $method->name;
         $getter = preg_match('/^(get|has|is)/', $methodName);
         $setter = preg_match('/^(set|unset)/', $methodName);
         $argPrototypeList = [];
         $argNameList = [];
         $needsImplementation = false;
         foreach ($method->getParameters() as $arg) {
             $argDescription = '$' . $arg->name;
             $argNameList[] = $argDescription;
             if ($arg->isOptional()) {
                 $argDescription = $argDescription . ' = ' . str_replace("\n", "", var_export($arg->getDefaultValue(), true));
                 // We will create wrapper methods for any method that
                 // has default parameters.
                 $needsImplementation = true;
             }
             $argPrototypeList[] = $argDescription;
         }
         $argPrototypeString = implode(', ', $argPrototypeList);
         $argNameListString = implode(', ', $argNameList);
         if ($methodName[0] != '_') {
             $methodDescriptions[] = "@method {$methodName}({$argPrototypeString})";
             if ($getter) {
                 $immediateMethods[] = "    public function {$methodName}({$argPrototypeString})\n    {\n        return \$this->delegate->{$methodName}({$argNameListString});\n    }";
             } elseif ($setter) {
                 $immediateMethods[] = "    public function {$methodName}({$argPrototypeString})\n    {\n        \$this->delegate->{$methodName}({$argNameListString});\n        return \$this;\n    }";
             } elseif ($needsImplementation) {
                 // Include an implementation for the wrapper method if necessary
                 $methodImplementations[] = "    protected function _{$methodName}({$argPrototypeString})\n    {\n        \$this->delegate->{$methodName}({$argNameListString});\n    }";
             }
         }
     }
     $classNameParts = explode('\\', $this->className);
     $delegate = array_pop($classNameParts);
     $delegateNamespace = implode('\\', $classNameParts);
     if (empty($this->wrapperClassName)) {
         $this->wrapperClassName = $delegate;
     }
     $replacements['{delegateNamespace}'] = $delegateNamespace;
     $replacements['{delegate}'] = $delegate;
     $replacements['{wrapperClassName}'] = $this->wrapperClassName;
     $replacements['{taskname}'] = "task{$delegate}";
     $replacements['{methodList}'] = $leadingCommentChars . implode("\n{$leadingCommentChars}", $methodDescriptions);
     $replacements['{immediateMethods}'] = "\n\n" . implode("\n\n", $immediateMethods);
     $replacements['{methodImplementations}'] = "\n\n" . implode("\n\n", $methodImplementations);
     $template = file_get_contents(__DIR__ . "/GeneratedWrapper.tmpl");
     $template = str_replace(array_keys($replacements), array_values($replacements), $template);
     // Returning data in the $message will cause it to be printed.
     return Result::success($this, $template);
 }
示例#11
0
 public function run()
 {
     $this->printTaskInfo("Writing {$this->filename}");
     $res = file_put_contents($this->filename, $this->body);
     if ($res === false) {
         return Result::error($this, "File {$this->filename} couldnt be created");
     }
     return Result::success($this);
 }
示例#12
0
 /**
  * Check for availablilty of PHP extensions.
  */
 protected function checkExtension($service, $extensionList)
 {
     foreach ((array) $extensionList as $ext) {
         if (!extension_loaded($ext)) {
             return Result::error($this, "You must use PHP with the {$ext} extension enabled to use {$service}");
         }
     }
     return Result::success($this);
 }
示例#13
0
文件: CopyDir.php 项目: jjok/Robo
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->checkResources($this->dirs, 'dir')) {
         return Result::error($this, 'Source directories are missing!');
     }
     foreach ($this->dirs as $src => $dst) {
         $this->copyDir($src, $dst);
         $this->printTaskInfo('Copied from {source} to {destination}', ['source' => $src, 'destination' => $dst]);
     }
     return Result::success($this);
 }
示例#14
0
文件: DeleteDir.php 项目: jjok/Robo
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->checkResources($this->dirs, 'dir')) {
         return Result::error($this, 'Source directories are missing!');
     }
     foreach ($this->dirs as $dir) {
         $this->fs->remove($dir);
         $this->printTaskInfo("Deleted {dir}...", ['dir' => $dir]);
     }
     return Result::success($this);
 }
示例#15
0
 public function run()
 {
     if (!$this->checkResources($this->dirs, 'dir')) {
         return Result::error($this, 'Source directories are missing!');
     }
     foreach ($this->dirs as $dir) {
         $this->emptyDir($dir);
         $this->printTaskInfo("Cleaned <info>{$dir}</info>");
     }
     return Result::success($this);
 }
示例#16
0
 public function __construct($username = '', $password = '', $pathToSvn = 'svn')
 {
     $this->executable = $pathToSvn;
     if (!empty($username)) {
         $this->executable .= " --username {$username}";
     }
     if (!empty($password)) {
         $this->executable .= " --password {$password}";
     }
     $this->result = Result::success($this);
 }
示例#17
0
 public function run()
 {
     if (!$this->checkResources($this->dirs, 'dir')) {
         return Result::error($this, 'Source directories are missing!');
     }
     foreach ($this->dirs as $src => $dst) {
         $this->copyDir($src, $dst);
         $this->printTaskInfo("Copied from <info>{$src}</info> to <info>{$dst}</info>");
     }
     return Result::success($this);
 }
示例#18
0
 public function run()
 {
     if ($this->check()) {
         return Result::success($this);
     }
     $message = 'One or more requirements failed';
     if ($this->stopOnFail) {
         $requirements = array_keys($this->results);
         $message = array_pop($requirements);
     }
     return Result::error($this, $message);
 }
示例#19
0
 public function run()
 {
     $openCommand = $this->getOpenCommand();
     if (empty($openCommand)) {
         return Result::error($this, 'no suitable browser opening command found');
     }
     foreach ($this->urls as $url) {
         passthru(sprintf($openCommand, ProcessUtils::escapeArgument($url)));
         $this->printTaskInfo("Opened <info>{$url}</info>");
     }
     return Result::success($this);
 }
示例#20
0
文件: TmpDir.php 项目: zondor/Robo
 /**
  * Create our temporary directory.
  */
 public function run()
 {
     // Save the current working directory
     $this->savedWorkingDirectory = getcwd();
     foreach ($this->dirs as $dir) {
         $this->fs->mkdir($dir);
         $this->printTaskInfo("Created <info>{$dir}</info>...");
         // Change the current working directory, if requested
         if ($this->cwd) {
             chdir($dir);
         }
     }
     return Result::success($this, '', ['path' => $this->getPath()]);
 }
示例#21
0
文件: Watch.php 项目: lamenath/fbp
 public function run()
 {
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo("watching <info>{$dir}</info> for changes...");
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
示例#22
0
 public function run()
 {
     $result = call_user_func($this->fn);
     // If the function returns no result, then count it
     // as a success.
     if (!isset($result)) {
         $result = Result::success($this);
     }
     // If the function returns a result, it must either return
     // a \Robo\Result or an exit code.  In the later case, we
     // convert it to a \Robo\Result.
     if (!$result instanceof Result) {
         $result = new Result($this, $result);
     }
     return $result;
 }
示例#23
0
 public function run()
 {
     if (empty($this->exec)) {
         throw new TaskException($this, 'You must add at least one command');
     }
     if (!$this->stopOnFail) {
         return $this->taskExec($this->getCommand())->printed($this->isPrinted)->dir($this->workingDirectory)->run();
     }
     foreach ($this->exec as $command) {
         $result = $this->taskExec($command)->printed($this->isPrinted)->dir($this->workingDirectory)->run();
         if (!$result->wasSuccessful()) {
             return $result;
         }
     }
     return Result::success($this);
 }
示例#24
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (!$this->skip()) {
         $this->say('Settings file not available: ' . $this->file);
         $this->say('Let\'s create one...');
         // TODO: use a default development settings file for all local environments and add database config as necessary
         if (!$this->skipDatabaseConnection()) {
             $this->db_host = $this->askDefault('Host', 'localhost');
             $this->db_port = $this->askDefault('Port', '3306');
             $this->db_name = $this->askDefault('Database', 'drupal');
             $this->db_user = $this->askDefault('User', 'root');
             $this->db_pass = $this->askDefault('Password', '');
         }
         return (new Write($this->file))->lines($this->lines())->run();
     }
     return Result::success($this);
 }
示例#25
0
 public function run()
 {
     if (!class_exists('Lurker\\ResourceWatcher')) {
         return Result::errorMissingPackage($this, 'ResourceWatcher', 'henrikbjorn/lurker');
     }
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo('Watching {dir} for changes...', ['dir' => $dir]);
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
示例#26
0
 public function run()
 {
     if (empty($this->exec)) {
         throw new TaskException($this, 'You must add at least one command');
     }
     if (!$this->stopOnFail) {
         $this->printTaskInfo("<info>" . $this->getCommand() . "</info>");
         return $this->executeCommand($this->getCommand());
     }
     foreach ($this->exec as $command) {
         $this->printTaskInfo("Executing <info>{$command}</info>");
         $result = $this->executeCommand($command);
         if (!$result->wasSuccessful()) {
             return $result;
         }
     }
     return Result::success($this);
 }
示例#27
0
文件: Replace.php 项目: roland-d/Robo
 function run()
 {
     if (!file_exists($this->filename)) {
         $this->printTaskError("File {$this->filename} does not exist");
         return false;
     }
     $text = file_get_contents($this->filename);
     if ($this->regex) {
         $text = preg_replace($this->regex, $this->to, $text, -1, $count);
     } else {
         $text = str_replace($this->from, $this->to, $text, $count);
     }
     $res = file_put_contents($this->filename, $text);
     if ($res === false) {
         return Result::error($this, "Error writing to file {$this->filename}.");
     }
     $this->printTaskSuccess("<info>{$this->filename}</info> updated. {$count} items replaced");
     return Result::success($this, '', ['replaced' => $count]);
 }
示例#28
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (is_null($this->dst) || "" === $this->dst) {
         return Result::error($this, 'You must specify a destination file with to() method.');
     }
     if (!$this->checkResources($this->files, 'file')) {
         return Result::error($this, 'Source files are missing!');
     }
     $dump = '';
     foreach ($this->files as $path) {
         foreach (glob($path) as $file) {
             $dump .= file_get_contents($file) . "\n";
         }
     }
     $this->printTaskInfo(sprintf('Writing <info>%s</info>', $this->dst));
     $dst = $this->dst . '.part';
     file_put_contents($dst, $dump);
     rename($dst, $this->dst);
     return Result::success($this);
 }
示例#29
0
文件: Concat.php 项目: lamenath/fbp
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (is_null($this->dst) || "" === $this->dst) {
         return Result::error($this, 'You must specify a destination file with to() method.');
     }
     $dump = '';
     foreach ($this->files as $path) {
         foreach (glob($path) as $file) {
             if (!file_exists($file)) {
                 return Result::error($this, sprintf('File %s not found', $file));
             }
             $dump .= file_get_contents($file);
         }
     }
     $this->printTaskInfo(sprintf('Writing <info>%s</info>', $this->dst));
     $dst = $this->dst . '.part';
     file_put_contents($dst, $dump);
     rename($dst, $this->dst);
     return Result::success($this);
 }
示例#30
0
文件: Simulator.php 项目: jjok/Robo
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $callchain = '';
     foreach ($this->stack as $action) {
         $command = array_shift($action);
         $parameters = $this->formatParameters($action);
         $callchain .= "\n    ->{$command}(<fg=green>{$parameters}</>)";
     }
     $context = $this->getTaskContext(['_level' => RoboLogLevel::SIMULATED_ACTION, 'simulated' => TaskInfo::formatTaskName($this->task), 'parameters' => $this->formatParameters($this->constructorParameters), '_style' => ['simulated' => 'fg=blue;options=bold']]);
     // RoboLogLevel::SIMULATED_ACTION
     $this->printTaskInfo("Simulating {simulated}({parameters}){$callchain}", $context);
     $result = null;
     if ($this->task instanceof SimulatedInterface) {
         $result = $this->task->simulate($context);
     }
     if (!isset($result)) {
         $result = Result::success($this);
     }
     return $result;
 }