keyExists() public static method

Assert that key exists in an array
public static keyExists ( mixed $value, string | integer $key, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$key string | integer
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
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();
 }
 /**
  * {@inheritdoc}
  */
 public function checkerParameter(ClientInterface $client, array &$parameters)
 {
     /*
      * @see http://tools.ietf.org/html/rfc6749#section-3.1.1
      */
     Assertion::keyExists($parameters, 'response_type', 'The parameter "response_type" is mandatory.');
 }
Exemplo n.º 3
0
 /**
  * @param array $array
  * @return Issuer
  */
 public static function fromArray(array $array)
 {
     Guard::keyExists($array, 'id');
     Guard::keyExists($array, 'name');
     Guard::keyExists($array, 'list_type');
     return new Issuer(SwiftBic::fromString($array['id']), Name::fromString($array['name']), ListType::fromString($array['list_type']));
 }
Exemplo n.º 4
0
 /**
  * @param array $taskData
  * @return static
  */
 public static function reconstituteFromArray(array $taskData)
 {
     Assertion::keyExists($taskData, 'target_node_name');
     Assertion::keyExists($taskData, 'process_definition');
     Assertion::keyExists($taskData, 'sync_log_messages');
     return new self(NodeName::fromString($taskData['target_node_name']), $taskData['process_definition'], (bool) $taskData['sync_log_messages']);
 }
 /**
  * @param Request $request
  *
  * @return JsonResponse
  *
  * @throws \Assert\AssertionFailedException
  * @throws InvalidMobileApiException
  * @throws BlankAliasApiException
  * @throws NoTopicsApiException
  * @throws InsufficientBalanceApiException
  * @throws ExistentMobileApiException
  */
 protected function create(Request $request)
 {
     /** @var UsernamePasswordToken $token */
     $token = $this->tokenStorage->getToken();
     $uniqueness = $token->getUsername();
     $data = $request->request->all();
     foreach (array('mobile', 'alias', 'topics') as $key) {
         Assertion::keyExists($data, $key);
     }
     try {
         $this->createSubscriptionApiWorker->create($data['mobile'], $uniqueness, $data['alias'], $data['topics'], $data['resellPackage']);
     } catch (InvalidMobileApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.INVALID_MOBILE'), 400);
     } catch (BlankAliasApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.BLANK_ALIAS'), 400);
     } catch (ExistentMobileApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.EXISTENT_MOBILE'), 400);
     } catch (NoTopicsApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_TOPICS'), 400);
     } catch (NoResellPackageApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.NO_RESELL_PACKAGE'), 400);
     } catch (TrialNotAcceptedApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.SUBSCRIPTION.TRIAL_NOT_ACCEPTED'), 400);
     } catch (InsufficientBalanceApiException $e) {
         return new JsonResponse(array('code' => 'INFO_SMS.PROFILE.INSUFFICIENT_BALANCE'), 400);
     }
     return new JsonResponse();
 }
 /**
  * @param array $serializedObject
  *
  * @return mixed
  *
  * @throws SerializationException
  */
 public function deserialize(array $serializedObject)
 {
     Assert::keyExists($serializedObject, 'type', "Key 'type' should be set.");
     Assert::keyExists($serializedObject, 'payload', "Key 'payload' should be set.");
     // TODO implement TypeDenormalizer
     return $this->denormalizer->denormalize($serializedObject['payload'], $serializedObject['type'], 'json');
 }
Exemplo n.º 7
0
 private function validate()
 {
     Assertion::keyExists($this->options, 'packages');
     Assertion::isArray($this->options['packages']);
     Assertion::keyExists($this->options, 'rooms');
     Assertion::isArray($this->options['rooms']);
 }
