Author: Benjamin Eberlei (kontakt@beberlei.de)
示例#1
0
 /**
  * @param string $name
  */
 protected function setName($name)
 {
     Assertion::string($name);
     Assertion::notBlank($name);
     $this->attributes['name'] = $name;
     $this->name = $name;
 }
 public function __construct($templateId, $id)
 {
     Assertion::notEmpty($templateId);
     Assertion::string($id);
     $this->id = $id;
     $this->templateId = $templateId;
 }
 /**
  * @param int $width
  * @param int $height
  * @param array $shipSizes
  * @return Fields
  */
 public static function generate($width, $height, array $shipSizes)
 {
     Assertion::integer($width);
     Assertion::integer($height);
     Assertion::allInteger($shipSizes);
     $elements = [];
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $elements[] = Field::generate($x, $y);
         }
     }
     $fields = Fields::create($elements);
     foreach ($shipSizes as $shipSize) {
         $attempts = 0;
         while (true) {
             if ($attempts == static::MAX_ATTEMPTS) {
                 throw new CannotPlaceShipOnGridException();
             }
             $direction = mt_rand(0, 1) == 0 ? 'right' : 'below';
             $spot = Coords::create(mt_rand(0, $width - 1), mt_rand(0, $height - 1));
             $endPoint = static::validEndpoint($fields, $spot, $shipSize, $direction);
             if ($endPoint === null) {
                 $attempts++;
                 continue;
             }
             // If we end up here the ship can fit at the determined spot
             $fields->place(Ship::create($spot, $endPoint));
             break;
         }
     }
     return $fields;
 }
示例#4
0
 /**
  * Construct.
  *
  * @param TransitionHandlerFactory $handlerFactory  The transition handler factory.
  * @param StateRepository          $stateRepository The state repository.
  * @param Workflow[]               $workflows       The set of managed workflows.
  */
 public function __construct(TransitionHandlerFactory $handlerFactory, StateRepository $stateRepository, $workflows = array())
 {
     Assertion::allIsInstanceOf($workflows, 'Netzmacht\\Workflow\\Flow\\Workflow');
     $this->workflows = $workflows;
     $this->handlerFactory = $handlerFactory;
     $this->stateRepository = $stateRepository;
 }
示例#5
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();
 }
 /**
  * Create Route.
  *
  * Creates a Route object from an array of comma separated coordinates,
  * e.g. ['52.54628,13.30841', '51.476780,0.000479', ...].
  *
  * @param string[] $arrayOfCommaSeparatedCoordinates
  * @return Route
  */
 public function createRoute($arrayOfCommaSeparatedCoordinates)
 {
     $coordinates = [];
     foreach ($arrayOfCommaSeparatedCoordinates as $item) {
         $valueArray = explode(',', $item);
         if (2 != count($valueArray)) {
             if (!is_null($this->logger)) {
                 $this->logger->error(sprintf('"%s" are not valid coordinates.', $item));
             }
             continue;
         }
         try {
             Assertion::allNumeric($valueArray);
         } catch (AssertionFailedException $e) {
             if (!is_null($this->logger)) {
                 $this->logger->error(sprintf('Given coordinates "%s" are invalid. %s', $item, $e->getMessage()));
                 continue;
             }
         }
         $lat = (double) $valueArray[0];
         $long = (double) $valueArray[1];
         try {
             $coordinate = new Coordinate($lat, $long);
         } catch (\DomainException $e) {
             if (!is_null($this->logger)) {
                 $this->logger->error(sprintf('Given coordinates "%s" are invalid. %s', $item, $e->getMessage()));
             }
             continue;
         }
         $coordinates[] = $coordinate;
     }
     $route = new Route();
     $route->setInputRoute($coordinates);
     return $route;
 }
示例#7
0
文件: Setting.php 项目: kfuchs/cribbb
 /**
  * Create a new Setting
  * 
  * @param NotificationId $id
  * @param User $user
  * @param string $key
  * @return void
  */
 public function __construct(SettingId $id, User $user, $key)
 {
     Assertion::string($key);
     $this->setId($id);
     $this->setUser($user);
     $this->setKey($key);
 }
 /**
  * @param string $value
  */
 private function __construct($value)
 {
     if (!empty($value)) {
         Guard::email($value, 'Email Address is invalid');
     }
     $this->value = $value;
 }
