/** * @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; }
/** * 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; }
/** * @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); }
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; }
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; }
public function __construct(array $messages = []) { Assertion::classExists(MessageFormatter::class); $this->messages = array_replace(self::BUILD_IN_MESSAGES, $messages); }
public function testValidClass() { Assertion::classExists("\\Exception"); }
/** * @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)); }
/** * @param string $resultClass * @param string $resultRendererClass */ public function addResult($resultClass, $resultRendererClass) { Assertion::classExists($resultClass); Assertion::classExists($resultRendererClass); $this->results[] = ['resultClass' => $resultClass, 'resultRendererClass' => $resultRendererClass]; }
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'); }