Exemplo n.º 8
0
 /**
  * Creates a new domain message from given array
  *
  * @param array $messageData
  * @return static
  */
 public static function fromArray(array $messageData)
 {
     Assertion::keyExists($messageData, 'uuid');
     Assertion::keyExists($messageData, 'message_name');
     Assertion::string($messageData['message_name'], 'message name needs to be string');
     Assertion::notEmpty($messageData['message_name'], 'message name must not be empty');
     Assertion::keyExists($messageData, 'version');
     Assertion::integer($messageData['version'], 'version needs to be an integer');
     Assertion::keyExists($messageData, 'payload');
     Assertion::isArray($messageData['payload'], 'payload needs to be an array');
     Assertion::keyExists($messageData, 'metadata');
     Assertion::keyExists($messageData, 'created_at');
     Assertion::isArray($messageData['metadata'], 'metadata needs to be an array');
     $messageRef = new \ReflectionClass(get_called_class());
     /** @var $message DomainMessage */
     $message = $messageRef->newInstanceWithoutConstructor();
     $message->uuid = Uuid::fromString($messageData['uuid']);
     $message->messageName = $messageData['message_name'];
     $message->version = $messageData['version'];
     $message->setPayload($messageData['payload']);
     $message->metadata = $messageData['metadata'];
     if (!$messageData['created_at'] instanceof \DateTimeInterface) {
         $messageData['created_at'] = \DateTimeImmutable::createFromFormat($message->dateTimeFormat, $messageData['created_at'], new \DateTimeZone('UTC'));
     }
     $message->createdAt = $messageData['created_at'];
     return $message;
 }
Exemplo n.º 9
0
 private function assertConfig(array $config)
 {
     Assertion::keyExists($config, "dbname");
     Assertion::string($config['dbname']);
     Assertion::keyExists($config, "driver");
     Assertion::inArray($config["driver"], $this->supportedDrivers);
 }
 public static function fromArray(array $array)
 {
     Ensure::keyExists($array, 'title');
     Ensure::keyExists($array, 'repositoryName');
     Ensure::keyExists($array, 'url');
     Ensure::keyExists($array, 'loneliness');
     return self::create(Title::fromString($array['title']), RepositoryName::fromString($array['repositoryName']), Url::fromString($array['url']), Loneliness::fromInteger($array['loneliness']));
 }
Exemplo n.º 11
0
 /**
  * @param array $jsonDecodedData
  * @return Payload
  */
 public static function fromJsonDecodedData(array $jsonDecodedData)
 {
     Assertion::keyExists($jsonDecodedData, 'typeClass');
     Assertion::keyExists($jsonDecodedData, 'data');
     Assertion::notEmpty($jsonDecodedData['typeClass']);
     Assertion::string($jsonDecodedData['typeClass']);
     return new static($jsonDecodedData['typeClass'], $jsonDecodedData['data']);
 }
Exemplo n.º 12
0
 public static function fromPersistedState(array $state)
 {
     Assertion::keyExists($state, 'account_id');
     Assertion::keyExists($state, 'email');
     Assertion::keyExists($state, 'password');
     Assertion::keyExists($state, 'salt');
     return new AccountCredentials(new AccountId($state['account_id']), new Credentials(new EmailAddress($state['email']), $state['password'], $state['salt']));
 }
 /**
  * @param $array
  *
  * @return Notification
  */
 public static function fromArray($array)
 {
     Ensure::keyExists($array, 'repositoryName');
     Ensure::keyExists($array, 'title');
     Ensure::keyExists($array, 'url');
     Ensure::keyExists($array, 'eventDateTime');
     return new self(RepositoryName::fromString($array['repositoryName']), Title::fromString($array['title']), Url::fromString($array['url']), new DateTimeImmutable($array['eventDateTime']));
 }
Exemplo n.º 14
0
 /**
  * Create a new Currency
  *
  * @param string $name
  */
 private function __construct($name)
 {
     if (!isset(self::$currencies)) {
         self::$currencies = (require __DIR__ . '/currencies.php');
     }
     Assertion::keyExists(self::$currencies, $name);
     $this->name = $name;
 }
