本文整理汇总了PHP中Symfony\Component\Validator\Constraint::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Constraint::__construct方法的具体用法?PHP Constraint::__construct怎么用?PHP Constraint::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* {@inheritdoc}
*/
public function __construct($options = null)
{
// no known options set? $options is the fields array
if (is_array($options) && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
$options = array('fields' => $options);
}
parent::__construct($options);
if (!is_array($this->fields)) {
throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__));
}
foreach ($this->fields as $fieldName => $field) {
// the XmlFileLoader and YamlFileLoader pass the field Optional
// and Required constraint as an array with exactly one element
if (is_array($field) && count($field) == 1) {
$this->fields[$fieldName] = $field = $field[0];
}
if (!$field instanceof Optional && !$field instanceof Required) {
$this->fields[$fieldName] = $field = new Required($field);
}
if (!is_array($field->constraints)) {
$field->constraints = array($field->constraints);
}
foreach ($field->constraints as $constraint) {
if (!$constraint instanceof Constraint) {
throw new ConstraintDefinitionException(sprintf('The value %s of the field %s is not an instance of Constraint in constraint %s', $constraint, $fieldName, __CLASS__));
}
if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__));
}
}
}
}
示例2: __construct
/**
* {@inheritDoc}
*/
public function __construct($options = null)
{
if (is_array($options) && !array_intersect(array_keys($options), array('constraints', 'stopOnError'))) {
$options = array('constraints' => $options);
}
parent::__construct($options);
// convert array of constraints into SplPriorityQueue
if (is_array($this->constraints)) {
$queue = new \SplPriorityQueue();
$constraints = $this->constraints;
$constraints = array_reverse($constraints);
foreach ($constraints as $index => $constraint) {
$queue->insert($constraint, $index);
}
$this->constraints = $queue;
}
if (!$this->constraints instanceof \SplPriorityQueue) {
throw new ConstraintDefinitionException('The option "constraints" is expected to be a SplPriorityQueue in constraint ' . __CLASS__ . '.');
}
$constraintsCopy = $this->getConstraints();
// set extraction mode to both priority and data
$constraintsCopy->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
// loop through the priority chain for options validation
while ($constraintsCopy->valid()) {
$constraint = $constraintsCopy->current();
// fail if the constraint is not actually a constraint
if (!$constraint['data'] instanceof Constraint) {
throw new ConstraintDefinitionException('The option "constraints" (priority: ' . $constraint['priority'] . ') is not a Constraint, in ' . __CLASS__ . '.');
}
// move to next constraint
$constraintsCopy->next();
}
}
示例3: __construct
public function __construct($options = null)
{
parent::__construct($options);
if (!$this->countryCode) {
throw new MissingOptionsException('Country must be given to validate social security numbers', array('countryCode'));
}
}
示例4: __construct
/**
* {@inheritdoc}
*/
public function __construct($options = null)
{
parent::__construct($options);
if ((!is_string($this->service) || !is_string($this->method)) && $this->serializingWarning !== true) {
throw new \RuntimeException('You are using a closure with the `InlineConstraint`, this constraint' . ' cannot be serialized. You need to re-attach the `InlineConstraint` on each request.' . ' Once done, you can set the `serializingWarning` option to `true` to avoid this message.');
}
}
示例5: __construct
public function __construct($options = null)
{
parent::__construct($options);
if (null === $this->min && null === $this->max) {
throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
}
}
示例6: __construct
/**
* {@inheritDoc}
*/
public function __construct($options = null)
{
// no known options set? $options is the fields array
if (is_array($options) && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
$options = array('fields' => $options);
}
parent::__construct($options);
if (!is_array($this->fields)) {
throw new ConstraintDefinitionException('The option "fields" is expected to be an array in constraint ' . __CLASS__);
}
foreach ($this->fields as $fieldName => $field) {
if (!$field instanceof Optional && !$field instanceof Required) {
$this->fields[$fieldName] = $field = new Required($field);
}
if (!is_array($field->constraints)) {
$field->constraints = array($field->constraints);
}
foreach ($field->constraints as $constraint) {
if (!$constraint instanceof Constraint) {
throw new ConstraintDefinitionException('The value ' . $constraint . ' of the field ' . $fieldName . ' is not an instance of Constraint in constraint ' . __CLASS__);
}
if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException('The constraint Valid cannot be nested inside constraint ' . __CLASS__ . '. You can only declare the Valid constraint directly on a field or method.');
}
}
}
}
示例7: __construct
/**
* @param \Spryker\Zed\Category\Persistence\CategoryQueryContainerInterface $queryContainer
* @param int $idCategory
* @param \Generated\Shared\Transfer\LocaleTransfer $locale
* @param mixed $options
*/
public function __construct(CategoryQueryContainerInterface $queryContainer, $idCategory, LocaleTransfer $locale, $options = null)
{
parent::__construct($options);
$this->queryContainer = $queryContainer;
$this->idCategory = $idCategory;
$this->locale = $locale;
}
示例8: __construct
public function __construct($options = null)
{
parent::__construct($options);
if (null !== $this->maxSize) {
$this->normalizeBinaryFormat($this->maxSize);
}
}
示例9: __construct
/**
* {@inheritDoc}
*/
public function __construct($options = null)
{
parent::__construct($options);
if (!is_int($this->filter)) {
throw new ConstraintDefinitionException('The option "filter" must be a valid FILTER_ constant in constraint ' . __CLASS__ . '.');
}
}
示例10: __construct
/**
* @inheritDoc
*/
public function __construct($options = null)
{
parent::__construct($options);
if (!in_array($this->version, self::$versions)) {
throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s"', implode('", "', self::$versions)));
}
}
示例11: __construct
/**
* {@inheritDoc}
*/
public function __construct($options = null)
{
if (!isset($options['value'])) {
throw new ConstraintDefinitionException(sprintf('The %s constraint requires the "value" option to be set.', get_class($this)));
}
parent::__construct($options);
}
示例12: __construct
public function __construct($options = null)
{
if (is_array($options) && array_key_exists('groups', $options)) {
throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
}
parent::__construct($options);
}
示例13: __construct
public function __construct($options = null)
{
parent::__construct($options);
if (null === $this->repository || null === $this->property) {
throw new MissingOptionsException(sprintf('The options "repository" and "property" must be given for constraint %s', __CLASS__), array('repository', 'property'));
}
}
示例14: __construct
/**
* {@inheritdoc}
*/
public function __construct($options = null)
{
parent::__construct($options);
// Validate all fields by default.
if (empty($this->fields)) {
$this->fields = AddressField::getAll();
}
}
示例15: __construct
/**
* {@inheritDoc}
*/
public function __construct($options = NULL)
{
parent::__construct($options);
// Validate all fields by default.
if (empty($this->fields)) {
$this->fields = array_values(AddressField::getAll());
}
}