* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator; use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Base class for constraint validators. * * @author Bernhard Schussek */ abstract class ConstraintValidator implements ConstraintValidatorInterface { /** * Whether to format {@link \DateTime} objects as RFC-3339 dates * ("Y-m-d H:i:s"). */ const PRETTY_DATE = 1; /** * Whether to cast objects with a "__toString()" method to strings. */ const OBJECT_TO_STRING = 2; /** * @var ExecutionContextInterface */ protected $context; /** * {@inheritdoc} */ public function initialize(ExecutionContextInterface $context) { $this->context = $context; } /** * Returns a string representation of the type of the value. * * This method should be used if you pass the type of a value as * message parameter to a constraint violation. Note that such * parameters should usually not be included in messages aimed at * non-technical people. * * @param mixed $value The value to return the type of * * @return string The type of the value */ protected function formatTypeOf($value) { return is_object($value) ? get_class($value) : gettype($value); } /** * Returns a string representation of the value. * * This method returns the equivalent PHP tokens for most scalar types * (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped * in double quotes ("). Objects, arrays and resources are formatted as * "object", "array" and "resource". If the $format bitmask contains * the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted * as RFC-3339 dates ("Y-m-d H:i:s"). * * Be careful when passing message parameters to a constraint violation * that (may) contain objects, arrays or resources. These parameters * should only be displayed for technical users. Non-technical users * won't know what an "object", "array" or "resource" is and will be * confused by the violation message. * * @param mixed $value The value to format as string * @param int $format A bitwise combination of the format * constants in this class * * @return string The string representation of the passed value */ protected function formatValue($value, $format = 0) { $isDateTime = $value instanceof \DateTimeInterface; if (($format & self::PRETTY_DATE) && $isDateTime) { if (class_exists('IntlDateFormatter')) { $locale = \Locale::getDefault(); $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); // neither the native nor the stub IntlDateFormatter support // DateTimeImmutable as of yet if (!$value instanceof \DateTime) { $value = new \DateTime( $value->format('Y-m-d H:i:s.u e'), $value->getTimezone() ); } return $formatter->format($value); } return $value->format('Y-m-d H:i:s'); } if (is_object($value)) { if (($format & self::OBJECT_TO_STRING) && method_exists($value, '__toString')) { return $value->__toString(); } return 'object'; } if (is_array($value)) { return 'array'; } if (is_string($value)) { return '"'.$value.'"'; } if (is_resource($value)) { return 'resource'; } if (null === $value) { return 'null'; } if (false === $value) { return 'false'; } if (true === $value) { return 'true'; } return (string) $value; } /** * Returns a string representation of a list of values. * * Each of the values is converted to a string using * {@link formatValue()}. The values are then concatenated with commas. * * @param array $values A list of values * @param int $format A bitwise combination of the format * constants in this class * * @return string The string representation of the value list * * @see formatValue() */ protected function formatValues(array $values, $format = 0) { foreach ($values as $key => $value) { $values[$key] = $this->formatValue($value, $format); } return implode(', ', $values); } } __halt_compiler();----SIGNATURE:----irA84wvaxxNkBo13LnaRJ3TkY1M1aKwsH5u33blSJZTGfoGnID59zumwbo4uHt1/16dM8T1gv9GczVo4q83NWiiTQGslF063PJNn10xlCFXrVRTeToytQrJN1Yq4rytbAr0BRKJ9HnFcCc+MMkU3g2nfaMYjZJ+pyqicsgiHllvRon3LhVYxja9YiqGfo1XxAFpStQhMZDFCj3D0u8PIoYewK17vd5kadgJ2gCkG7hdcSnF6VwdwRADyilZlJxkcPwVweFUDeL+NZuDdzRayKBvPye1M3fXOAw0zJwwm+Jcf1QYDJaihGCwnOCGG2EwEf42+MfJe8C///OZA+BuofybQF3CHvYZPOTcCHYbQiR40FWlr5J/MaeL4wjGlQcdTGsNH89/zjKC4vZLPAJ98dWz6mwvSrXG14xAQPBjX3ApkZmv40EOprZgLG7v/9UnSXkqHaE55W9yg1jYIQieq67ZHF61nHW1/QCQ5FRDMtwChzC0+Mlj0q++DZI315RgLgg04hiO/vtyAKQg2mlBWarltHMpAz4UU8MOKvBxF0/0k5WCPUM3h1NdF981ej+P6h/6upuVIVjjEMuP/sxX6I2GSBYHRGokxl9XODSIM8FgkaL5KFGwOzjc5TZuNTJSjRPzu+SnH7mHuFqpMBtp7rlc+c2OW/v+VWx+OfVgBSEA=----ATTACHMENT:----NTE0NjA1NTUzMjc0OTA4OSA5MDA1NzQ3NDU2MDE2NTQ0IDM2NjQ2MzMwOTg5MzQyNQ==