示例#9
0
 /**
  * @param int $id
  *
  * @throws SubjectNotFoundException
  *
  * @return JusticeRecord|false
  */
 public function findById($id)
 {
     Assertion::integer($id);
     $crawler = $this->client->request('GET', sprintf(self::URL_SUBJECTS, $id));
     $detailUrl = $this->extractDetailUrlFromCrawler($crawler);
     if (false === $detailUrl) {
         return false;
     }
     $people = [];
     $crawler = $this->client->request('GET', $detailUrl);
     $crawler->filter('.aunp-content .div-table')->each(function (Crawler $table) use(&$people) {
         $title = $table->filter('.vr-hlavicka')->text();
         try {
             if ('jednatel: ' === $title) {
                 $person = JusticeJednatelPersonParser::parseFromDomCrawler($table);
                 $people[$person->getName()] = $person;
             } elseif ('Společník: ' === $title) {
                 $person = JusticeSpolecnikPersonParser::parseFromDomCrawler($table);
                 $people[$person->getName()] = $person;
             }
         } catch (\Exception $e) {
         }
     });
     return new JusticeRecord($people);
 }
示例#10
0
 /**
  * @param float $minPrice
  * @param float $maxPrice
  */
 public function __construct($minPrice = 0.0, $maxPrice = 0.0)
 {
     Assertion::numeric($minPrice);
     Assertion::numeric($maxPrice);
     $this->minPrice = (double) $minPrice;
     $this->maxPrice = (double) $maxPrice;
 }
 /**
  * AddUserToGroup constructor.
  *
  * @param string $userName
  * @param string $groupId
  */
 public function __construct($userName = '', $groupId = '')
 {
     Assertion::notEmpty($userName, 'Username is a required field to add a user to a group');
     Assertion::notEmpty($groupId, 'Group id is a required field to add a user to a group');
     $this->userName = $userName;
     $this->groupId = $groupId;
 }
示例#12
0
 /**
  * @param string $messageName
  * @return string
  */
 public static function normalize($messageName)
 {
     Assertion::notEmpty($messageName);
     Assertion::string($messageName);
     $search = array(static::MESSAGE_NAME_PREFIX, "-", "\\", "/", " ");
     return strtolower(str_replace($search, "", $messageName));
 }
 /**
  * {@inheritdoc}
  */
 public function checkerParameter(ClientInterface $client, array &$parameters)
 {
     if (false === array_key_exists('response_mode', $parameters)) {
         return;
     }
     Assertion::true($this->isResponseModeParameterInAuthorizationRequestAllowed(), 'The parameter "response_mode" is not allowed.');
 }
示例#14
0
 /**
  * @param \Jose\Object\JWSInterface $jws
  * @param array                     $data
  */
 private static function populatePayload(JWSInterface &$jws, array $data)
 {
     $is_encoded = null;
     foreach ($jws->getSignatures() as $signature) {
         if (null === $is_encoded) {
             $is_encoded = self::isPayloadEncoded($signature);
         }
         Assertion::eq($is_encoded, self::isPayloadEncoded($signature), 'Foreign payload encoding detected. The JWS cannot be loaded.');
     }
     if (array_key_exists('payload', $data)) {
         $payload = $data['payload'];
         $jws = $jws->withAttachedPayload();
         $jws = $jws->withEncodedPayload($payload);
         if (false !== $is_encoded) {
             $payload = Base64Url::decode($payload);
         }
         $json = json_decode($payload, true);
         if (null !== $json && !empty($payload)) {
             $payload = $json;
         }
         $jws = $jws->withPayload($payload);
     } else {
         $jws = $jws->withDetachedPayload();
     }
 }
 private function __construct($repositoryName)
 {
     Ensure::string($repositoryName);
     Ensure::notBlank($repositoryName);
     Ensure::regex($repositoryName, '/^[a-zA-Z0-9\\-]+\\/[a-zA-Z0-9\\-\\.]+$/');
     $this->repositoryName = $repositoryName;
 }
示例#16
0
 /**
  * @param mixed $value
  */
 protected function setValue($value)
 {
     //We use the string assertion first
     parent::setValue($value);
     //and then check, if we really got an item class
     Assertion::implementsInterface($value, 'Prooph\\Processing\\Type\\Type');
 }
示例#17
0
 public static function fromString($uuid)
 {
     Assertion::uuid($uuid);
     $patientId = new static();
     $patientId->id = $uuid;
     return $patientId;
 }
示例#18
0
 /**
  * @param  \stdClass $obj
  * @param  array     $context
  * @return TwitterEvent
  */
 public function unserialize($obj, array $context = [])
 {
     Assertion::true($this->canUnserialize($obj), 'object is not unserializable');
     $createdAt = new \DateTimeImmutable($obj->created_at);
     Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone());
     return TwitterEvent::create($obj->event, $this->userSerializer->unserialize($obj->source), isset($obj->target) ? $this->userSerializer->unserialize($obj->target) : null, isset($obj->target_object) ? $this->targetSerializer->unserialize($obj->target_object) : null, $createdAt);
 }
