choice() public static method

Assert that value is in array of choices.
public static choice ( mixed $value, array $choices, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$choices array
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 /**
  * @param string $direction
  * @param int $days
  */
 public function __construct($direction, $days)
 {
     Assertion::integerish($days);
     Assertion::choice($direction, [self::DIRECTION_PAST, self::DIRECTION_FUTURE]);
     $this->direction = $direction;
     $this->days = (int) $days;
 }
Exemplo n.º 2
0
 /**
  * @param string $resolution
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withResolution($resolution)
 {
     $choices = [PriceInterface::RESOLUTION_HD, PriceInterface::RESOLUTION_SD];
     Assertion::choice($resolution, $choices);
     $instance = clone $this;
     $instance->resolution = $resolution;
     return $instance;
 }
Exemplo n.º 3
0
 /**
  * @param string $allowEmbed
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withAllowEmbed($allowEmbed)
 {
     $choices = [PlayerLocationInterface::ALLOW_EMBED_NO, PlayerLocationInterface::ALLOW_EMBED_YES];
     Assertion::choice($allowEmbed, $choices);
     $instance = clone $this;
     $instance->allowEmbed = $allowEmbed;
     return $instance;
 }
Exemplo n.º 4
0
 /**
  * Constructor.
  *
  * @param Identifier $identifier
  * @param \DateTimeImmutable $createdAt
  * @param string $url
  * @param string $visibility
  */
 public function __construct(Identifier $identifier, \DateTimeImmutable $createdAt, $url, $visibility)
 {
     Assertion::choice($visibility, static::$visibilityEnum);
     Assertion::url($url);
     $this->identifier = $identifier;
     $this->createdAt = $createdAt;
     $this->url = $url;
     $this->visibility = $visibility;
 }
Exemplo n.º 5
0
 /**
  * @param int $gender
  * @param string $firstName
  * @param string $lastName
  * @param string $email
  */
 public function __construct($gender, $firstName, $lastName, $email)
 {
     Assertion::choice($gender, [self::GENDER_MALE, self::GENDER_FEMALE]);
     Assertion::notEmpty($firstName);
     Assertion::notEmpty($lastName);
     Assertion::email($email);
     $this->gender = $gender;
     $this->firstName = $firstName;
     $this->lastName = $lastName;
     $this->email = $email;
 }
Exemplo n.º 6
0
 /**
  * @param string $result
  * @param Coords $target
  * @param Coords $startPoint
  * @param Coords $endPoint
  */
 private function __construct($result, Coords $target, Coords $startPoint = null, Coords $endPoint = null)
 {
     Assertion::choice($result, [static::HIT, static::MISS, static::SANK, static::WIN]);
     if (in_array($result, [static::SANK, static::WIN])) {
         Assertion::notNull($startPoint);
         Assertion::notNull($endPoint);
     }
     $this->result = $result;
     $this->startPoint = $startPoint;
     $this->endPoint = $endPoint;
     $this->target = $target;
 }
 /**
  * Create a Config.
  *
  * @param string $sender Sender code to use.
  * @param string $wsdl WSDL file to use (local path or URL), null means default depending on the debug mode.
  * @param int $timeoutSec (Optional) Timeout in seconds, null means no timeout.
  * @param string $operatingMode (Optional) Operating mode, default is "P" for production. "D" = Development, "T" = Test.
  * @param array $soapClientOptions (Optional) Options for SoapClient.
  * @param string $receiver (Optional) Receiver code to use, default: YELLOWCUBE.
  */
 function __construct($sender, $wsdl = null, $timeoutSec = null, $operatingMode = 'P', array $soapClientOptions = array(), $receiver = 'YELLOWCUBE')
 {
     Assertion::notEmpty($sender, 'Sender must be set.');
     Assertion::nullOrNotEmpty($wsdl, 'WSDL must be set.');
     Assertion::nullOrInteger($timeoutSec, 'Timeout must be null or an integer in seconds.');
     Assertion::choice($operatingMode, array('T', 'D', 'P'), 'Operating mode must be "T", "D" or "P".');
     Assertion::notEmpty($receiver, 'Receiver must be set.');
     $this->sender = $sender;
     $this->wsdl = $wsdl;
     $this->timeoutSec = $timeoutSec;
     $this->operatingMode = $operatingMode;
     $this->soapClientOptions = $soapClientOptions;
     $this->receiver = $receiver;
 }
Exemplo n.º 8
0
 /**
  * @param UuidInterface $id
  * @param int $type
  * @param string $street
  * @param string $streetNumber
  * @param string $postalCode
  * @param string $city
  * @param string $state
  * @param string $country
  * @param string $phone
  */
 public function __construct(UuidInterface $id, $type, $street, $streetNumber, $postalCode, $city, $state, $country, $phone)
 {
     Assertion::uuid($id->toString());
     Assertion::choice($type, [self::TYPE_BILLING, self::TYPE_SHIPPING]);
     Assertion::notEmpty($street);
     Assertion::notEmpty($streetNumber);
     Assertion::notEmpty($postalCode);
     Assertion::notEmpty($city);
     Assertion::notEmpty($state);
     Assertion::notEmpty($country);
     Assertion::notEmpty($phone);
     $this->id = $id;
     $this->type = $type;
     $this->street = $street;
     $this->streetNumber = $streetNumber;
     $this->postalCode = $postalCode;
     $this->city = $city;
     $this->state = $state;
     $this->country = $country;
     $this->phone = $phone;
 }
 public function __construct($filters, $offset, $limit, $sortField, $sortOrder, $isPaginated)
 {
     Assertion::isArray($filters, "Invalid filters");
     Assertion::integerish($limit, "Invalid limit");
     Assertion::integerish($offset, "Invalid offset");
     Assertion::nullOrString($sortField, "Invalid sort field");
     Assertion::choice($sortOrder, [null, self::ORDER_ASC, self::ORDER_DESC], "Invalid sort order");
     Assertion::boolean($isPaginated, "Invalid value for isPaginated");
     if ($limit < 0) {
         throw new \InvalidArgumentException("Invalid limit");
     }
     if ($offset < 0) {
         throw new \InvalidArgumentException("Invalid offset");
     }
     $this->filters = $filters;
     $this->offset = (int) $offset;
     $this->limit = (int) $limit;
     $this->sortField = $sortField;
     $this->sortOrder = $sortOrder;
     $this->isPaginated = (bool) $isPaginated;
 }
Exemplo n.º 10
0
 /**
  * @param string $live
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withLive($live)
 {
     $choices = [VideoInterface::LIVE_NO, VideoInterface::LIVE_YES];
     Assertion::choice($live, $choices);
     $instance = clone $this;
     $instance->live = $live;
     return $instance;
 }
Exemplo n.º 11
0
 /**
  * @param string $relationship
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($relationship)
 {
     $choices = [PlatformInterface::RELATIONSHIP_ALLOW, PlatformInterface::RELATIONSHIP_DENY];
     Assertion::choice($relationship, $choices);
     $this->relationship = $relationship;
 }
 /**
  * @param string $value
  */
 private function __construct($value)
 {
     Guard::choice($value, $this->possibleValues());
     $this->value = $value;
 }
Exemplo n.º 13
0
 private function __construct($type)
 {
     Assertion::choice($type, ['read', 'write']);
     $this->type = $type;
 }
Exemplo n.º 14
0
 /**
  * @param string $changeFrequency
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withChangeFrequency($changeFrequency)
 {
     $choices = [UrlInterface::CHANGE_FREQUENCY_ALWAYS, UrlInterface::CHANGE_FREQUENCY_HOURLY, UrlInterface::CHANGE_FREQUENCY_DAILY, UrlInterface::CHANGE_FREQUENCY_WEEKLY, UrlInterface::CHANGE_FREQUENCY_MONTHLY, UrlInterface::CHANGE_FREQUENCY_YEARLY, UrlInterface::CHANGE_FREQUENCY_NEVER];
     Assertion::choice($changeFrequency, $choices);
     $instance = clone $this;
     $instance->changeFrequency = $changeFrequency;
     return $instance;
 }
Exemplo n.º 15
0
 /**
  * @param string $algo
  */
 public function __construct($algo)
 {
     Assertion::choice($algo, hash_algos());
     $this->algo = $algo;
 }
 /**
  * @param string $minLevel One of the \Psr\Log\LogLevel constants.
  * @param \Psr\Log\LoggerInterface $logger
  *
  * @throws \InvalidArgumentException if log level is invalid.
  */
 public function __construct($minLevel, LoggerInterface $logger)
 {
     Assertion::choice($minLevel, self::$levelOrder, "Level '{$minLevel}' is not defined.");
     $this->minLevel = $minLevel;
     $this->logger = $logger;
 }
Exemplo n.º 17
0
 public function testValidChoice()
 {
     Assertion::choice("foo", array("foo"));
 }
Exemplo n.º 18
0
 /**
  * @param string $access
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withAccess($access)
 {
     $choices = [NewsInterface::ACCESS_REGISTRATION, NewsInterface::ACCESS_SUBSCRIPTION];
     Assertion::choice($access, $choices);
     $instance = clone $this;
     $instance->access = $access;
     return $instance;
 }