isInstanceOf() публичный статический метод

Assert that value is instance of given class-name.
public static isInstanceOf ( mixed $value, string $className, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$className string
$message string | null
$propertyPath string | null
Результат boolean
 /**
  * @param $partId
  * @return \Modules\Parts\ReadModel\PartsThatWereManufactured
  */
 public function getReadModel($partId)
 {
     $partId = (string) $partId;
     $readModel = $this->repository->find($partId);
     Assertion::isInstanceOf($readModel, PartsThatWereManufactured::class);
     return $readModel;
 }
 /**
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return CommonReport
  * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
  * @throws \Assert\AssertionFailedException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;
     /** @var ModuleOptionsPluginManagerInterface $moduleOptionsManager */
     $moduleOptionsManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class);
     Assertion::isInstanceOf($moduleOptionsManager, ModuleOptionsPluginManagerInterface::class, sprintf('Module options manager not implement %s', ModuleOptionsPluginManagerInterface::class));
     /** @var ModuleOptions $moduleOptions */
     $moduleOptions = $moduleOptionsManager->get(ModuleOptions::class);
     Assertion::isInstanceOf($moduleOptions, ModuleOptions::class, sprintf('Module options not implement %s', ModuleOptions::class));
     /** @var GoogleSheetsStorageBuilder $googleSheetsStorageBuilder */
     $googleSheetsStorageBuilder = $appServiceLocator->get(GoogleSheetsStorageBuilder::class);
     Assertion::isInstanceOf($googleSheetsStorageBuilder, GoogleSheetsStorageBuilder::class, sprintf('GoogleSheetsStorageBuilder not implement %s', GoogleSheetsStorageBuilder::class));
     /** @var GitLabDataStorageBuilder $gitLabDataStorageBuilder */
     $gitLabDataStorageBuilder = $appServiceLocator->get(GitLabDataStorageBuilder::class);
     Assertion::isInstanceOf($gitLabDataStorageBuilder, GitLabDataStorageBuilder::class, sprintf('GitLabDataStorageBuilder not implement %s', GitLabDataStorageBuilder::class));
     $report = new CommonReport($googleSheetsStorageBuilder, $gitLabDataStorageBuilder);
     if ($report instanceof LoggerAwareInterface) {
         $loggerName = $moduleOptions->getLogger();
         if (null !== $loggerName) {
             /** @var LoggerInterface  $logger */
             $logger = $appServiceLocator->get($loggerName);
             Assertion::isInstanceOf($logger, LoggerInterface::class, sprintf('Log  not implement %s', LoggerInterface::class));
             $report->setLogger($logger);
         }
     }
     return $report;
 }
Пример #3
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());
 }
 /**
  * @Given /^I have some generated config at "([^"]*)"$/
  */
 public function iHaveSomeGeneratedConfigAt($arg1)
 {
     $this->configFilePath = getcwd() . "/{$arg1}/";
     Assertion::file($this->configFilePath . 'configured.json');
     $this->config = json_decode(file_get_contents($this->configFilePath . 'configured.json'));
     Assertion::isInstanceOf($this->config, 'stdClass');
 }
 /**
  * @param LegDto[] $legs
  */
 public function setLegs(array $legs) : array
 {
     foreach ($legs as $leg) {
         Assertion::isInstanceOf($leg, LegDto::class);
     }
     $this->legs = $legs;
 }
Пример #6
0
 /**
  * FilesCollection constructor.
  *
  * @param File[] $files
  */
 public function __construct(array $files)
 {
     foreach ($files as $file) {
         Assertion::isInstanceOf($file, File::class);
     }
     $this->files = $files;
 }
 /**
  * @param CreateCoupon $createCoupon
  */
 public function validate(DtoInterface $createCoupon)
 {
     Assertion::isInstanceOf($createCoupon, 'Matthias\\LeanpubApi\\Dto\\CreateCoupon');
     if (count($createCoupon->getPackageDiscounts()) === 0) {
         throw new BadRequestException('Coupon should have at least one package discount, one of which can be for the "book" package');
     }
 }
Пример #8
0
 protected function _validateIpnListeners()
 {
     Assertion::notEmpty($this->ipnListeners);
     foreach ($this->ipnListeners as $ipn_listener) {
         Assertion::isInstanceOf($ipn_listener, PaymentListener::class);
     }
 }
Пример #9
0
 public function fromFileMakerValue($value)
 {
     if (null === $value) {
         return null;
     }
     Assertion::isInstanceOf($value, StreamInterface::class);
     return $value;
 }
Пример #10
0
 /**
  * @param TaskListId $taskListId
  * @param TaskListEntry[] $taskListEntries
  */
 private function __construct(TaskListId $taskListId, array $taskListEntries)
 {
     foreach ($taskListEntries as $taskListEntry) {
         Assertion::isInstanceOf($taskListEntry, 'Prooph\\Processing\\Processor\\Task\\TaskListEntry');
     }
     $this->taskListEntries = $taskListEntries;
     $this->taskListId = $taskListId;
 }
