isArray() public static method

Assert that value is an array.
public static isArray ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
Ejemplo n.º 1
0
 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::regex($this->projection_type, '#^([a-z][a-z_-]+(?<!_-)\\.){2}[a-z][a-z_]+(?<!_)::projection\\.[a-z][a-z_]+(?<!_)$#');
     Assertion::isArray($this->data);
     Assertion::regex($this->projection_identifier, '/[\\w\\.\\-_]{1,128}\\-\\w{8}\\-\\w{4}\\-\\w{4}\\-\\w{4}\\-\\w{12}\\-\\w{2}_\\w{2}\\-\\d+/');
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function authenticate($subject, Caller $caller)
 {
     Assertion::isArray($subject);
     Assertion::choicesNotEmpty($subject, ['password']);
     Assertion::isInstanceOf($caller, 'Guardian\\User\\Caller', sprintf('The caller was expected to be an instance of "%s"', 'Indigo\\Guardian\\Caller\\User'));
     return $this->hasher->verify($subject['password'], $caller->getPassword());
 }
Ejemplo n.º 3
0
 /**
  * @return \Jose\Object\JWKInterface[]
  */
 public function getKeys()
 {
     $content = json_decode($this->getContent(), true);
     Assertion::isArray($content, 'Invalid content.');
     Assertion::keyExists($content, 'keys', 'Invalid content.');
     return (new JWKSet($content))->getKeys();
 }
Ejemplo n.º 4
0
 private function validate()
 {
     Assertion::keyExists($this->options, 'packages');
     Assertion::isArray($this->options['packages']);
     Assertion::keyExists($this->options, 'rooms');
     Assertion::isArray($this->options['rooms']);
 }
Ejemplo n.º 5
0
 public static function deserialize($data)
 {
     Assertion::isArray($data);
     $entities = array_map(function ($entity) {
         return Entity::deserialize($entity);
     }, $data);
     return new self($entities);
 }
