2010-12-03 22:36:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
2011-01-31 01:17:06 +01:00
|
|
|
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(
|
2011-02-08 23:10:58 +01:00
|
|
|
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
|
|
|
);
|
|
|
|
|
2011-02-08 23:10:58 +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
|
|
|
}
|
|
|
|
|
2011-01-31 01:17:06 +01:00
|
|
|
public function getMainMessage()
|
2010-12-03 22:36:46 +01:00
|
|
|
{
|
2011-01-31 01:17:06 +01:00
|
|
|
if (1 === count($this->related))
|
2011-02-08 23:10:58 +01:00
|
|
|
return $this->related[0]
|
|
|
|
->setName($this->getName())
|
|
|
|
->getMainMessage();
|
2011-01-31 01:17:06 +01:00
|
|
|
else
|
|
|
|
return parent::getMainMessage();
|
2010-12-03 22:36:46 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 03:28:02 +01:00
|
|
|
public function getRelated($full=false)
|
|
|
|
{
|
|
|
|
if (!$full && 1 === count($this->related))
|
2011-02-06 23:21:15 +01:00
|
|
|
return $this->related[0]->getRelated(false);
|
2011-02-02 03:28:02 +01:00
|
|
|
else
|
|
|
|
return parent::getRelated($full);
|
|
|
|
}
|
|
|
|
|
2010-12-03 22:36:46 +01:00
|
|
|
}
|