respect-validation/library/Respect/Validation/Exceptions/AbstractCompositeException.php

37 lines
1,000 B
PHP
Raw Normal View History

2010-12-03 22:36:46 +01:00
<?php
namespace Respect\Validation\Exceptions;
class AbstractCompositeException extends AbstractRelatedException
2010-12-03 22:36:46 +01:00
{
2011-02-07 02:12:41 +01:00
const NONE = 0;
const SOME = 1;
2010-12-03 22:36:46 +01:00
public static $defaultTemplates = array(
self::NONE => 'All of the %3$d required rules must pass for %1$s',
self::SOME => 'These %2$d rules must pass for %1$s',
2010-12-03 22:36:46 +01:00
);
public function chooseTemplate($name, $numFailed, $numRequired, $numTotal)
2010-12-03 22:36:46 +01:00
{
2011-02-07 02:12:41 +01:00
return $numFailed === $numTotal ? static::NONE : static::SOME;
2010-12-03 22:36:46 +01:00
}
public function getMainMessage()
2010-12-03 22:36:46 +01:00
{
if (1 === count($this->related))
return $this->related[0]
->setName($this->getName())
->getMainMessage();
else
return parent::getMainMessage();
2010-12-03 22:36:46 +01:00
}
public function getRelated($full=false)
{
if (!$full && 1 === count($this->related))
return $this->related[0]->getRelated(false);
else
return parent::getRelated($full);
}
2010-12-03 22:36:46 +01:00
}