当前位置: 首页>>代码示例>>PHP>>正文


PHP Assert::nullOrString方法代码示例

本文整理汇总了PHP中Webmozart\Assert\Assert::nullOrString方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::nullOrString方法的具体用法?PHP Assert::nullOrString怎么用?PHP Assert::nullOrString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Webmozart\Assert\Assert的用法示例。


在下文中一共展示了Assert::nullOrString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: startConversation

 /**
  * {@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;
 }
开发者ID:jbinfo,项目名称:FOSMessage,代码行数:28,代码来源:Sender.php

示例2: doPut

 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: '{$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));
 }
开发者ID:kelunik,项目名称:acme-client,代码行数:28,代码来源:ChallengeStore.php

示例3: create

 /**
  * @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));
 }
开发者ID:Ocramius,项目名称:ReflectionDocBlock,代码行数:15,代码来源:Version.php

示例4: __construct

 /**
  * 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;
 }
开发者ID:webmozart,项目名称:console,代码行数:26,代码来源:AbstractOption.php

示例5: __construct

 /**
  * @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;
 }
开发者ID:acmephp,项目名称:acmephp,代码行数:26,代码来源:ParsedCertificate.php

示例6: __construct

 /**
  * @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]);
 }
开发者ID:acmephp,项目名称:acmephp,代码行数:29,代码来源:DistinguishedName.php

示例7: registerAccount

 /**
  * {@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;
 }
开发者ID:acmephp,项目名称:core,代码行数:27,代码来源:AcmeClient.php

示例8: setSubject

 /**
  * @param null|string $subject
  */
 public function setSubject($subject)
 {
     \Webmozart\Assert\Assert::nullOrString($subject);
     $this->subject = $subject;
 }
开发者ID:tgalopin,项目名称:FOSMessage-demo,代码行数:8,代码来源:StartConversationModel.php

示例9: getFilenameWithoutExtension

 /**
  * 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);
 }
开发者ID:akochnov,项目名称:fts,代码行数:25,代码来源:Path.php

示例10: __construct

 /**
  * 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);
     }
 }
开发者ID:webmozart,项目名称:console,代码行数:27,代码来源:Argument.php

示例11: setImage

 /**
  * Set image
  *
  * @param string $image
  * @return User
  */
 public function setImage($image)
 {
     Assert::nullOrString($image);
     $this->image = $image;
     return $this;
 }
开发者ID:winkutc,项目名称:server,代码行数:12,代码来源:User.php


注:本文中的Webmozart\Assert\Assert::nullOrString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。