Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Timezone.php

function Timezone::__construct

Parameters

int|array<string,mixed>|null $zone Restrict valid timezones to this geographical zone (defaults to {@see \DateTimeZone::ALL}):

string|null $countryCode Restrict the valid timezones to this country if the zone option is {@see \DateTimeZone::PER_COUNTRY}:

bool|null $intlCompatible Whether to restrict valid timezones to ones available in PHP's intl (defaults to false):

string[]|null $groups:

array<string,mixed> $options:

Overrides Constraint::__construct

See also

\DateTimeZone

File

vendor/symfony/validator/Constraints/Timezone.php, line 52

Class

Timezone
Validates that a value is a valid timezone identifier.

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct(int|array|null $zone = null, ?string $message = null, ?string $countryCode = null, ?bool $intlCompatible = null, ?array $groups = null, mixed $payload = null, array $options = []) {
    if (\is_array($zone)) {
        $options = array_merge($zone, $options);
    }
    elseif (null !== $zone) {
        $options['value'] = $zone;
    }
    parent::__construct($options, $groups, $payload);
    $this->message = $message ?? $this->message;
    $this->countryCode = $countryCode ?? $this->countryCode;
    $this->intlCompatible = $intlCompatible ?? $this->intlCompatible;
    if (null === $this->countryCode) {
        if (0 >= $this->zone || \DateTimeZone::ALL_WITH_BC < $this->zone) {
            throw new ConstraintDefinitionException('The option "zone" must be a valid range of "\\DateTimeZone" constants.');
        }
    }
    elseif (\DateTimeZone::PER_COUNTRY !== (\DateTimeZone::PER_COUNTRY & $this->zone)) {
        throw new ConstraintDefinitionException('The option "countryCode" can only be used when the "zone" option is configured with "\\DateTimeZone::PER_COUNTRY".');
    }
    if ($this->intlCompatible && !class_exists(\IntlTimeZone::class)) {
        throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.');
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal