Webmozart\Assert\Assert::contains PHP Method

contains() public static method

public static contains ( $value, $subString, $message = '' )
    public static function contains($value, $subString, $message = '')
    {
        if (false === strpos($value, $subString)) {
            static::reportInvalidArgument(sprintf($message ?: 'Expected a value to contain %2$s. Got: %s', static::valueToString($value), static::valueToString($subString)));
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Turns a URL into a relative path.
  *
  * The result is a canonical path. This class is using functionality of Path class.
  *
  * @see Path
  *
  * @param string $url     A URL to make relative.
  * @param string $baseUrl A base URL.
  *
  * @return string
  *
  * @throws InvalidArgumentException If the URL and base URL does
  *                                  not match.
  */
 public static function makeRelative($url, $baseUrl)
 {
     Assert::string($url, 'The URL must be a string. Got: %s');
     Assert::string($baseUrl, 'The base URL must be a string. Got: %s');
     Assert::contains($baseUrl, '://', '%s is not an absolute Url.');
     list($baseHost, $basePath) = self::split($baseUrl);
     if (false === strpos($url, '://')) {
         if (0 === strpos($url, '/')) {
             $host = $baseHost;
         } else {
             $host = '';
         }
         $path = $url;
     } else {
         list($host, $path) = self::split($url);
     }
     if ('' !== $host && $host !== $baseHost) {
         throw new InvalidArgumentException(sprintf('The URL "%s" cannot be made relative to "%s" since their host names are different.', $host, $baseHost));
     }
     return Path::makeRelative($path, $basePath);
 }
All Usage Examples Of Webmozart\Assert\Assert::contains