/**
  * @param int|null $id
  *
  * @return UnfinishedUserRightSpec
  */
 private static function withId($id)
 {
     Assertion::nullOrInteger($id);
     if ($id === null) {
         return self::hasUnauthorizedUser();
     } else {
         return new UnfinishedUserRightSpec(new ByIdUserSpec($id));
     }
 }
Exemplo n.º 2
0
 /**
  * If no timestamp is provided, the OTP is verified at the actual timestamp
  * {@inheritdoc}
  */
 public function verify($otp, $timestamp = null, $window = null)
 {
     Assertion::string($otp, 'The OTP must be a string');
     Assertion::nullOrInteger($timestamp, 'The timestamp must be null or an integer');
     Assertion::nullOrInteger($window, 'The window parameter must be null or an integer');
     $timestamp = $this->getTimestamp($timestamp);
     if (null === $window) {
         return $this->compareOTP($this->at($timestamp), $otp);
     }
     return $this->verifyOtpWithWindow($otp, $timestamp, $window);
 }
Exemplo n.º 3
0
 /**
  * If the counter is not provided, the OTP is verified at the actual counter.
  *
  * {@inheritdoc}
  */
 public function verify($otp, $counter = null, $window = null)
 {
     Assertion::string($otp, 'The OTP must be a string');
     Assertion::nullOrInteger($counter, 'The counter must be null or an integer');
     Assertion::greaterOrEqualThan($counter, 0, 'The counter must be at least 0.');
     Assertion::nullOrInteger($window, 'The window parameter must be null or an integer');
     if (null === $counter) {
         $counter = $this->getCounter();
     } elseif ($counter < $this->getCounter()) {
         return false;
     }
     return $this->verifyOtpWithWindow($otp, $counter, $window);
 }
 /**
  * Create a Config.
  *
  * @param string $sender Sender code to use.
  * @param string $wsdl WSDL file to use (local path or URL), null means default depending on the debug mode.
  * @param int $timeoutSec (Optional) Timeout in seconds, null means no timeout.
  * @param string $operatingMode (Optional) Operating mode, default is "P" for production. "D" = Development, "T" = Test.
  * @param array $soapClientOptions (Optional) Options for SoapClient.
  * @param string $receiver (Optional) Receiver code to use, default: YELLOWCUBE.
  */
 function __construct($sender, $wsdl = null, $timeoutSec = null, $operatingMode = 'P', array $soapClientOptions = array(), $receiver = 'YELLOWCUBE')
 {
     Assertion::notEmpty($sender, 'Sender must be set.');
     Assertion::nullOrNotEmpty($wsdl, 'WSDL must be set.');
     Assertion::nullOrInteger($timeoutSec, 'Timeout must be null or an integer in seconds.');
     Assertion::choice($operatingMode, array('T', 'D', 'P'), 'Operating mode must be "T", "D" or "P".');
     Assertion::notEmpty($receiver, 'Receiver must be set.');
     $this->sender = $sender;
     $this->wsdl = $wsdl;
     $this->timeoutSec = $timeoutSec;
     $this->operatingMode = $operatingMode;
     $this->soapClientOptions = $soapClientOptions;
     $this->receiver = $receiver;
 }
Exemplo n.º 5
0
 /**
  * @param int|null $userId
  * @param int $rightId
  * @param null|string $forObjectGroup
  * @param null|string $withId
  */
 public function __construct($userId, $rightId, $forObjectGroup, $withId)
 {
     Assertion::nullOrInteger($userId);
     Assertion::integer($rightId);
     Assertion::nullOrString($forObjectGroup);
     //If there is no object group, there can not be an id
     if ($forObjectGroup === null) {
         Assertion::same($withId, null);
     } else {
         Assertion::nullOrString($withId);
     }
     $this->userId = $userId;
     $this->rightId = $rightId;
     $this->forObjectGroup = $forObjectGroup;
     $this->withId = $withId;
 }
Exemplo n.º 6
0
 /**
  * Constructor.
  *
  * @param bool $verified
  * @param \DateTimeImmutable|null $createdAt
  * @param Photo\Photo $bestPhoto
  * @param float|null $rating
  * @param string|null $url
  * @param int|null $hereNow
  * @param string[] $tags
  * @param int|null $likes
  * @param \DateTimeZone|null $timeZone
  */
 public function __construct($verified, \DateTimeImmutable $createdAt = null, Photo\Photo $bestPhoto = null, $rating = null, $url = null, $hereNow = null, $tags = [], $likes = null, \DateTimeZone $timeZone = null)
 {
     Assertion::boolean($verified);
     Assertion::isArray($tags);
     Assertion::nullOrInteger($likes);
     Assertion::nullOrFloat($rating);
     Assertion::nullOrString($url);
     Assertion::nullOrInteger($hereNow);
     $this->verified = $verified;
     $this->rating = $rating;
     $this->hereNow = $hereNow;
     $this->url = $url;
     $this->createdAt = $createdAt;
     $this->timeZone = $timeZone;
     $this->bestPhoto = $bestPhoto;
     $this->tags = $tags;
     $this->likes = $likes;
 }
 public function existsUserRight($userId, $rightId, $forObject, $withId)
 {
     Assertion::nullOrInteger($userId);
     Assertion::integer($rightId);
     Assertion::nullOrString($forObject);
     //If there is no forObject, there can not be an withId
     if ($forObject === null) {
         Assertion::same($withId, null);
     } else {
         Assertion::nullOrString($withId);
     }
     if ($userId !== null && !$this->userService->existsUserById($userId)) {
         throw new UserDoesNotExistException();
     }
     if (!$this->rightService->existsRightById($rightId)) {
         throw new RightNotFoundException();
     }
     return $this->getORMUserRight($userId, $rightId, $forObject, $withId) !== null;
 }
Exemplo n.º 8
0
 /**
  * Removes old project revision directories.
  *
  * @param Project $project Project instance
  * @param int     $copies  Amount of copies to keep
  *
  * @return int Amount of deleted directories
  */
 public function cleanup(Project $project, $copies = null)
 {
     Assertion::nullOrInteger($copies);
     Assertion::nullOrMin($copies, 1);
     if (is_null($copies)) {
         $copies = $this->copies;
     }
     $projectDirectory = sprintf('%s/%s', $this->baseDirectory, $project->getName());
     $finder = new Finder();
     $finder->directories()->in($projectDirectory)->sort($this->getSortByDateAscClosure());
     $directories = iterator_to_array($finder);
     // calculate amount of directories to delete
     $length = count($directories) - $copies;
     if ($length < 0) {
         $length = 0;
     }
     // extract directories to delete
     $directories = array_slice($directories, 0, $length);
     $fs = new Filesystem();
     $fs->remove($directories);
     $removedDirectoriesCount = count($directories);
     $this->logger->debug(sprintf("Removing %s old copies in working directory.", $removedDirectoriesCount));
     return $removedDirectoriesCount;
 }