本文整理汇总了PHP中Assert\Assertion类的典型用法代码示例。如果您正苦于以下问题:PHP Assertion类的具体用法?PHP Assertion怎么用?PHP Assertion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assertion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setName
/**
* @param string $name
*/
protected function setName($name)
{
Assertion::string($name);
Assertion::notBlank($name);
$this->attributes['name'] = $name;
$this->name = $name;
}
示例2: __construct
public function __construct($templateId, $id)
{
Assertion::notEmpty($templateId);
Assertion::string($id);
$this->id = $id;
$this->templateId = $templateId;
}
示例3: generate
/**
* @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: __construct
/**
* 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: getKeys
/**
* @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();
}
示例6: createRoute
/**
* 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: __construct
/**
* 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);
}
示例8: findById
/**
* @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);
}
示例9: __construct
/**
* @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;
}
示例10: __construct
/**
* 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;
}
示例11: normalize
/**
* @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));
}
示例12: checkerParameter
/**
* {@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.');
}
示例13: populatePayload
/**
* @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();
}
}
示例14: setValue
/**
* @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');
}
示例15: fromString
public static function fromString($uuid)
{
Assertion::uuid($uuid);
$patientId = new static();
$patientId->id = $uuid;
return $patientId;
}