Created
August 11, 2023 07:36
Revisions
-
nyamsprod created this gist
Aug 11, 2023 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <?php use League\Uri\Idna\Converter as IdnConverter; use League\Uri\IPv4\Converter as Ipv4Converter; echo IdnConverter::toAscii('bébé.be')->domain(), PHP_EOL; //display "xn--bb-bjab.be" echo Ipv4Converter::fromEnvironment()->toDecimal('192.87.125'); //display "192.87.0.125" This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ <?php use League\Uri\BaseUri; use League\Uri\Modifier; $uri = "https://www.bbc.co.uk"; $resolveUri = BaseUri::from($uri) ->resolve("path/to/../../the/sky/?foo.bar"); $newUri = Modifier::from($resolveUri) ->appendQuery('foo.bar=tata') ->removeLabels(1) ->removeTrailingSlash() ->getUriString(); This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <?php use League\Uri\Uri; use League\Uri\UriModifier; use League\Uri\UriResolver; $uri = "https://www.bbc.co.uk"; $relativeUri = "path/to/../../the/sky/?foo.bar"; $baseUri = Uri::createFromString($uri); $relativeUri = Uri::createFromString($relativeUri); $resolveUri = UriResolver::resolve($relativeUri, $baseUri); $newUri = UriModifier::appendQuery($resolveUri, 'foo.bar=tata'); $newUri = UriModifier::removeLabels($newUri, 1); $newUri = UriModifier::removeTrailingSlash($newUri); $newUri = $newUri->__toString(); echo $newUri, PHP_EOL; This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <?php use League\Uri\UriTemplate; $template = 'https://api.example.com/{version}/search/{term}/{?q*,limit}'; $params = [ 'term' => ['john', 'doe'], 'q' => ['a', 'b'], 'limit' => '10', ]; $uriTemplate = new UriTemplate($template); echo $uriTemplate->expand($params); // display https://api.example.com//search/john,doe/?q=a&q=b&limit=10 with missing version // this is valid and follow the specifications echo $uriTemplate->expandOrFail($params); // will throw a TemplateCanNotBeExpanded exception with the following message // Missing variables `version`