本文整理汇总了PHP中Result::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Result::getErrors方法的具体用法?PHP Result::getErrors怎么用?PHP Result::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Result
的用法示例。
在下文中一共展示了Result::getErrors方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddErrors
/**
* @covers W3C\Validation\Result::addError
* @covers W3C\Validation\Result::getErrors
*/
public function testAddErrors()
{
$violation1 = new Violation();
$violation2 = new Violation();
$this->result->addError($violation1);
$this->result->addError($violation2);
$this->assertSame(array($violation1, $violation2), $this->result->getErrors());
}
示例2: the_result_correctly_reports_whether_or_not_it_is_valid
/**
* @group response-validation
* @test
*/
public function the_result_correctly_reports_whether_or_not_it_is_valid()
{
$result = new Result();
$this->assertTrue($result->isValid());
$this->assertCount(0, $result->getErrors());
$result->addError('Oh noooos!');
$this->assertFalse($result->isValid());
$this->assertCount(1, $result->getErrors());
}
示例3: merge
/**
* Returns a result that represents the combination of the two given results.
* In particular, this means:
*
* If $a->getErrors() is empty and $a->isValid() is true, $b is returned.
* If $b->getErrors() is empty and $b->isValid() is true, $a is returned.
*
* Otherwise, a new Result is constructed that contains
* all errors from $a and $b, and is considered valid
* if both $a and $b were valid.
*
* @since 0.1
*
* @param Result $a
* @param Result $b
*
* @return Result
*/
public static function merge(Result $a, Result $b)
{
$aErrors = $a->getErrors();
$bErrors = $b->getErrors();
if ($a->isValid() && empty($aErrors)) {
return $b;
} elseif ($b->isValid() && empty($bErrors)) {
return $a;
} else {
$errors = array_merge($aErrors, $bErrors);
$valid = $a->isValid() && $b->isValid();
return new Result($valid, $errors);
}
}
示例4: writeResult
/**
* @param Result $result
* @param ErrorFormatter $errorFormatter
* @param bool $ignoreFails
*/
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
{
if ($this->checkedFiles % $this->filesPerLine !== 0) {
$rest = $this->filesPerLine - $this->checkedFiles % $this->filesPerLine;
$this->write(str_repeat(' ', $rest));
$this->writeProgress();
}
$this->writeNewLine(2);
$testTime = round($result->getTestTime(), 1);
$message = "Checked {$result->getCheckedFilesCount()} files in {$testTime} ";
$message .= $testTime == 1 ? 'second' : 'seconds';
if ($result->getSkippedFilesCount() > 0) {
$message .= ", skipped {$result->getSkippedFilesCount()} ";
$message .= $result->getSkippedFilesCount() === 1 ? 'file' : 'files';
}
$this->writeLine($message);
if (!$result->hasSyntaxError()) {
$message = "No syntax error found";
} else {
$message = "Syntax error found in {$result->getFilesWithSyntaxErrorCount()} ";
$message .= $result->getFilesWithSyntaxErrorCount() === 1 ? 'file' : 'files';
}
if ($result->hasFilesWithFail()) {
$message .= ", failed to check {$result->getFilesWithFailCount()} ";
$message .= $result->getFilesWithFailCount() === 1 ? 'file' : 'files';
if ($ignoreFails) {
$message .= ' (ignored)';
}
}
$hasError = $ignoreFails ? $result->hasSyntaxError() : $result->hasError();
$this->writeLine($message, $hasError ? self::TYPE_ERROR : self::TYPE_OK);
if ($result->hasError()) {
$this->writeNewLine();
foreach ($result->getErrors() as $error) {
$this->writeLine(str_repeat('-', 60));
$this->writeLine($errorFormatter->format($error));
}
}
}
示例5: doOutput
/**
* Handle output based on Environment and Options
* @param Result $result Object derived from Result
* @return Interpreter
*/
public function doOutput(Result $result)
{
$this->debug(__METHOD__, __LINE__);
if ($this->environment->isWeb()) {
$json = json_encode($result->toArray());
$this->stdout($json);
} else {
if ($result->hasErrors()) {
foreach ($result->getErrors() as $error) {
$errstr = $this->outputFormatErrorMessage($error);
$this->stderr($errstr);
}
if ($result->isFail()) {
return;
}
}
if ($buffer = trim($result->getOutput())) {
$this->stdout($buffer . PHP_EOL);
}
}
}
示例6: actionSave
public function actionSave($id)
{
// Получаем куки для опроса
/*
define('COOKIE_NAME', 'poll_genplanmos_ru');
$isCookie = isset(Yii::app()->request->cookies[COOKIE_NAME]->value);
$pollCookie = $isCookie ?
Yii::app()->request->cookies[COOKIE_NAME] :
new CHttpCookie(COOKIE_NAME, '');
$pollCookieValue = $isCookie? CJSON::decode($pollCookie->value) : array();
*
*/
// Авторизован ли пользователь
if (Yii::app()->user->isAuthenticated() === false) {
$this->redirect(Yii::app()->user->loginUrl);
}
if (($user = Yii::app()->user->getProfile()) === null) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
Yii::app()->user->logout();
$this->redirect((array) '/user/account/login');
}
$poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active')))->findByPK((int) $id);
if (!$poll) {
throw new CHttpException(404, Yii::t('PollModule.poll', 'Страница не найдена'));
}
// Поиск результата
$result = Result::model()->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $user->id, ':poll_id' => $poll->id));
if ($result !== null) {
throw new CHttpException(403, Yii::t('PollModule.poll', 'Вы уже проходили данный опрос'));
}
$result = new Result();
$result->user_id = $user->id;
$result->poll_id = $poll->id;
// Обработка результата
if (($data = Yii::app()->getRequest()->getPost('question')) !== null) {
// Формирование списка ответов
$answers = array();
foreach ($poll->questions as $question) {
$formValue = isset($data[$question->id]) ? $data[$question->id] : null;
switch ($question->type) {
case Question::TYPE_VARIANT:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = $formValue !== null ? (int) $formValue : $formValue;
$answers[] = $answer;
break;
case Question::TYPE_MULTIPLE:
// Просматриваем полученные ответы
if (!isset($formValue) || !is_array($formValue)) {
break;
}
foreach ($formValue as $value) {
$answer = new Answer();
$answer->question_id = $question->id;
$answer->variant_id = (int) $value;
$answers[] = $answer;
}
break;
default:
$answer = new Answer();
$answer->question_id = $question->id;
$answer->value = $formValue !== null ? $formValue : '';
$answers[] = $answer;
break;
}
$result->answers = $answers;
}
if ($result->validate()) {
$result->save();
Yii::app()->ajax->success(array('html' => $this->widget('application.modules.poll.widgets.PollWidget', array('model_id' => $poll->id), true)));
} else {
Yii::app()->ajax->failure(array('message' => '', 'errors' => $result->getErrors()));
}
}
}