classExists() public static method

Assert that the class exists.
public static classExists ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 /**
  * @param MappingInterface[] $mappings
  */
 public function __construct(array $mappings, string $className, callable $apply = null, callable $unapply = null)
 {
     foreach ($mappings as $mappingKey => $mapping) {
         Assertion::string($mappingKey);
         Assertion::isInstanceOf($mapping, MappingInterface::class);
         $this->mappings[$mappingKey] = $mapping->withPrefixAndRelativeKey($this->key, $mappingKey);
     }
     Assertion::classExists($className);
     if (null === $apply) {
         $apply = function (...$arguments) {
             return new $this->className(...array_values($arguments));
         };
     }
     if (null === $unapply) {
         $unapply = function ($value) {
             Assertion::isInstanceOf($value, $this->className);
             $values = [];
             $reflectionClass = new ReflectionClass($this->className);
             foreach ($reflectionClass->getProperties() as $property) {
                 /* @var $property ReflectionProperty */
                 $property->setAccessible(true);
                 $values[$property->getName()] = $property->getValue($value);
             }
             return $values;
         };
     }
     $this->className = $className;
     $this->apply = $apply;
     $this->unapply = $unapply;
 }
Exemplo n.º 2
0
 /**
  * Get current route parameters in array 
  * @return array (controller,action,parameters and _route)
  */
 function getCurrentRoute()
 {
     $ret = null;
     $inst = null;
     $url = null;
     if ($this->_request->get('url')) {
         $url = $this->_request->get('url');
     }
     $url = '/' . $url;
     $parameters = \Parameters::get('router');
     $classes = "GL\\Core\\Routing\\Router";
     if (isset($parameters["classes"])) {
         $classes = $parameters["classes"];
     }
     try {
         Assertion::classExists($classes);
         $inst = new $classes();
         $ret = $inst->route($url);
         $args = $inst->getArgs();
         $ret = array();
         $ret["controller"] = $inst->getController();
         $ret["action"] = $inst->getMethod();
         $ret["_route"] = $inst->getRoute();
         $ret = array_merge($ret, $args);
     } catch (AssertionFailedException $e) {
         $ret = null();
     }
     return $ret;
 }
 /**
  * {@inheritDoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     Assertion::choicesNotEmpty($data, ['message', 'class', 'timestamp']);
     Assertion::classExists($data['class']);
     $envelope = new Envelope($this->aggregate->denormalize($data['message'], $data['class']));
     $this->forcePropertyValue($envelope, 'class', $data['class']);
     $this->forcePropertyValue($envelope, 'timestamp', $data['timestamp']);
     return $envelope;
 }
Exemplo n.º 4
0
 /**
  * @param int|float|string $step
  * @param int|float|string|null $base
  */
 public function __construct($step, $base = null)
 {
     Assertion::classExists(Decimal::class);
     Assertion::numeric($step);
     $decimalStep = Decimal::fromString((string) $step);
     Assertion::true($decimalStep->comp(DecimalConstants::zero()) > 0);
     thatNullOr($base)->numeric();
     $this->step = $decimalStep;
     $this->base = null === $base ? DecimalConstants::zero() : Decimal::fromString((string) $base);
 }
 /**
  * Supported processing types can be given as processing prototypes or a list of type classes
  *
  * @param Prototype[]|array $processingTypes
  * @return ProcessingTypes
  */
 public static function support(array $processingTypes)
 {
     $prototypes = [];
     foreach ($processingTypes as $typeClassOrPrototype) {
         if ($typeClassOrPrototype instanceof Prototype) {
             $prototypes[] = $typeClassOrPrototype;
         } else {
             Assertion::string($typeClassOrPrototype);
             Assertion::classExists($typeClassOrPrototype);
             Assertion::implementsInterface($typeClassOrPrototype, Type::class);
             $prototypes[] = $typeClassOrPrototype::prototype();
         }
     }
     return new self($prototypes, false);
 }
Exemplo n.º 6
0
 private function getRouterInstance()
 {
     $parameters = \Parameters::get('router');
     $classes = "GL\\Core\\Routing\\Router";
     $inst = null;
     if (isset($parameters["classes"])) {
         $classes = $parameters["classes"];
     }
     try {
         Assertion::classExists($classes);
         $inst = new $classes();
     } catch (AssertionFailedException $e) {
         echo "Routing classes " . $classes . " does not exist";
         die;
     }
     return $inst;
 }
Exemplo n.º 7
0
 private function __construct($target, array $allowedTypes, $preferredType = null, array $metadata)
 {
     Assertion::notEmpty($target);
     Assertion::string($target);
     Assertion::notEmpty($allowedTypes);
     $this->assertMetadata($metadata);
     foreach ($allowedTypes as $allowedType) {
         Assertion::classExists($allowedType);
         Assertion::implementsInterface($allowedType, 'Prooph\\Processing\\Type\\Type');
     }
     if (!is_null($preferredType)) {
         Assertion::inArray($preferredType, $allowedTypes);
     }
     $this->target = $target;
     $this->allowedTypes = $allowedTypes;
     $this->preferredType = $preferredType;
     $this->metadata = $metadata;
 }
Exemplo n.º 8
0
 public function __construct(array $messages = [])
 {
     Assertion::classExists(MessageFormatter::class);
     $this->messages = array_replace(self::BUILD_IN_MESSAGES, $messages);
 }
Exemplo n.º 9
0
 public function testValidClass()
 {
     Assertion::classExists("\\Exception");
 }
Exemplo n.º 10
0
 /**
  * @param int|float|string $limit
  */
 public function __construct($limit)
 {
     Assertion::classExists(Decimal::class);
     Assertion::numeric($limit);
     $this->limit = Decimal::fromString((string) $limit);
 }
 public function __invoke(ContainerInterface $container, $requestedService)
 {
     Assertion::classExists($requestedService);
     return new $requestedService($container->get(BookingService::class));
 }
Exemplo n.º 12
0
 /**
  * @param string $resultClass
  * @param string $resultRendererClass
  */
 public function addResult($resultClass, $resultRendererClass)
 {
     Assertion::classExists($resultClass);
     Assertion::classExists($resultRendererClass);
     $this->results[] = ['resultClass' => $resultClass, 'resultRendererClass' => $resultRendererClass];
 }
Exemplo n.º 13
0
 public function __construct($command_class)
 {
     Assertion::classExists($command_class);
     $this->command_class = $command_class;
     $this->command_state = [];
 }
 /**
  * {@inheritdoc}
  */
 public function validatePlugin($dataMapper)
 {
     Assertion::isInstanceOf($dataMapper, DataMapperInterface::class, 'Invalid data mapper');
     Assertion::classExists($dataMapper->getEntityClass(), 'Invalid entity class');
 }