PHP code example of rnr1721 / le7-links
1. Go to this page and download the library: Download rnr1721/le7-links library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rnr1721 / le7-links example snippets
use Core\Links\Link;
$link = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']);
$scheme = $link->getScheme();
$authority = $link->getAuthority();
$userInfo = $link->getUserInfo();
$host = $link->getHost();
$port = $link->getPort();
$path = $link->getPath();
$query = $link->getQuery();
$fragment = $link->getFragment();
$newLink = $link->withScheme('https');
$newLink = $link->withUserInfo('username', 'password');
$newLink = $link->withHost('example.com');
$newLink = $link->withPort(8080);
$newLink = $link->withPath('/new-path');
$newLink = $link->withQuery('param1=value1¶m2=value2');
$newLink = $link->withFragment('section1');
$html = $link->render();
$newLink = $link->withHref('https://example.com/page2');
$newLink = $link->withRel('rel2', 'rel3');
$newLink = $link->withoutRel('rel1');
$newLink = $link->withAttribute('attribute2', 'value2');
$newLink = $link->withoutAttribute('attribute1');
$string = (string)$link;
use Core\Links\LinkProvider;
$linkProvider = new LinkProvider();
use Core\Links\Link;
$link = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']);
$linkProvider = $linkProvider->withLink($link);
$link1 = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']);
$link2 = new Link('https://example.com/page2', ['rel2'], ['attribute2' => 'value2']);
$linkProvider = $linkProvider->withLink($link1)
->withLink($link2);
$links = $linkProvider->getLinks();
$linkProvider = $linkProvider->withoutLink($link);
$filteredLinks = $linkProvider->getLinksByRel('rel1');
$links = [
new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']),
new Link('https://example.com/page2', ['rel2'], ['attribute2' => 'value2']),
];
$linkProvider = $linkProvider->withLinks($links);
$linkProvider = $linkProvider->withoutLinks($links);