2011-02-20 17:59:53 +01:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2011-02-20 17:59:53 +01:00
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
|
|
|
class AbstractGroupedException extends AbstractNestedException
|
|
|
|
{
|
|
|
|
const NONE = 0;
|
|
|
|
const SOME = 1;
|
|
|
|
public static $defaultTemplates = array(
|
2011-04-10 01:34:21 +02:00
|
|
|
self::MODE_DEFAULT => array(
|
|
|
|
self::NONE => 'All of the required rules must pass for {{name}}',
|
|
|
|
self::SOME => 'These rules must pass for {{name}}',
|
|
|
|
),
|
|
|
|
self::MODE_NEGATIVE => array(
|
|
|
|
self::NONE => 'None of there rules must pass for {{name}}',
|
|
|
|
self::SOME => 'These rules must not pass for {{name}}',
|
2015-01-08 03:15:35 +01:00
|
|
|
),
|
2011-02-20 17:59:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
public function chooseTemplate()
|
|
|
|
{
|
|
|
|
$numRules = $this->getParam('passed');
|
|
|
|
$numFailed = count($this->getRelated());
|
2013-01-14 22:55:03 +01:00
|
|
|
|
2011-02-20 17:59:53 +01:00
|
|
|
return $numRules === $numFailed ? static::NONE : static::SOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParams()
|
|
|
|
{
|
2013-01-14 22:55:03 +01:00
|
|
|
if (1 === count($this->related)) {
|
2011-02-21 01:53:21 +01:00
|
|
|
return current($this->related)->getParams();
|
2013-01-14 22:55:03 +01:00
|
|
|
} else {
|
2011-02-20 17:59:53 +01:00
|
|
|
return parent::getParams();
|
2013-01-14 22:55:03 +01:00
|
|
|
}
|
2011-02-20 17:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTemplate()
|
|
|
|
{
|
2011-08-11 04:05:35 +02:00
|
|
|
$parentTemplate = parent::getTemplate();
|
2012-03-23 02:12:07 +01:00
|
|
|
$isEmpty = empty($this->template);
|
|
|
|
|
2013-01-14 22:55:03 +01:00
|
|
|
if (!$isEmpty && $this->template != $parentTemplate) {
|
2011-04-17 17:29:48 +02:00
|
|
|
return $this->template;
|
2015-01-08 03:15:35 +01:00
|
|
|
}
|
|
|
|
if ($isEmpty && 1 === count($this->related)) {
|
2011-02-21 01:53:21 +01:00
|
|
|
return current($this->related)->getTemplate();
|
2013-01-14 22:55:03 +01:00
|
|
|
} else {
|
2011-08-11 04:05:35 +02:00
|
|
|
return $parentTemplate;
|
2013-01-14 22:55:03 +01:00
|
|
|
}
|
2011-02-20 17:59:53 +01:00
|
|
|
}
|
2013-01-14 22:55:03 +01:00
|
|
|
}
|