Пример #11
0
 public function toFileMakerValue($value)
 {
     if (null === $value) {
         return null;
     }
     Assertion::isInstanceOf($value, Decimal::class);
     return $value;
 }
Пример #12
0
 /**
  * @param Adapter $snapshotAdapter
  */
 public function __construct(Adapter $snapshotAdapter, array $aggregateRepositories)
 {
     foreach ($aggregateRepositories as $aggregateRepository) {
         Assertion::isInstanceOf($aggregateRepository, AggregateRepository::class);
     }
     $this->snapshotAdapter = $snapshotAdapter;
     $this->aggregateRepositories = $aggregateRepositories;
 }
Пример #13
0
 /**
  * @param StreamName $streamName
  * @param Message[] $streamEvents
  */
 public function __construct(StreamName $streamName, array $streamEvents)
 {
     foreach ($streamEvents as $streamEvent) {
         Assertion::isInstanceOf($streamEvent, Message::class);
     }
     $this->streamName = $streamName;
     $this->streamEvents = $streamEvents;
 }
Пример #14
0
 public function fromFileMakerValue($value)
 {
     if (null === $value) {
         return null;
     }
     Assertion::isInstanceOf($value, Decimal::class);
     return $value->asInteger();
 }
 public function delete($identifier, SettingsInterface $settings = null)
 {
     $arguments = $settings->get('arguments');
     Assertion::isInstanceOf($arguments, SettingsInterface::CLASS);
     $exchange = $this->getConfig()->get('exchange');
     $channel = $this->connector->getConnection()->channel();
     $channel->exchange_unbind($exchange, $exchange, $identifier, false, $arguments->toArray());
 }
Пример #16
0
 public function toFileMakerValue($value)
 {
     if (null === $value) {
         return null;
     }
     Assertion::isInstanceOf($value, DateTimeInterface::class);
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function savePreConfiguredAuthorization(BasePreConfiguredAuthorizationInterface $pre_configured_authorization)
 {
     Assertion::isInstanceOf($pre_configured_authorization, CurrentPreConfiguredAuthorizationInterface::class);
     $hash = $this->calculateHash($pre_configured_authorization->getResourceOwnerPublicId(), $pre_configured_authorization->getClientPublicId(), $pre_configured_authorization->getScopes());
     $pre_configured_authorization->setHash($hash);
     $this->getEntityManager()->persist($pre_configured_authorization);
     $this->getEntityManager()->flush();
 }
Пример #18
0
 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::regex($this->aggregate_root_type, '#^([a-z][a-z_-]+(?<![_-])\\.){2}[a-z][a-z_-]+(?<![_-])$#');
     Assertion::integer($this->seq_number);
     Assertion::isInstanceOf($this->embedded_entity_events, EmbeddedEntityEventList::CLASS);
     Assertion::regex($this->aggregate_root_identifier, '/[\\w\\.\\-_]{1,128}\\-\\w{8}\\-\\w{4}\\-\\w{4}\\-\\w{4}\\-\\w{12}\\-\\w{2}_\\w{2}\\-\\d+/');
 }
 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;
 }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 public function unbind(string $key, $value) : Data
 {
     Assertion::isInstanceOf($value, DateTimeInterface::class);
     $dateTime = $value->setTimezone($this->timeZone);
     if ((int) $dateTime->format('u') > 0) {
         return Data::fromFlatArray([$key => $dateTime->format('H:i:s.u')]);
     }
     return Data::fromFlatArray([$key => $dateTime->format('H:i:s')]);
 }
 /**
  * {@inheritDoc}
  */
 public function create($aggregateClass, DomainEventStreamInterface $domainEventStream)
 {
     $methodCall = sprintf('%s::%s', $aggregateClass, $this->staticConstructorMethod);
     Assert::true(method_exists($aggregateClass, $this->staticConstructorMethod), sprintf('NamedConstructorAggregateFactory expected %s to exist', $methodCall));
     $aggregate = call_user_func($methodCall);
     Assert::isInstanceOf($aggregate, $aggregateClass);
     $aggregate->initializeState($domainEventStream);
     return $aggregate;
 }
Пример #22
0
 /**
  * @param string $offset
  * @param TechnicalData $value
  */
 public function offsetSet($offset, $value)
 {
     Assertion::isInstanceOf($value, TechnicalData::class);
     $name = $value->getName();
     if (null !== $offset) {
         Assertion::eq($name, $offset);
     }
     $this->data[$name] = $value;
 }
