Version 1.0.0

This commit is contained in:
2025-07-13 00:10:45 +03:00
commit 42da8af363
35 changed files with 3468 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Diffhead\PHP\Url\Builder;
use Diffhead\PHP\Url\Builder;
use Diffhead\PHP\Url\Url;
class ReplaceAttributes implements Builder
{
public function __construct(
private Url $url
) {}
/**
* Pass the hostname and/or another params
* to replace it in the URL instance.
*
* Empty hostname argument means
* it will not be replaced.
*
* @param string $hostname
* @param array{scheme?:string,port?:int,path?:string,parameters?:array} $parameters
*/
public function build(string $hostname = '', array $parameters = []): Url
{
$scheme = $parameters['scheme'] ?? $this->url->scheme();
$hostname = $hostname ?: $this->url->hostname();
$path = $parameters['path'] ?? $this->url->path();
$port = $parameters['port'] ?? $this->url->port();
$params = $parameters['parameters'] ?? $this->url->parameters();
return Url::create($scheme, $hostname, $path, $port, $params);
}
}