本文整理匯總了PHP中Robo\Result::error方法的典型用法代碼示例。如果您正苦於以下問題:PHP Result::error方法的具體用法?PHP Result::error怎麽用?PHP Result::error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Robo\Result
的用法示例。
在下文中一共展示了Result::error方法的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
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);
}
示例4: 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);
}
示例5: callTaskMethod
/**
* Execute one task method
*/
protected function callTaskMethod($command, $action)
{
try {
$function_result = call_user_func_array($command, $action);
return $this->processResult($function_result);
} catch (IOExceptionInterface $e) {
$this->printTaskInfo("<error>" . $e->getMessage() . "</error>");
return Result::error($this, $e->getMessage(), $e->getPath());
}
}
示例6: run
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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: run
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);
}
示例11: run
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);
}
示例12: run
/**
* Create our working directory.
*
* @return \Robo\Result
*/
public function run()
{
// Destination cannot be empty
if (empty($this->finalDestination)) {
return Result::error($this, "Destination directory not specified.");
}
// Before we do anything else, ensure that any directory in the
// final destination is writable, so that we can at a minimum
// move it out of the way before placing our results there.
if (is_dir($this->finalDestination)) {
if (!is_writable($this->finalDestination)) {
return Result::error($this, "Destination directory {dir} exists and cannot be overwritten.", ['dir' => $this->finalDestination]);
}
}
return parent::run();
}
示例13: run
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]);
}
示例14: 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!');
}
$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);
}
示例15: 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.');
}
$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);
}