tipo: modificación del cpanel y gitignore de la carpeta vendor
This commit is contained in:
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) Spatie bvba <info@spatie.be>
|
||||
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in
|
||||
> all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
> THE SOFTWARE.
|
||||
Vendored
+159
@@ -0,0 +1,159 @@
|
||||
# Parse, build and manipulate URLs
|
||||
|
||||
[](https://packagist.org/packages/spatie/url)
|
||||
[](https://github.com/spatie/url/actions/workflows/run-tests.yml)
|
||||
[](https://packagist.org/packages/spatie/url)
|
||||
|
||||
A simple package to deal with URLs in your applications.
|
||||
|
||||
## Installation
|
||||
|
||||
You can install the package via composer:
|
||||
|
||||
```bash
|
||||
composer require spatie/url
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Parse and transform a URL
|
||||
|
||||
Retrieve any part of the URL:
|
||||
|
||||
```php
|
||||
use Spatie\Url\Url;
|
||||
|
||||
$url = Url::fromString('https://spatie.be/opensource');
|
||||
|
||||
echo $url->getScheme(); // 'https'
|
||||
echo $url->getHost(); // 'spatie.be'
|
||||
echo $url->getPath(); // '/opensource'
|
||||
```
|
||||
|
||||
Transform any part of the URL:
|
||||
|
||||
> **Note**
|
||||
> the `Url` class is immutable.
|
||||
|
||||
```php
|
||||
$url = Url::fromString('https://spatie.be/opensource');
|
||||
|
||||
echo $url->withHost('github.com')->withPath('spatie');
|
||||
// 'https://github.com/spatie'
|
||||
```
|
||||
|
||||
### Scheme
|
||||
|
||||
Transform the URL scheme.
|
||||
```php
|
||||
$url = Url::fromString('http://spatie.be/opensource');
|
||||
|
||||
echo $url->withScheme('https'); // 'https://spatie.be/opensource'
|
||||
```
|
||||
|
||||
Use a list of allowed schemes.
|
||||
|
||||
> **Note**
|
||||
> each scheme in the list will be sanitized
|
||||
|
||||
```php
|
||||
$url = Url::fromString('https://spatie.be/opensource');
|
||||
|
||||
echo $url->withAllowedSchemes(['wss'])->withScheme('wss'); // 'wss://spatie.be/opensource'
|
||||
```
|
||||
|
||||
or pass the list directly to `fromString` as the URL's scheme will be sanitized and validated immediately:
|
||||
|
||||
```php
|
||||
$url = Url::fromString('https://spatie.be/opensource', [...SchemeValidator::VALID_SCHEMES, 'wss']);
|
||||
|
||||
echo $url->withScheme('wss'); // 'wss://spatie.be/opensource'
|
||||
```
|
||||
|
||||
|
||||
### Query parameters
|
||||
|
||||
Retrieve and transform query parameters:
|
||||
|
||||
```php
|
||||
$url = Url::fromString('https://spatie.be/opensource?utm_source=github&utm_campaign=packages');
|
||||
|
||||
echo $url->getQuery(); // 'utm_source=github&utm_campaign=packages'
|
||||
|
||||
echo $url->getQueryParameter('utm_source'); // 'github'
|
||||
echo $url->getQueryParameter('utm_medium'); // null
|
||||
echo $url->getQueryParameter('utm_medium', 'social'); // 'social'
|
||||
echo $url->getQueryParameter('utm_medium', function() {
|
||||
//some logic
|
||||
return 'email';
|
||||
}); // 'email'
|
||||
|
||||
echo $url->withoutQueryParameter('utm_campaign'); // 'https://spatie.be/opensource?utm_source=github'
|
||||
echo $url->withQueryParameters(['utm_campaign' => 'packages']); // 'https://spatie.be/opensource?utm_source=github&utm_campaign=packages'
|
||||
```
|
||||
|
||||
### Path segments
|
||||
|
||||
Retrieve path segments:
|
||||
|
||||
```php
|
||||
$url = Url::fromString('https://spatie.be/opensource/laravel');
|
||||
|
||||
echo $url->getSegment(1); // 'opensource'
|
||||
echo $url->getSegment(2); // 'laravel'
|
||||
```
|
||||
|
||||
### PSR-7 `UriInterface`
|
||||
|
||||
Implements PSR-7's `UriInterface` interface:
|
||||
|
||||
```php
|
||||
class Url implements UriInterface { /* ... */ }
|
||||
```
|
||||
|
||||
The [`league/uri`](https://github.com/thephpleague/uri) is a more powerful package than this one. The main reason this package exists, is because the alternatives requires non-standard php extensions. If you're dealing with special character encodings or need bulletproof validation, you're definitely better off using `league/uri`.
|
||||
|
||||
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
composer test
|
||||
```
|
||||
|
||||
## Support us
|
||||
|
||||
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/url.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/url)
|
||||
|
||||
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
|
||||
|
||||
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
|
||||
|
||||
## Changelog
|
||||
|
||||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
|
||||
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
|
||||
|
||||
## Security Vulnerabilities
|
||||
|
||||
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
|
||||
|
||||
## Postcardware
|
||||
|
||||
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
|
||||
|
||||
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
|
||||
|
||||
We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).
|
||||
|
||||
## Credits
|
||||
|
||||
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
|
||||
- [All Contributors](../../contributors)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
||||
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "spatie/url",
|
||||
"description": "Parse, build and manipulate URL's",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"spatie",
|
||||
"url"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sebastian De Deyne",
|
||||
"email": "sebastian@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"homepage": "https://github.com/spatie/url",
|
||||
"require": {
|
||||
"php": "^8.0",
|
||||
"psr/http-message": "^1.0 || ^2.0",
|
||||
"spatie/macroable": "^1.0 || ^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"pestphp/pest": "^1.21"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Spatie\\Url\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Spatie\\Url\\Test\\": "tests"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
},
|
||||
"sort-packages": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/pest",
|
||||
"test-coverage": "vendor/bin/pest --coverage-html coverage"
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url;
|
||||
|
||||
use Spatie\Url\Contracts\Validator;
|
||||
|
||||
abstract class BaseValidator implements Validator
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url\Contracts;
|
||||
|
||||
interface Validator
|
||||
{
|
||||
public function validate(): void;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class InvalidArgument extends InvalidArgumentException
|
||||
{
|
||||
public static function invalidScheme(string $scheme, array $allowedSchemes): static
|
||||
{
|
||||
$schemes = implode(', ', array_map(fn ($scheme) => "`{$scheme}`", $allowedSchemes));
|
||||
|
||||
return new static("The scheme `{$scheme}` isn't valid. It should be either {$schemes}.");
|
||||
}
|
||||
|
||||
public static function invalidUrl(string $url): static
|
||||
{
|
||||
return new static("The string `{$url}` is no valid url.");
|
||||
}
|
||||
|
||||
public static function segmentZeroDoesNotExist(): static
|
||||
{
|
||||
return new static("Segment 0 doesn't exist. Segments can be retrieved by using 1-based index or a negative index.");
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url;
|
||||
|
||||
class QueryParameterBag implements \Stringable
|
||||
{
|
||||
public function __construct(
|
||||
protected array $parameters = [],
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
public static function fromString(string $query = ''): static
|
||||
{
|
||||
if ($query === '') {
|
||||
return new static();
|
||||
}
|
||||
|
||||
$parameters = [];
|
||||
parse_str($query, $parameters);
|
||||
$parameters = array_map(fn ($param) => $param !== '' ? $param : null, $parameters);
|
||||
|
||||
return new static($parameters);
|
||||
}
|
||||
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return $this->parameters[$key];
|
||||
}
|
||||
|
||||
return is_callable($default) ? $default() : $default;
|
||||
}
|
||||
|
||||
public function has(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->parameters);
|
||||
}
|
||||
|
||||
public function set(string $key, string|array $value): self
|
||||
{
|
||||
$this->parameters[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unset(string $key): self
|
||||
{
|
||||
unset($this->parameters[$key]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unsetAll(): self
|
||||
{
|
||||
$this->parameters = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return http_build_query($this->parameters, '', '&', PHP_QUERY_RFC3986);
|
||||
}
|
||||
}
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url;
|
||||
|
||||
use Spatie\Macroable\Macroable;
|
||||
use Stringable;
|
||||
|
||||
class Scheme implements Stringable
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
protected string $scheme;
|
||||
|
||||
protected SchemeValidator $validator;
|
||||
|
||||
public function __construct(
|
||||
string $scheme = '',
|
||||
array|null $allowedSchemes = null,
|
||||
) {
|
||||
$this->validator = new SchemeValidator($allowedSchemes);
|
||||
|
||||
$this->setScheme($scheme);
|
||||
}
|
||||
|
||||
protected function validate(string $scheme): void
|
||||
{
|
||||
$this->validator->setScheme($scheme);
|
||||
|
||||
$this->validator->validate();
|
||||
}
|
||||
|
||||
public function getScheme(): string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
public function setScheme(string $scheme): void
|
||||
{
|
||||
$sanitizedScheme = $this->validator::sanitizeScheme($scheme);
|
||||
|
||||
$this->validate($sanitizedScheme);
|
||||
|
||||
$this->scheme = $sanitizedScheme;
|
||||
}
|
||||
|
||||
public function getAllowedSchemes(): array
|
||||
{
|
||||
return $this->validator->getAllowedSchemes();
|
||||
}
|
||||
|
||||
public function setAllowedSchemes(array $allowedSchemes): void
|
||||
{
|
||||
$this->validator->setAllowedSchemes($allowedSchemes);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getScheme();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->validator = clone $this->validator;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url;
|
||||
|
||||
use Spatie\Url\Exceptions\InvalidArgument;
|
||||
|
||||
class SchemeValidator extends BaseValidator
|
||||
{
|
||||
public const VALID_SCHEMES = ['http', 'https', 'mailto', 'tel'];
|
||||
|
||||
private string|null $scheme;
|
||||
|
||||
public function __construct(
|
||||
private array|null $allowedSchemes = null
|
||||
) {
|
||||
$this->scheme = null;
|
||||
$this->allowedSchemes = $allowedSchemes ?? self::VALID_SCHEMES;
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
// '' aka "no scheme" must always be valid
|
||||
$alwaysAllowedSchemes = [''];
|
||||
|
||||
if (! in_array($this->scheme, [...$this->allowedSchemes, ...$alwaysAllowedSchemes])) {
|
||||
throw InvalidArgument::invalidScheme($this->scheme, $this->allowedSchemes);
|
||||
}
|
||||
}
|
||||
|
||||
public static function sanitizeScheme(string $scheme): string
|
||||
{
|
||||
// TODO: regex to allow correct format according to https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
|
||||
return strtolower($scheme);
|
||||
}
|
||||
|
||||
public function getScheme(): string|null
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
public function setScheme(string $scheme): void
|
||||
{
|
||||
$this->scheme = $scheme;
|
||||
}
|
||||
|
||||
public function getAllowedSchemes(): array|null
|
||||
{
|
||||
return $this->allowedSchemes;
|
||||
}
|
||||
|
||||
public function setAllowedSchemes(array $allowedSchemes): void
|
||||
{
|
||||
$this->allowedSchemes = array_map(
|
||||
fn ($scheme) => static::sanitizeScheme($scheme),
|
||||
$allowedSchemes
|
||||
);
|
||||
}
|
||||
}
|
||||
Vendored
+373
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Url;
|
||||
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Spatie\Macroable\Macroable;
|
||||
use Spatie\Url\Exceptions\InvalidArgument;
|
||||
use Stringable;
|
||||
|
||||
class Url implements UriInterface, Stringable
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
protected Scheme $scheme;
|
||||
|
||||
protected string $host = '';
|
||||
|
||||
protected ?int $port = null;
|
||||
|
||||
protected string $user = '';
|
||||
|
||||
protected ?string $password = null;
|
||||
|
||||
protected string $path = '';
|
||||
|
||||
protected QueryParameterBag $query;
|
||||
|
||||
protected string $fragment = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->scheme = new Scheme();
|
||||
$this->query = new QueryParameterBag();
|
||||
}
|
||||
|
||||
public static function create(): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
||||
public static function fromString(string $url, array|null $allowedSchemes = null): static
|
||||
{
|
||||
$toUrl = new static();
|
||||
|
||||
if($allowedSchemes !== null) {
|
||||
$toUrl = $toUrl->withAllowedSchemes($allowedSchemes);
|
||||
}
|
||||
|
||||
return static::make($url, $toUrl);
|
||||
}
|
||||
|
||||
protected static function make(string $fromUrl, self $toUrl): static
|
||||
{
|
||||
if (! $parts = parse_url($fromUrl)) {
|
||||
throw InvalidArgument::invalidUrl($fromUrl);
|
||||
}
|
||||
|
||||
$toUrl->scheme->setScheme(isset($parts['scheme']) ? $parts['scheme'] : '');
|
||||
$toUrl->host = $parts['host'] ?? '';
|
||||
$toUrl->port = $parts['port'] ?? null;
|
||||
$toUrl->user = $parts['user'] ?? '';
|
||||
$toUrl->password = $parts['pass'] ?? null;
|
||||
$toUrl->path = $parts['path'] ?? '/';
|
||||
$toUrl->query = QueryParameterBag::fromString($parts['query'] ?? '');
|
||||
$toUrl->fragment = $parts['fragment'] ?? '';
|
||||
|
||||
return $toUrl;
|
||||
}
|
||||
|
||||
public function getScheme(): string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
public function getAuthority(): string
|
||||
{
|
||||
$authority = $this->host;
|
||||
|
||||
if ($this->getUserInfo()) {
|
||||
$authority = $this->getUserInfo().'@'.$authority;
|
||||
}
|
||||
|
||||
if ($this->port !== null) {
|
||||
$authority .= ':'.$this->port;
|
||||
}
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
public function getUserInfo(): string
|
||||
{
|
||||
$userInfo = $this->user;
|
||||
|
||||
if ($this->password !== null) {
|
||||
$userInfo .= ':'.$this->password;
|
||||
}
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
public function getPort(): ?int
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return $this->getSegment(-1);
|
||||
}
|
||||
|
||||
public function getDirname(): string
|
||||
{
|
||||
$segments = $this->getSegments();
|
||||
|
||||
array_pop($segments);
|
||||
|
||||
return '/'.implode('/', $segments);
|
||||
}
|
||||
|
||||
public function getQuery(): string
|
||||
{
|
||||
return (string) $this->query;
|
||||
}
|
||||
|
||||
public function getQueryParameter(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->query->get($key, $default);
|
||||
}
|
||||
|
||||
public function hasQueryParameter(string $key): bool
|
||||
{
|
||||
return $this->query->has($key);
|
||||
}
|
||||
|
||||
public function getAllQueryParameters(): array
|
||||
{
|
||||
return $this->query->all();
|
||||
}
|
||||
|
||||
public function withQueryParameter(string $key, string $value): static
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->query->unset($key);
|
||||
|
||||
$url->query->set($key, $value);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withQueryParameters(array $parameters): static
|
||||
{
|
||||
$parameters = array_merge($this->getAllQueryParameters(), $parameters);
|
||||
$url = clone $this;
|
||||
$url->query = new QueryParameterBag($parameters);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withoutQueryParameter(string $key): static
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->query->unset($key);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withoutQueryParameters(): static
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->query->unsetAll();
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getFragment(): string
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
public function getSegments(): array
|
||||
{
|
||||
return explode('/', trim($this->path, '/'));
|
||||
}
|
||||
|
||||
public function getSegment(int $index, mixed $default = null): mixed
|
||||
{
|
||||
$segments = $this->getSegments();
|
||||
|
||||
if ($index === 0) {
|
||||
throw InvalidArgument::segmentZeroDoesNotExist();
|
||||
}
|
||||
|
||||
if ($index < 0) {
|
||||
$segments = array_reverse($segments);
|
||||
$index = abs($index);
|
||||
}
|
||||
|
||||
return $segments[$index - 1] ?? $default;
|
||||
}
|
||||
|
||||
public function getFirstSegment(): mixed
|
||||
{
|
||||
$segments = $this->getSegments();
|
||||
|
||||
return $segments[0] ?? null;
|
||||
}
|
||||
|
||||
public function getLastSegment(): mixed
|
||||
{
|
||||
$segments = $this->getSegments();
|
||||
|
||||
return end($segments) ?? null;
|
||||
}
|
||||
|
||||
public function withScheme($scheme): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->scheme->setScheme($scheme);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withAllowedSchemes(array $schemes): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->scheme->setAllowedSchemes($schemes);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withUserInfo($user, $password = null): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->user = $user;
|
||||
$url->password = $password;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withHost($host): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->host = $host;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withPort($port): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->port = $port;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withPath($path): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
if (! str_starts_with($path, '/')) {
|
||||
$path = '/'.$path;
|
||||
}
|
||||
|
||||
$url->path = $path;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withDirname(string $dirname): static
|
||||
{
|
||||
$dirname = trim($dirname, '/');
|
||||
|
||||
if (! $this->getBasename()) {
|
||||
return $this->withPath($dirname);
|
||||
}
|
||||
|
||||
return $this->withPath($dirname.'/'.$this->getBasename());
|
||||
}
|
||||
|
||||
public function withBasename(string $basename): static
|
||||
{
|
||||
$basename = trim($basename, '/');
|
||||
|
||||
if ($this->getDirname() === '/') {
|
||||
return $this->withPath('/'.$basename);
|
||||
}
|
||||
|
||||
return $this->withPath($this->getDirname().'/'.$basename);
|
||||
}
|
||||
|
||||
public function withQuery($query): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->query = QueryParameterBag::fromString($query);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function withFragment($fragment): static
|
||||
{
|
||||
$url = clone $this;
|
||||
|
||||
$url->fragment = $fragment;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function matches(self $url): bool
|
||||
{
|
||||
return (string) $this === (string) $url;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
$url = '';
|
||||
|
||||
if ($this->getScheme() !== '' && ! in_array($this->getScheme(), ['mailto', 'tel'], true)) {
|
||||
$url .= $this->getScheme().'://';
|
||||
}
|
||||
|
||||
if (in_array($this->getScheme(), ['mailto', 'tel'], true) && $this->getPath() !== '') {
|
||||
$url .= $this->getScheme().':';
|
||||
}
|
||||
|
||||
if ($this->getScheme() === '' && $this->getAuthority() !== '') {
|
||||
$url .= '//';
|
||||
}
|
||||
|
||||
if ($this->getAuthority() !== '') {
|
||||
$url .= $this->getAuthority();
|
||||
}
|
||||
|
||||
if ($this->getPath() !== '/') {
|
||||
$path = in_array($this->getScheme(), ['mailto', 'tel'], true)
|
||||
? ltrim($this->getPath(), '/')
|
||||
: $this->getPath();
|
||||
|
||||
$url .= $path;
|
||||
}
|
||||
|
||||
if ($this->getQuery() !== '') {
|
||||
$url .= '?'.$this->getQuery();
|
||||
}
|
||||
|
||||
if ($this->getFragment() !== '') {
|
||||
$url .= '#'.$this->getFragment();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->query = clone $this->query;
|
||||
$this->scheme = clone $this->scheme;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user