示例#19
0
 /**
  * @param $name
  */
 public function __construct($name)
 {
     Assertion::string($name, 'StreamName must be a string');
     Assertion::notEmpty($name, 'StreamName must not be empty');
     Assertion::maxLength($name, 200, 'StreamName should not be longer than 200 chars');
     $this->name = $name;
 }
示例#20
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']));
 }
 /**
  * @param string $field
  * @param string $operator
  * @param string|array $value ['min' => 1, 'max' => 10] for between operator
  */
 public function __construct($field, $operator, $value)
 {
     Assertion::string($field);
     $this->field = $field;
     $this->value = $value;
     $this->operator = $operator;
 }
示例#22
0
 /**
  * @param $text
  */
 public function __construct($text)
 {
     Assertion::string($text);
     Assertion::minLength($text, 1);
     Assertion::maxLength($text, 1000);
     $this->text = $text;
 }
示例#23
0
 public function __construct($name, $set)
 {
     Assertion::string($name);
     Assertion::boolean($set);
     $this->name = $name;
     $this->set = $set;
 }
 /**
  * Set the radius in meters.
  *
  * @param int $meters
  *
  * @return self
  */
 public function setRadius($meters)
 {
     Assertion::integer($meters);
     Assertion::range($meters, 1, 100000);
     $this->radius = $meters;
     return $this;
 }
示例#25
0
 /**
  * Initialise text item
  *
  * @param string $breakChar
  * @param int    $lines
  */
 public function __construct($breakChar = ' ', $lines = 1)
 {
     Assertion::string($breakChar);
     Assertion::integer($lines);
     $this->breakChar = $breakChar;
     $this->lines = $lines;
 }
 /**
  * {@inheritdoc}
  */
 public function checkPKCEInput($code_challenge_method, $code_challenge, $code_verifier)
 {
     Assertion::true($this->hasPKCEMethod($code_challenge_method), sprintf('Unsupported code challenge method "%s".', $code_challenge_method));
     $method = $this->getPKCEMethod($code_challenge_method);
     Assertion::notNull($code_verifier, 'The parameter "code_verifier" is required.');
     Assertion::true($method->isChallengeVerified($code_verifier, $code_challenge), 'Invalid parameter "code_verifier".');
 }
 public static function withData($workflowId, $previousTaskId, $nextMessageHandlerId)
 {
     Assertion::uuid($workflowId);
     Assertion::uuid($previousTaskId);
     Assertion::uuid($nextMessageHandlerId);
     return new self(__CLASS__, ['workflow_id' => $workflowId, 'previous_task_id' => $previousTaskId, 'next_message_handler_id' => $nextMessageHandlerId]);
 }
示例#28
0
 /**
  * @param string $text
  * @param CliMenu $subMenu
  * @param bool $disabled
  */
 public function __construct($text, CliMenu $subMenu, $disabled = false)
 {
     Assertion::string($text);
     $this->text = $text;
     $this->subMenu = $subMenu;
     $this->disabled = $disabled;
 }
示例#29
0
 /**
  * Builds an environment.
  *
  * @param string  $name        Name
  * @param array   $environment Environment
  * @param Project $project     Project instance
  *
  * @return Environment
  */
 public function build($name, array $environment, Project $project)
 {
     Assertion::string($name);
     $this->logger->debug(sprintf("Building environment '%s'", $name));
     if (empty($environment)) {
         throw new \DomainException(sprintf("No configuration for environment '%s' given", $name));
     }
     if (!array_key_exists('servers', $environment) || empty($environment['servers'])) {
         throw new \DomainException(sprintf("No servers for environment '%s' given", $name));
     }
     if (!array_key_exists('stages', $environment) || empty($environment['stages'])) {
         throw new \DomainException(sprintf("No stages for environment '%s' given", $name));
     }
     $this->tasks = $project->getTasks();
     $this->logger->debug("Creating environment instance.");
     $options = $environment;
     $environment = new Environment($name);
     if (array_key_exists('config', $options)) {
         $this->logger->debug("Config section given. Hydrating config instance.");
         $environment->getConfig()->merge(new Config($options['config']));
     } else {
         $this->logger->debug("No config section given.");
     }
     foreach ($options['stages'] as $name => $stage) {
         if (!$stage) {
             throw new \DomainException(sprintf("No tasks for stage '%s' in environment '%s' given", $name, $environment->getName()));
         }
         $environment->addStage($this->buildStage($name, $stage));
     }
     $this->logger->debug(sprintf("Resolving task/server mapping."));
     $environment->setMapping($this->mappingResolver->resolve($options, $environment, $project));
     return $environment;
 }
示例#30
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;
 }