Ejemplo n.º 6
0
 /**
  * Create a new value object
  * @param array $value
  */
 public function __construct($value)
 {
     Assertion::isArray($value);
     foreach ($value as $object) {
         Assertion::implementsInterface($object, EventInterface::class);
     }
     $this->value = SplFixedArray::fromArray($value);
 }
 private function extractWithMetadata($entity, Entity $metadata) : array
 {
     if ($entity instanceof ProxyInterface) {
         $entity = $entity->__getRealEntity();
     }
     Assertion::isInstanceOf($entity, $metadata->getClassName());
     $data = [];
     $reflectionClass = new ReflectionClass($entity);
     foreach ($metadata->getFields() as $fieldMetadata) {
         if ($fieldMetadata->isReadOnly()) {
             continue;
         }
         $fieldName = $fieldMetadata->getFieldName();
         try {
             $type = $fieldMetadata->getType();
             $value = $this->getProperty($reflectionClass, $entity, $fieldMetadata->getPropertyName());
             if (!$fieldMetadata->isRepeatable()) {
                 $data[$fieldName] = $type->toFileMakerValue($value);
                 continue;
             }
             Assertion::isArray($value);
             $index = 0;
             foreach ($value as $individualValue) {
                 $data[sprintf('%s(%d)', $fieldName, ++$index)] = $type->toFileMakerValue($individualValue);
             }
         } catch (Exception $e) {
             throw ExtractionException::fromInvalidField($metadata, $fieldMetadata, $e);
         }
     }
     foreach ($metadata->getEmbeddables() as $embeddableMetadata) {
         $prefix = $embeddableMetadata->getFieldNamePrefix();
         $embeddableData = $this->extractWithMetadata($this->getProperty($reflectionClass, $entity, $embeddableMetadata->getPropertyName()), $embeddableMetadata->getMetadata());
         foreach ($embeddableData as $key => $value) {
             $data[$prefix . $key] = $value;
         }
     }
     $toOne = array_filter($metadata->getManyToOne(), function (ManyToOne $manyToOneMetadata) {
         return !$manyToOneMetadata->isReadOnly();
     }) + array_filter($metadata->getOneToOne(), function (OneToOne $oneToOneMetadata) {
         return $oneToOneMetadata->isOwningSide() && !$oneToOneMetadata->isReadOnly();
     });
     foreach ($toOne as $relationMetadata) {
         $relation = $this->getProperty($reflectionClass, $entity, $relationMetadata->getPropertyName());
         if (null === $relation) {
             $data[$relationMetadata->getFieldName()] = null;
             continue;
         }
         if ($relation instanceof ProxyInterface) {
             Assertion::isInstanceOf($relation->__getRealEntity(), $relationMetadata->getTargetEntity());
             $relationId = $relation->__getRelationId();
         } else {
             Assertion::isInstanceOf($relation, $relationMetadata->getTargetEntity());
             $relationId = $this->getProperty(new ReflectionClass($relation), $relation, $relationMetadata->getTargetPropertyName());
         }
         $data[$relationMetadata->getFieldName()] = $relationId;
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function check(ClientInterface $client, array $registration_parameters)
 {
     if (!array_key_exists('request_uris', $registration_parameters)) {
         return;
     }
     Assertion::isArray($registration_parameters['request_uris'], 'The parameter "request_uris" must be a list of URI.');
     Assertion::allUrl($registration_parameters['request_uris'], 'The parameter "request_uris" must be a list of URI.');
     $client->set('request_uris', $registration_parameters['request_uris']);
 }
Ejemplo n.º 9
0
 /**
  * Create a new immutable Body instance
  *
  * @param string $route
  * @param string $signature
  * @param array $data
  * @return void
  */
 public function __construct($route, $signature, $data)
 {
     Assertion::url($route);
     Assertion::string($signature);
     Assertion::isArray($data);
     $this->route = $route;
     $this->signature = $signature;
     $this->data = $data;
 }
Ejemplo n.º 10
0
 /**
  * @param string $uri
  *
  * @throws \InvalidArgumentException
  *
  * @return \OTPHP\TOTP|\OTPHP\HOTP
  */
 public static function loadFromProvisioningUri($uri)
 {
     $parsed_url = parse_url($uri);
     Assertion::isArray($parsed_url, 'Not a valid OTP provisioning URI');
     self::checkData($parsed_url);
     $otp = self::createOTP($parsed_url);
     self::populateOTP($otp, $parsed_url);
     return $otp;
 }
Ejemplo n.º 11
0
 /**
  * @param array $taskData
  * @return static
  */
 public static function reconstituteFromArray(array $taskData)
 {
     Assertion::keyExists($taskData, 'target');
     Assertion::keyExists($taskData, 'allowed_types');
     Assertion::keyExists($taskData, 'preferred_type');
     Assertion::keyExists($taskData, 'metadata');
     Assertion::isArray($taskData['allowed_types']);
     return new self($taskData['target'], $taskData['allowed_types'], $taskData['preferred_type'], $taskData['metadata']);
 }
Ejemplo n.º 12
0
 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::string($this->parent_attribute_name);
     Assertion::string($this->embedded_entity_type);
     Assertion::uuid($this->embedded_entity_identifier);
     Assertion::isArray($this->embedded_entity_events);
     Assertion::isArray($this->data);
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function checkHeader(array $protected_headers, array $headers, array $checked_claims)
 {
     if (!array_key_exists('crit', $protected_headers)) {
         return;
     }
     Assertion::isArray($protected_headers['crit'], 'The parameter "crit" must be a list.');
     $diff = array_diff($protected_headers['crit'], $checked_claims);
     Assertion::true(empty($diff), sprintf('One or more claims are marked as critical, but they are missing or have not been checked (%s).', json_encode(array_values($diff))));
 }
Ejemplo n.º 14
0
 public function unbind($value) : Data
 {
     Assertion::isArray($value);
     $data = Data::none();
     foreach ($value as $index => $individualValue) {
         $data = $data->merge($this->wrappedMapping->withPrefixAndRelativeKey($this->key, (string) $index)->unbind($individualValue));
     }
     return $data;
 }
Ejemplo n.º 15
0
 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::isArray($this->data);
     $mandatory_attribute_names = ['identifier', 'uuid', 'language', 'version', 'workflow_state'];
     foreach ($mandatory_attribute_names as $attribute_name) {
         Assertion::keyExists($this->data, $attribute_name, 'mandatory');
     }
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function identify($subject)
 {
     Assertion::isArray($subject);
     Assertion::notEmptyKey($subject, 'username');
     if (!in_array($subject['username'], $this->userKeys)) {
         throw new IdentificationFailed('User not found');
     }
     $id = array_search($subject['username'], $this->userKeys);
     return new User($id, $this->users[$id]);
 }
Ejemplo n.º 17
0
 public function __construct($name, $slug)
 {
     Assertion::string($name);
     Assertion::isArray($slug);
     $this->setName($name);
     $this->setSlug($slug);
     $this->setCreatedAt(new DateTime());
     $this->setUpdatedAt(new DateTime());
     $this->roles = new ArrayCollection();
     $this->users = new ArrayCollection();
 }
 /**
  * @param string $workflowId
  * @param array $startMessage
  * @param string $firstMessageHandlerId
  * @return ScheduleFirstTasksForWorkflow
  */
 public static function withData($workflowId, $startMessage, $firstMessageHandlerId)
 {
     Assertion::uuid($workflowId);
     Assertion::uuid($firstMessageHandlerId);
     Assertion::isArray($startMessage);
     Assertion::keyExists($startMessage, 'message_type');
     Assertion::keyExists($startMessage, 'processing_type');
     $processingType = $startMessage['processing_type'];
     Assertion::implementsInterface($processingType, Type::class);
     return new self(__CLASS__, ['workflow_id' => $workflowId, 'start_message' => $startMessage, 'first_message_handler' => $firstMessageHandlerId]);
 }
Ejemplo n.º 19
0
 /**
  * @param array $taskListArr
  * @return TaskList
  */
 public static function fromArray(array $taskListArr)
 {
     Assertion::keyExists($taskListArr, 'taskListId');
     Assertion::keyExists($taskListArr, 'entries');
     Assertion::isArray($taskListArr['entries']);
     $taskListId = TaskListId::fromString($taskListArr['taskListId']);
     $entries = [];
     foreach ($taskListArr['entries'] as $entryArr) {
         $entries[] = TaskListEntry::fromArray($entryArr);
     }
     return self::fromTaskListEntries($taskListId, $entries);
 }
 /**
  * Retrieves exchange rates from http://fixer.io
  *
  * @param Currency $currency
  */
 private function retrieveExchangeRateFor(Currency $currency)
 {
     $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/latest', ['query' => ['base' => $this->baseCurrency->getName()]]);
     Assert::same($response->getStatusCode(), 200);
     $rawExchangeRates = $response->getBody();
     $exchangeRates = json_decode($rawExchangeRates, true);
     Assert::isArray($exchangeRates);
     Assert::keyExists($exchangeRates, 'rates');
     Assert::keyExists($exchangeRates['rates'], $currency->getName());
     Assert::numeric($exchangeRates['rates'][$currency->getName()]);
     $this->exchangeRates[$currency->getName()] = $exchangeRates['rates'][$currency->getName()];
 }
Ejemplo n.º 21
0
 /**
  * @param string $uri    The URI
  * @param array  $params Parameters added to the URI
  *
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 public static function buildURI($uri, $params = [])
 {
     $parse_url = parse_url($uri);
     Assertion::isArray($parse_url, 'The argument is not a valid URI.');
     foreach ($params as $k => $v) {
         if (isset($parse_url[$k])) {
             $parse_url[$k] .= '&' . http_build_query($v);
         } else {
             $parse_url[$k] = http_build_query($v);
         }
     }
     return self::buildScheme($parse_url) . self::buildUserAuthentication($parse_url) . self::buildHost($parse_url) . self::buildPort($parse_url) . self::buildPath($parse_url) . self::buildQuery($parse_url) . self::buildFragment($parse_url);
 }
 /**
  * Retrieves exchange rates from http://free.currencyconverterapi.com
  *
  * @param Currency $currency
  */
 private function retrieveExchangeRateFor(Currency $currency)
 {
     $conversion = sprintf('%s_%s', $currency->getName(), $this->baseCurrency->getName());
     $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/api/v3/convert', ['query' => ['q' => $conversion]]);
     Assert::same($response->getStatusCode(), 200);
     $rawExchangeRates = $response->getBody();
     $exchangeRates = json_decode($rawExchangeRates, true);
     Assert::isArray($exchangeRates);
     Assert::keyExists($exchangeRates, 'results');
     Assert::keyExists($exchangeRates['results'], $conversion);
     Assert::keyExists($exchangeRates['results'][$conversion], 'val');
     Assert::numeric($exchangeRates['results'][$conversion]['val']);
     $this->exchangeRates[$currency->getName()] = (double) $exchangeRates['results'][$conversion]['val'];
 }
Ejemplo n.º 23
0
 public function scrollStart($query, $cursor = null)
 {
     Assertion::isArray($query);
     $query['index'] = $this->getIndex();
     $query['type'] = $this->getType();
     $query['scroll'] = $this->config->get('scroll_timeout', '1m');
     $query['sort'] = ['_doc'];
     if ($this->config->get('log_scroll_query', false) === true) {
         $this->logger->debug('[' . __METHOD__ . '] scroll start = ' . json_encode($query, JSON_PRETTY_PRINT));
     }
     // Elasticsearch returns results on scroll start
     $raw_result = $this->connector->getConnection()->search($query);
     return new FinderResult($this->mapResultData($raw_result), $raw_result['hits']['total'], 0, $raw_result['_scroll_id']);
 }
Ejemplo n.º 24
0
 /**
  * @return \Jose\Object\JWKInterface[]
  */
 public function getKeys()
 {
     $content = json_decode($this->getContent(), true);
     Assertion::isArray($content, 'Invalid content.');
     $jwkset = new JWKSet();
     foreach ($content as $kid => $cert) {
         $jwk = KeyConverter::loadKeyFromCertificate($cert);
         Assertion::notEmpty($jwk, 'Invalid content.');
         if (is_string($kid)) {
             $jwk['kid'] = $kid;
         }
         $jwkset->addKey(new JWK($jwk));
     }
     return $jwkset->getKeys();
 }
Ejemplo n.º 25
0
 /**
  * Submit constructor.
  * @param array $url
  * @param string $label
  * @param string $method
  * @param array $configurableOptions
  */
 public function __construct($url, $label = 'Submit', $method = 'post', array $configurableOptions = [])
 {
     Assertion::string($method);
     $configurableOptions['url'] = $url;
     $configurableOptions['label'] = $label;
     $configurableOptions['method'] = $method;
     $this->configurableOptions[] = 'hiddenFields';
     if (array_key_exists('hiddenFields', $configurableOptions)) {
         Assertion::isArray($configurableOptions['hiddenFields']);
     }
     parent::__construct($configurableOptions);
     // add csrf token ?
     if (function_exists('csrf_token')) {
         $this->hiddenFields['_token'] = csrf_token();
     }
 }
Ejemplo n.º 26
0
 /**
  * Constructor.
  *
  * @param bool $verified
  * @param \DateTimeImmutable|null $createdAt
  * @param Photo\Photo $bestPhoto
  * @param float|null $rating
  * @param string|null $url
  * @param int|null $hereNow
  * @param string[] $tags
  * @param int|null $likes
  * @param \DateTimeZone|null $timeZone
  */
 public function __construct($verified, \DateTimeImmutable $createdAt = null, Photo\Photo $bestPhoto = null, $rating = null, $url = null, $hereNow = null, $tags = [], $likes = null, \DateTimeZone $timeZone = null)
 {
     Assertion::boolean($verified);
     Assertion::isArray($tags);
     Assertion::nullOrInteger($likes);
     Assertion::nullOrFloat($rating);
     Assertion::nullOrString($url);
     Assertion::nullOrInteger($hereNow);
     $this->verified = $verified;
     $this->rating = $rating;
     $this->hereNow = $hereNow;
     $this->url = $url;
     $this->createdAt = $createdAt;
     $this->timeZone = $timeZone;
     $this->bestPhoto = $bestPhoto;
     $this->tags = $tags;
     $this->likes = $likes;
 }
Ejemplo n.º 27
0
 /**
  * create an array of tokens to be used in various column functions. if the
  * data passed is an object, it will first see if the object has a method called
  * isArray() to create an array from the object, otherwise it will cast the object
  * to an array and hope for the best
  * @param $data
  */
 public function createTokens($data)
 {
     if (isset($this->tokens)) {
         return $this->tokens;
     }
     if (is_object($data) && method_exists($data, 'toArray')) {
         $data = $data->toArray();
     }
     Assertion::isArray($data);
     // drop any object members.
     $data = array_filter($data, function ($v) {
         return !is_object($v);
     });
     // allow for tokens to access multi-dimensional arrays via dot syntax
     $data = array_dot($data);
     foreach ($data as $key => $value) {
         $this->tokens['{' . $key . '}'] = $value;
     }
 }
 /**
  * @param \OAuth2\Client\ClientInterface $client
  * @param array                          $registration_parameters
  */
 private function checkResponseTypes(ClientInterface $client, array $registration_parameters)
 {
     Assertion::isArray($registration_parameters['response_types'], 'The parameter "response_types" must be an array of strings.');
     Assertion::allString($registration_parameters['response_types'], 'The parameter "grant_types" must be an array of strings.');
     foreach ($registration_parameters['response_types'] as $response_type) {
         $types = $this->getResponseTypeManager()->getResponseTypes($response_type);
         if (!in_array($response_type, $client->get('response_types'))) {
             $response_types = $client->get('response_types');
             $response_types[] = $response_type;
             $client->set('response_types', $response_types);
         }
         foreach ($types as $type) {
             $associated_grant_types = $type->getAssociatedGrantTypes();
             $diff = array_diff($associated_grant_types, $registration_parameters['grant_types']);
             Assertion::true(empty($diff), sprintf('The response type "%s" is associated with the grant types "%s" but this response type is missing.', $type->getResponseType(), json_encode($diff)));
             $client->set('grant_types', array_unique(array_merge($client->get('grant_types'), $associated_grant_types)));
         }
     }
 }
Ejemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public static function createFromResponse(ResponseInterface $response)
 {
     $content = $response->getBody()->getContents();
     $json = json_decode($content, true);
     Assertion::isArray($json, 'The response is not a valid OAuth2 Response.');
     if (array_key_exists('error', $json)) {
         $class = Error::class;
     } elseif (array_key_exists('access_token', $json)) {
         $class = AccessToken::class;
     } else {
         throw new \InvalidArgumentException('Unsupported response.');
     }
     /**
      * @var self
      */
     $object = new $class();
     $object->values = $json;
     return $object;
 }
 /**
  * @param array $data
  *
  * @internal param GitLabDto $hydratedObject
  *
  * @return OAuthDto
  * @throws \Assert\AssertionFailedException
  */
 protected function getAuthFromData(array $data)
 {
     Assertion::keyExists($data, 'auth');
     Assertion::keyExists($data, 'authData');
     Assertion::isArray($data['authData']);
     $authUuid = $data['auth'];
     unset($data['auth']);
     $auth = null;
     foreach ($data['authData'] as $authDataItem) {
         Assertion::isInstanceOf($authDataItem, OAuthDto::class);
         /** @var OAuthDto  $authDataItem*/
         if ($authUuid === $authDataItem->getId()) {
             $auth = $authDataItem;
             break;
         }
     }
     Assertion::isInstanceOf($auth, OAuthDto::class);
     return $auth;
 }