/** * {@inheritdoc} */ public function startConversation(PersonInterface $sender, $recipient, $body, $subject = null) { if (!is_array($recipient) && !$recipient instanceof \Traversable) { $recipient = [$recipient]; } Assert::allIsInstanceOf($recipient, 'FOS\\Message\\Model\\PersonInterface', '$recipient expected ether an instance or a collection of PersonInterface in Sender::startConversation().'); Assert::string($body, '$body expected a string in Sender::startConversation(). Got: %s'); Assert::nullOrString($subject, '$subject expected either a string or null in Sender::startConversation(). Got: %s'); // Create conversation and message $conversation = $this->createAndPersistConversation($subject); $message = $this->createAndPersistMessage($conversation, $sender, $body); // Add the recipients links foreach ($recipient as $person) { $this->createAndPersistConversationPerson($conversation, $person); $this->createAndPersistMessagePerson($message, $person, false); } // Add the sender link $this->createAndPersistConversationPerson($conversation, $sender); $this->createAndPersistMessagePerson($message, $sender, true); // Flush the previously persisted entities $this->driver->flush(); // Dispatch the event $this->dispatchConversationEvent($conversation, $message); return $conversation; }
private function doPut($token, $payload, $user = null) { Assert::string($token, "Token must be a string. Got: %s"); Assert::string($payload, "Payload must be a string. Got: %s"); Assert::nullOrString($user, "User must be a string or null. Got: %s"); $path = $this->docroot . "/.well-known/acme-challenge"; $realpath = realpath($path); if (!realpath($this->docroot)) { throw new ChallengeStoreException("Document root doesn't exist: '{$this->docroot}'"); } if (!$realpath && !@mkdir($path, 0755, true)) { throw new ChallengeStoreException("Couldn't create public directory to serve the challenges: '{$path}'"); } if ($user) { if (!($userInfo = posix_getpwnam($user))) { throw new ChallengeStoreException("Unknown user: '******'"); } } if (isset($userInfo)) { (yield \Amp\File\chown($this->docroot . "/.well-known", $userInfo["uid"], -1)); (yield \Amp\File\chown($this->docroot . "/.well-known/acme-challenge", $userInfo["uid"], -1)); } (yield \Amp\File\put("{$path}/{$token}", $payload)); if (isset($userInfo)) { (yield \Amp\File\chown("{$path}/{$token}", $userInfo["uid"], -1)); } (yield \Amp\File\chmod("{$path}/{$token}", 0644)); }
/** * @return static */ public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null) { Assert::nullOrString($body); if (empty($body)) { return new static(); } $matches = []; if (!preg_match('/^(' . self::REGEX_VECTOR . ')\\s*(.+)?$/sux', $body, $matches)) { return null; } return new static($matches[1], $descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context)); }
/** * Creates a new option. * * @param string $longName The long option name. * @param string|null $shortName The short option name. * @param int $flags A bitwise combination of the option flag * constants. * @param string $description A human-readable description of the option. * * @throws InvalidValueException If the default value is invalid. */ public function __construct($longName, $shortName = null, $flags = 0, $description = null) { $longName = $this->removeDoubleDashPrefix($longName); $shortName = $this->removeDashPrefix($shortName); Assert::nullOrString($description, 'The option description must be a string or null. Got: %s'); Assert::nullOrNotEmpty($description, 'The option description must not be empty.'); $this->assertFlagsValid($flags); $this->assertLongNameValid($longName); $this->assertShortNameValid($shortName, $flags); $this->longName = $longName; $this->shortName = $shortName; $this->description = $description; $this->addDefaultFlags($flags); $this->flags = $flags; }
/** * @param Certificate $source * @param string $subject * @param string $issuer * @param bool $selfSigned * @param \DateTime $validFrom * @param \DateTime $validTo * @param string $serialNumber * @param array $subjectAlternativeNames */ public function __construct(Certificate $source, $subject, $issuer = null, $selfSigned = true, \DateTime $validFrom = null, \DateTime $validTo = null, $serialNumber = null, array $subjectAlternativeNames = []) { Assert::stringNotEmpty($subject, __CLASS__ . '::$subject expected a non empty string. Got: %s'); Assert::nullOrString($issuer, __CLASS__ . '::$issuer expected a string or null. Got: %s'); Assert::nullOrBoolean($selfSigned, __CLASS__ . '::$selfSigned expected a boolean or null. Got: %s'); Assert::nullOrString($serialNumber, __CLASS__ . '::$serialNumber expected a string or null. Got: %s'); Assert::allStringNotEmpty($subjectAlternativeNames, __CLASS__ . '::$subjectAlternativeNames expected a array of non empty string. Got: %s'); $this->source = $source; $this->subject = $subject; $this->issuer = $issuer; $this->selfSigned = $selfSigned; $this->validFrom = $validFrom; $this->validTo = $validTo; $this->serialNumber = $serialNumber; $this->subjectAlternativeNames = $subjectAlternativeNames; }
/** * @param string $commonName * @param string $countryName * @param string $stateOrProvinceName * @param string $localityName * @param string $organizationName * @param string $organizationalUnitName * @param string $emailAddress * @param array $subjectAlternativeNames */ public function __construct($commonName, $countryName = null, $stateOrProvinceName = null, $localityName = null, $organizationName = null, $organizationalUnitName = null, $emailAddress = null, array $subjectAlternativeNames = []) { Assert::stringNotEmpty($commonName, __CLASS__ . '::$commonName expected a non empty string. Got: %s'); Assert::nullOrString($countryName, __CLASS__ . '::$countryName expected a string. Got: %s'); Assert::nullOrString($stateOrProvinceName, __CLASS__ . '::$stateOrProvinceName expected a string. Got: %s'); Assert::nullOrString($localityName, __CLASS__ . '::$localityName expected a string. Got: %s'); Assert::nullOrString($organizationName, __CLASS__ . '::$organizationName expected a string. Got: %s'); Assert::nullOrString($organizationalUnitName, __CLASS__ . '::$organizationalUnitName expected a string. Got: %s'); Assert::nullOrString($emailAddress, __CLASS__ . '::$emailAddress expected a string. Got: %s'); Assert::allStringNotEmpty($subjectAlternativeNames, __CLASS__ . '::$subjectAlternativeNames expected an array of non empty string. Got: %s'); $this->commonName = $commonName; $this->countryName = $countryName; $this->stateOrProvinceName = $stateOrProvinceName; $this->localityName = $localityName; $this->organizationName = $organizationName; $this->organizationalUnitName = $organizationalUnitName; $this->emailAddress = $emailAddress; $this->subjectAlternativeNames = array_diff(array_unique($subjectAlternativeNames), [$commonName]); }
/** * {@inheritdoc} */ public function registerAccount($agreement = null, $email = null) { Assert::nullOrString($agreement, 'registerAccount::$agreement expected a string or null. Got: %s'); Assert::nullOrString($email, 'registerAccount::$email expected a string or null. Got: %s'); $payload = []; $payload['resource'] = ResourcesDirectory::NEW_REGISTRATION; $payload['agreement'] = $agreement; if (is_string($email)) { $payload['contact'] = ['mailto:' . $email]; } $response = (array) $this->requestResource('POST', ResourcesDirectory::NEW_REGISTRATION, $payload); $links = $this->httpClient->getLastLinks(); foreach ($links as $link) { if ('terms-of-service' === $link['rel']) { $agreement = substr($link[0], 1, -1); $payload = []; $payload['resource'] = ResourcesDirectory::REGISTRATION; $payload['agreement'] = $agreement; $this->httpClient->signedRequest('POST', $this->httpClient->getLastLocation(), $payload, true); break; } } return $response; }
/** * @param null|string $subject */ public function setSubject($subject) { \Webmozart\Assert\Assert::nullOrString($subject); $this->subject = $subject; }
/** * Returns the file name without the extension from a file path. * * @param string $path The path string. * @param string|null $extension If specified, only that extension is cut * off (may contain leading dot). * * @return string The file name without extension. * * @since 1.1 Added method. * @since 2.0 Method now fails if $path or $extension have invalid types. */ public static function getFilenameWithoutExtension($path, $extension = null) { if ('' === $path) { return ''; } Assert::string($path, 'The path must be a string. Got: %s'); Assert::nullOrString($extension, 'The extension must be a string or null. Got: %s'); if (null !== $extension) { // remove extension and trailing dot return rtrim(basename($path, $extension), '.'); } return pathinfo($path, PATHINFO_FILENAME); }
/** * Creates a new argument. * * @param string $name The argument name * @param int $flags A bitwise combination of the flag constants. * @param string $description A human-readable description of the argument. * @param mixed $defaultValue The default value of the argument (must be * null for the flag {@link self::REQUIRED}). */ public function __construct($name, $flags = 0, $description = null, $defaultValue = null) { Assert::string($name, 'The argument name must be a string. Got: %s'); Assert::notEmpty($name, 'The argument name must not be empty.'); Assert::startsWithLetter($name, 'The argument name must start with a letter.'); Assert::regex($name, '~^[a-zA-Z0-9\\-]+$~', 'The argument name must contain letters, digits and hyphens only.'); Assert::nullOrString($description, 'The argument description must be a string or null. Got: %s'); Assert::nullOrNotEmpty($description, 'The argument description must not be empty.'); $this->assertFlagsValid($flags); $this->addDefaultFlags($flags); $this->name = $name; $this->flags = $flags; $this->description = $description; $this->defaultValue = $this->isMultiValued() ? array() : null; if ($this->isOptional() || null !== $defaultValue) { $this->setDefaultValue($defaultValue); } }
/** * Set image * * @param string $image * @return User */ public function setImage($image) { Assert::nullOrString($image); $this->image = $image; return $this; }