Exemplo n.º 15
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     $data = $request->getParsedBody();
     Assertion::keyExists($data, 'origin');
     Assertion::keyExists($data, 'destination');
     $trackingId = $this->bookingService->bookNewCargo($data['origin'], $data['destination']);
     return new JsonResponse(['trackingId' => $trackingId]);
 }
Exemplo n.º 16
0
 /**
  * @Then I should see the following locales:
  */
 public function iShouldSeeTheFollowingLocales(TableNode $table)
 {
     foreach ($table->getHash() as $row) {
         Assertion::keyExists($this->result, $row['shortcut']);
         Assertion::eq($row['display_name'], $this->result[$row['shortcut']]);
     }
     Assertion::count(iterator_to_array($table), count($this->result));
 }
 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::keyExists($this->data, 'parent_node_id');
     Assertion::string($this->data['parent_node_id']);
     if ($this->data['parent_node_id'] !== '') {
         Assertion::regex($this->data['parent_node_id'], '/[\\w\\.\\-_]{1,128}\\-\\w{8}\\-\\w{4}\\-\\w{4}\\-\\w{4}\\-\\w{12}\\-\\w{2}_\\w{2}\\-\\d+/');
     }
 }
Exemplo n.º 18
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']);
 }
Exemplo n.º 19
0
 /**
  * @param array $data
  */
 private static function checkData(array &$data)
 {
     foreach (['scheme', 'host', 'path', 'query'] as $key) {
         Assertion::keyExists($data, $key, 'Not a valid OTP provisioning URI');
     }
     Assertion::eq('otpauth', $data['scheme'], 'Not a valid OTP provisioning URI');
     parse_str($data['query'], $data['query']);
     Assertion::keyExists($data['query'], 'secret', 'Not a valid OTP provisioning URI');
 }
 /**
  * {@inheritdoc}
  */
 public function check(ClientInterface $client, array $registration_parameters)
 {
     Assertion::keyExists($registration_parameters, 'token_endpoint_auth_method', 'The parameter "token_endpoint_auth_method" is missing.');
     Assertion::string($registration_parameters['token_endpoint_auth_method'], 'The parameter "token_endpoint_auth_method" must be a string.');
     Assertion::true($this->getTokenEndpointAuthMethodManager()->hasTokenEndpointAuthMethod($registration_parameters['token_endpoint_auth_method']), sprintf('The token endpoint authentication method "%s" is not supported. Please use one of the following values: %s', $registration_parameters['token_endpoint_auth_method'], json_encode($this->getTokenEndpointAuthMethodManager()->getSupportedTokenEndpointAuthMethods())));
     $token_endpoint_auth_method = $this->getTokenEndpointAuthMethodManager()->getTokenEndpointAuthMethod($registration_parameters['token_endpoint_auth_method']);
     $token_endpoint_auth_method->checkClientConfiguration($registration_parameters, $client);
     $client->set('token_endpoint_auth_method', $registration_parameters['token_endpoint_auth_method']);
 }
