PHP Classes

File: example.URLUtility.php

Recommend this page to a friend!
  Classes of Marcel Oehler   URL Utility   example.URLUtility.php   Download  
File: example.URLUtility.php
Role: Example script
Content type: text/plain
Description: URL Utility example
Class: URL Utility
Compose an URL from its component definitions
Author: By
Last change: OO
Date: 5 years ago
Size: 4,228 bytes
 

Contents

Class file image Download
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>URLUtility</title>
</head>
<body>
<pre>
<?php

require('../library/URLUtility.php');
$link = new URLUtility();

echo
'Current document:' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setScheme('https');
$link->setHost('local_host');
$link->setPort('4242');
$link->setPath('/any/path/');
$link->setFileName('script_file.php');

echo
'setScheme(\'https\')' . PHP_EOL . 'setHost(\'local_host\')' . PHP_EOL . 'setPort(\'4242\')' . PHP_EOL . 'setPath(\'/any/path/\')' . PHP_EOL . 'setFileName(\'script_file.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

// --- SET ---

$link->setQuery('one=[1]&two=[2]&three=[3]');
echo
'setQuery(\'one=[1]&two=[2]&three=[3]\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setFilePath('/path/to/script.php');
echo
'setFilePath(\'/path/to/script.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setFilePathQuery('/path/to/another/script.php?four=[4]&five=[5]');
echo
'setFilePathQuery(\'/path/to/another/script.php?four=[4]&five=[5]\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setSchemeHost('http://www.local-host.ch');
echo
'setSchemeHost(\'http://www.local-host.ch\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setSchemeHostPath('http://www.local_host.ch');
echo
'setSchemeHostPath(\'http://www.local_host.ch\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->setSchemeHostFilePath('http://www.localhost.ch');
echo
'setSchemeHostFilePath(\'http://www.localhost.ch\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

// --- MERGE ---

$link->mergeQuery('one=[1]&two=[2]&three=[3]');
echo
'mergeQuery(\'one=[1]&two=[2]&three=[3]\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->mergeFilePath('./path/to/yet/another/php_script.php');
echo
'mergeFilePath(\'./path/to/yet/another/php_script.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->mergeFilePathQuery('../?six=[6]&seven=[7]');
echo
'mergeFilePathQuery(\'../?six=[6]&seven=[7]\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->mergeSchemeHost('http://local-host:4244/no/path/at/all.php');
echo
'mergeSchemeHost(\'http://local-host:4244/no/path/at/all.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->mergeSchemeHostPath('http://local_host:4243/no/path/at/all.php');
echo
'mergeSchemeHostPath(\'http://local_host:4243/no/path/at/all.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

$link->mergeSchemeHostFilePath('http://localhost:4242/no/path/at/all.php');
echo
'mergeSchemeHostFilePath(\'http://localhost:4242/no/path/at/all.php\')' . PHP_EOL . PHP_EOL . output($link) . PHP_EOL . PHP_EOL . '<hr>' . PHP_EOL;

highlight_file('../library/URLUtility.php');

/**
 * @param URLUtility $link
 * @return string
 */
function output($link)
{
    return
       
'getURL() : ' . $link->getURL() . PHP_EOL .
       
'getSchemeHost() : ' . $link->getSchemeHost() . PHP_EOL .
       
'getSchemeHostPath() : ' . $link->getSchemeHostPath() . PHP_EOL .
       
'getSchemeHostFilePath() : ' . $link->getSchemeHostFilePath() . PHP_EOL .
       
'getScheme() : ' . $link->getScheme() . PHP_EOL .
       
'getHost() : ' . $link->getHost() . PHP_EOL .
       
'getPort() : ' . $link->getPort() . PHP_EOL .
       
'getPath() : ' . $link->getPath() . PHP_EOL .
       
'getFileName() : ' . $link->getFileName() . PHP_EOL .
       
'getFilePath() : ' . $link->getFilePath() . PHP_EOL .
       
'getQuery() : ' . $link->getQuery() . PHP_EOL .
       
'getFilePathQuery() : ' . $link->getFilePathQuery();
}

?>
</pre>
</body>
</html>