本文整理汇总了PHP中Robo\Result::success方法的典型用法代码示例。如果您正苦于以下问题:PHP Result::success方法的具体用法?PHP Result::success怎么用?PHP Result::success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robo\Result
的用法示例。
在下文中一共展示了Result::success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@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: testStopOnFail
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: run
/**
* {@inheritdoc}
*/
public function run()
{
if (!$this->skip()) {
return $this->exec()->arg('locale-update')->run();
}
return Result::success($this);
}
示例4: run
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: run
/**
* {@inheritdoc}
*/
public function run()
{
Environment::set($this->environment);
if (Environment::isDevdesktop()) {
$this->ensureDevdesktopPath();
}
return Result::success($this);
}
示例6: run
public function run()
{
foreach ($this->dirs as $dir) {
$this->emptyDir($dir);
$this->printTaskInfo("Cleaned <info>{$dir}</info>");
}
return Result::success($this);
}
示例7: run
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: run
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: run
public function run()
{
foreach ($this->dirs as $dir) {
$this->fs->remove($dir);
$this->printTaskInfo("deleted <info>{$dir}</info>...");
}
return Result::success($this);
}
示例10: run
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: run
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: checkExtension
/**
* 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: run
/**
* {@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: run
/**
* {@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: run
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);
}