Exemplo n.º 21
0
 /**
  * @Req\Route("/recharge-card/update-package/{id}")
  * @Req\Method({"POST"})
  *
  * @param string $id
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function updateAction($id, Request $request)
 {
     $data = $request->request->all();
     foreach (array('name', 'category', 'amount', 'price') as $key) {
         Assertion::keyExists($data, $key);
     }
     $this->updatePackageApiWorker->update($id, $data['name'], $data['category'], $data['amount'], $data['price']);
     return new JsonResponse($this->collectPackagesApiWorker->collect());
 }
Exemplo n.º 22
0
 /**
  * @Req\Route("/recharge-card/create-category", name="muchacuba.recharge_card.create-category")
  * @Req\Method({"POST"})
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function createAction(Request $request)
 {
     $data = $request->request->all();
     foreach (array('name', 'utility') as $key) {
         Assertion::keyExists($data, $key);
     }
     $this->createCategoryApiWorker->create($data['name'], $data['utility']);
     return new JsonResponse($this->collectCategoriesApiWorker->collect());
 }
Exemplo n.º 23
0
 /**
  * @param string[] $selected_algorithms
  *
  * @return \Jose\Algorithm\JWAInterface[]
  */
 public function getSelectedAlgorithmMethods(array $selected_algorithms)
 {
     $result = [];
     foreach ($selected_algorithms as $algorithm) {
         Assertion::keyExists($this->algorithms, $algorithm, sprintf('The algorithm "%s" is not supported.', $algorithm));
         $result[] = $this->algorithms[$algorithm];
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function deserialize(array $serializedObject)
 {
     Assert::keyExists($serializedObject, 'class', "Key 'class' should be set.");
     Assert::keyExists($serializedObject, 'payload', "Key 'payload' should be set.");
     if (!in_array('Broadway\\Serializer\\SerializableInterface', class_implements($serializedObject['class']))) {
         throw new SerializationException(sprintf('Class \'%s\' does not implement Broadway\\Serializer\\SerializableInterface', $serializedObject['class']));
     }
     return $serializedObject['class']::deserialize($serializedObject['payload']);
 }
Exemplo n.º 25
0
 /**
  * @Req\Route("/info-sms/update-topic/{id}")
  * @Req\Method({"POST"})
  *
  * @param string  $id
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function updateAction($id, Request $request)
 {
     $data = $request->request->all();
     foreach (array('title', 'description', 'average', 'active', 'order') as $key) {
         Assertion::keyExists($data, $key);
     }
     $this->updateTopicApiWorker->update($id, $data['title'], $data['description'], $data['average'], $data['active'], $data['order']);
     return new JsonResponse($this->collectTopicsApiWorker->collect());
 }
Exemplo n.º 26
0
 /**
  * @Req\Route("/recharge-card/lend-cards")
  * @Req\Method({"POST"})
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function lendAction(Request $request)
 {
     $data = $request->request->all();
     foreach (array('uniqueness', 'package') as $key) {
         Assertion::keyExists($data, $key);
     }
     $this->lendCardsApiWorker->lend($data['uniqueness'], $data['package']);
     return new JsonResponse();
 }
 /**
  * {@inheritdoc}
  */
 public function prepend(ContainerBuilder $container)
 {
     $config = current($container->getExtensionConfig('oauth2_server'));
     Assertion::keyExists($config, 'token_endpoint', 'The "TokenEndpointPlugin" must be enabled to use the "ResourceOwnerPasswordCredentialsGrantTypePlugin".');
     if (array_key_exists('token_endpoint', $config)) {
         $config[$this->name()]['user_account_manager'] = $config['token_endpoint']['user_account_manager'];
     }
     $container->prependExtensionConfig('oauth2_server', $config);
 }
Exemplo n.º 28
0
 /**
  * @Req\Route("/info-sms/update-resell-package/{id}")
  * @Req\Method({"POST"})
  *
  * @param string  $id
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function updateAction($id, Request $request)
 {
     $data = $request->request->all();
     foreach (array('amount', 'price') as $key) {
         Assertion::keyExists($data, $key);
     }
     $this->updateResellPackageApiWorker->update($id, (int) $data['amount'], (int) $data['price'], $data['description']);
     return new JsonResponse($this->collectResellPackagesApiWorker->collect());
 }
Exemplo n.º 29
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');
     }
 }
Exemplo n.º 30
0
 /**
  * @param \Symfony\Component\DependencyInjection\Definition       $definition
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  */
 private function addClaimCheckers(Definition $definition, ContainerBuilder $container)
 {
     $taggedClaimCheckerServices = $container->findTaggedServiceIds('jose.checker.claim');
     foreach ($taggedClaimCheckerServices as $id => $tags) {
         foreach ($tags as $attributes) {
             Assertion::keyExists($attributes, 'alias', sprintf("The claim checker '%s' does not have any 'alias' attribute.", $id));
             $definition->addMethodCall('addClaimChecker', [new Reference($id), $attributes['alias']]);
         }
     }
 }