Пример #23
0
 /**
  * {@inheritDoc}
  */
 public function save(AggregateRoot $aggregate)
 {
     // maybe we can get generics one day.... ;)
     Assert::isInstanceOf($aggregate, $this->aggregateClass);
     $domainEventStream = $aggregate->getUncommittedEvents();
     $eventStream = $this->decorateForWrite($aggregate, $domainEventStream);
     $this->eventStore->append($aggregate->getAggregateRootId(), $eventStream);
     $this->eventBus->publish($eventStream);
 }
 /**
  * @inheritdoc
  *
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return BaseReportRepository
  * @throws \Assert\AssertionFailedException
  * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;
     /** @var ObjectManagerAutoDetectorInterface $objectManagerAutoDetector */
     $objectManagerAutoDetector = $appServiceLocator->get(ObjectManagerAutoDetectorInterface::class);
     $om = $objectManagerAutoDetector->getObjectManagerByClassName(BaseReport::class);
     $rep = $om->getRepository(BaseReport::class);
     Assertion::isInstanceOf($rep, BaseReportRepository::class);
     return $rep;
 }
Пример #25
0
 /**
  * @param string $relatedTypeClass
  * @param Description $descriptionOfType
  * @param PrototypeProperty[] $typeProperties
  */
 public function __construct($relatedTypeClass, Description $descriptionOfType, array $typeProperties)
 {
     Assertion::implementsInterface($relatedTypeClass, 'Prooph\\Processing\\Type\\Type');
     foreach ($typeProperties as $propertyOfType) {
         Assertion::isInstanceOf($propertyOfType, 'Prooph\\Processing\\Type\\PrototypeProperty');
     }
     $this->relatedTypeClass = $relatedTypeClass;
     $this->descriptionOfType = $descriptionOfType;
     $this->typeProperties = $typeProperties;
     PrototypeRegistry::registerPrototype($this);
 }
 public function resolve(Command $command)
 {
     Assertion::string($command->name(), sprintf('%s::name() should return a string', get_class($command)));
     if (!isset($this->commandHandlers[$command->name()])) {
         throw new \InvalidArgumentException(sprintf('No valid handler found for command "%s"', $command->name()));
     }
     $serviceId = $this->commandHandlers[$command->name()];
     $commandHandler = call_user_func($this->serviceLocator, $serviceId);
     Assertion::isInstanceOf($commandHandler, 'Matthias\\SimpleBus\\Command\\Handler\\CommandHandler');
     return $commandHandler;
 }
Пример #27
0
 public function __construct($context, $reference, DateTime $start, Kind $kind)
 {
     Assertion::isInstanceOf($context, 'Bakgat\\Notos\\Domain\\Model\\Identity\\Party');
     Assertion::isInstanceOf($reference, 'Bakgat\\Notos\\Domain\\Model\\Identity\\Party');
     $this->setContext($context);
     $this->setReference($reference);
     $this->setStart($start);
     $this->setKind($kind);
     $this->setCreatedAt(new DateTime());
     $this->setUpdatedAt(new DateTime());
 }
 /**
  * @param string $error             Short name of the error
  * @param string $error_description Description of the error
  * @param array  $error_data        Data to add to the error
  * @param array  $data              Additional data sent to the exception
  */
 public function __construct($error, $error_description, array $error_data, array $data)
 {
     parent::__construct(302, $error, $error_description, $error_data);
     Assertion::keyExists($data, 'redirect_uri', 'redirect_uri_not_defined');
     Assertion::keyExists($data, 'response_mode', 'invalid_response_mode');
     Assertion::isInstanceOf($data['response_mode'], ResponseModeInterface::class, 'invalid_response_mode');
     $this->response_mode = $data['response_mode'];
     $this->redirect_uri = $data['redirect_uri'];
     if (array_key_exists('state', $data) && null !== $data['state']) {
         $this->errorData['state'] = $data['state'];
     }
 }
 /**
  * @inheritdoc
  */
 public function allTrue(array $specs)
 {
     $allTrue = true;
     foreach ($specs as $spec) {
         Assertion::isInstanceOf($spec, UserRightSpecInterface::class);
         if (!$this->isTrue($spec)) {
             $allTrue = false;
             break;
         }
     }
     return $allTrue;
 }
Пример #30
0
 /**
  * @param EventInterface $e
  *
  * @return array|void
  * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
  * @throws \Assert\AssertionFailedException
  */
 public function onBootstrap(EventInterface $e)
 {
     Assertion::isInstanceOf($e, MvcEvent::class);
     /** @var MvcEvent $e */
     $sm = $e->getApplication()->getServiceManager();
     /** @var GoogleClientBuilder $googleClientBuilder */
     $googleClientBuilder = $sm->get(GoogleClientBuilder::class);
     Assertion::isInstanceOf($googleClientBuilder, GoogleClientBuilder::class);
     /** @var AccessTokenFromConsole $accessTokenFromConsole */
     $accessTokenFromConsole = $sm->get(AccessTokenFromConsole::class);
     Assertion::isInstanceOf($accessTokenFromConsole, AccessTokenFromConsole::class);
     $googleClientBuilder->getEventManager()->attachAggregate($accessTokenFromConsole);
 }