phpdoc/Library/Helper/Url.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="robots" content="index, follow, all" />
<title>Library\Helper\Url | Library</title>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="../../css/sami.css">
<script src="../../js/jquery-1.11.1.min.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/typeahead.min.js"></script>
<script src="../../sami.js"></script>
<meta name="MobileOptimized" content="width">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
</head>
<body id="class" data-name="class:Library_Helper_Url" data-root-path="../../">
<div id="content">
<div id="left-column">
<div id="control-panel">
<form id="search-form" action="../../search.html" method="GET">
<span class="glyphicon glyphicon-search"></span>
<input name="search"
class="typeahead form-control"
type="search"
placeholder="Search">
</form>
</div>
<div id="api-tree"></div>
</div>
<div id="right-column">
<nav id="site-nav" class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-elements">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../../index.html">Library</a>
</div>
<div class="collapse navbar-collapse" id="navbar-elements">
<ul class="nav navbar-nav">
<li><a href="../../classes.html">Classes</a></li>
<li><a href="../../namespaces.html">Namespaces</a></li>
<li><a href="../../interfaces.html">Interfaces</a></li>
<li><a href="../../traits.html">Traits</a></li>
<li><a href="../../doc-index.html">Index</a></li>
<li><a href="../../search.html">Search</a></li>
</ul>
</div>
</div>
</nav>
<div class="namespace-breadcrumbs">
<ol class="breadcrumb">
<li><span class="label label-default">class</span></li>
<li><a href="../../Library.html">Library</a></li>
<li><a href="../../Library/Helper.html">Helper</a></li>
<li>Url</li>
</ol>
</div>
<div id="page-content">
<div class="page-header">
<h1>Url</h1>
</div>
<p> class
<strong>Url</strong>
</p>
<div class="description">
<p>URL common methods</p> <p>For convenience, the best practice is to use:</p>
<pre><code>use Library\Helper\Url as UrlHelper;
</code></pre>
</p> </div>
<h2>Methods</h2>
<div class="container-fluid underlined">
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_getRequestUrl">getRequestUrl</a>(
bool $entities = false,
bool $base = false,
bool $no_file = false,
bool $no_rewrite = false)
<p>Get the current browser/server URL</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_getHttpProtocol">getHttpProtocol</a>()
<p>Get the current 'http' or 'https' protocol</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
array
</div>
<div class="col-md-8 type">
<a href="#method_parse">parse</a>(
string $url)
<p>Parse an URL and returns its composition as an array, with the URI query if so</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_resolvePath">resolvePath</a>(
string $url = null,
boolean $realpath = false)
<p>Returns the URL with paths cleaned (<code>./</code> and `.</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_resolveHttp">resolveHttp</a>(
string $url = null)
<p>Returns an URL with leading 'http://' if it was absent</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_getAbsoluteUrl">getAbsoluteUrl</a>(
string $url = null)
<p>Returns if possible an absolute URL in the current system</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_url">url</a>(
<abbr title="Library\Helper\string/array/null">string/array/null</abbr> $param = null,
<abbr title="Library\Helper\string/null">string/null</abbr> $value = null,
<abbr title="Library\Helper\string/null">string/null</abbr> $url = null)
<p>Global URL builder</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
<abbr title="Library\Helper\string/array">string/array</abbr>
</div>
<div class="col-md-8 type">
<a href="#method_getParameter">getParameter</a>(
<abbr title="Library\Helper\string/bool">string/bool</abbr> $param = false,
<abbr title="Library\Helper\string/null">string/null</abbr> $url = false)
<p>Get the value of an URL parameter</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
<abbr title="Library\Helper\string/array">string/array</abbr>
</div>
<div class="col-md-8 type">
<a href="#method_setParameter">setParameter</a>(
<abbr title="Library\Helper\string/bool">string/bool</abbr> $var = '',
<abbr title="Library\Helper\string/false">string/false</abbr> $val = false,
<abbr title="Library\Helper\string/false">string/false</abbr> $url = false,
bool $rebuild = true)
<p>Set the value of an URL parameter</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
string
</div>
<div class="col-md-8 type">
<a href="#method_build">build</a>(
array $url_components = null,
<abbr title="Library\Helper\string/array/boolean">string/array/boolean</abbr> $not_toput = null)
<p>Rebuild a full URL string from an array of elements</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
bool
</div>
<div class="col-md-8 type">
<a href="#method_isUrl">isUrl</a>(
string $url = null,
array $protocols = array('http', 'https', 'ftp'),
<abbr title="Library\Helper\bool/string">bool/string</abbr> $localhost = false)
<p>Validate an URL (without a hash content)</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
bool
</div>
<div class="col-md-8 type">
<a href="#method_isEmail">isEmail</a>(
string $email = null)
<p>Validate an email address</p> </div>
<div class="col-md-2"></div>
</div>
</div>
<h2>Details</h2>
<div id="method-details">
<div class="method-item">
<h3 id="method_getRequestUrl">
<div class="location">at line 48</div>
<code> static
string
<strong>getRequestUrl</strong>(
bool $entities = false,
bool $base = false,
bool $no_file = false,
bool $no_rewrite = false)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Get the current browser/server URL</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
bool</td>
<td>$entities</td>
<td>Protect '&' entities parsing them in '&' ? (default is FALSE)</td>
</tr>
<tr>
<td>
bool</td>
<td>$base</td>
<td>Do you want just the base URL, without any URI (default is FALSE)</td>
</tr>
<tr>
<td>
bool</td>
<td>$no_file</td>
<td>Do you want just the base URL path, without the input file and any URI (default is FALSE)</td>
</tr>
<tr>
<td>
bool</td>
<td>$no_rewrite</td>
<td>Do you want the real file pointed by the URL in case of URL rewriting (default is FALSE)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_getHttpProtocol">
<div class="location">at line 89</div>
<code> static
string
<strong>getHttpProtocol</strong>()</code>
</h3>
<div class="details">
<div class="method-description">
<p>Get the current 'http' or 'https' protocol</p> </div>
<div class="tags">
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The current protocol</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_parse">
<div class="location">at line 103</div>
<code> static
array
<strong>parse</strong>(
string $url)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Parse an URL and returns its composition as an array, with the URI query if so</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$url</td>
<td>The URL to parse (required)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
array</td>
<td>An array of the URL components</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_resolvePath">
<div class="location">at line 124</div>
<code> static
string
<strong>resolvePath</strong>(
string $url = null,
boolean $realpath = false)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Returns the URL with paths cleaned (<code>./</code> and `.</p> <p>./` are resolved)</p>
<p>Inspired by SPIP <a href="http://spip.net">http://spip.net</a></p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$url</td>
<td>The URL to resolve</td>
</tr>
<tr>
<td>
boolean</td>
<td>$realpath</td>
<td>Returns the real path of the path (default is <code>false</code>)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The resolved path, or real path if so</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_resolveHttp">
<div class="location">at line 151</div>
<code> static
string
<strong>resolveHttp</strong>(
string $url = null)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Returns an URL with leading 'http://' if it was absent</p> <p>Inspired by SPIP <a href="http://spip.net">http://spip.net</a></p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$url</td>
<td>The URL to resolve</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The resolved URL</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_getAbsoluteUrl">
<div class="location">at line 169</div>
<code> static
string
<strong>getAbsoluteUrl</strong>(
string $url = null)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Returns if possible an absolute URL in the current system</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$url</td>
<td>The URL to resolve</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The resolved URL</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_url">
<div class="location">at line 191</div>
<code> static
string
<strong>url</strong>(
<abbr title="Library\Helper\string/array/null">string/array/null</abbr> $param = null,
<abbr title="Library\Helper\string/null">string/null</abbr> $value = null,
<abbr title="Library\Helper\string/null">string/null</abbr> $url = null)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Global URL builder</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
<abbr title="Library\Helper\string/array/null">string/array/null</abbr></td>
<td>$param</td>
<td>A parameter to set, or an array like <code>param => value</code> to set in URL</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/null">string/null</abbr></td>
<td>$value</td>
<td>The value of the <code>$param</code> argument (if it is a string)</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/null">string/null</abbr></td>
<td>$url</td>
<td>The URL to work on (<code>self::getRequestUrl()</code> by default)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The final rebuilt URL</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_getParameter">
<div class="location">at line 226</div>
<code> static
<abbr title="Library\Helper\string/array">string/array</abbr>
<strong>getParameter</strong>(
<abbr title="Library\Helper\string/bool">string/bool</abbr> $param = false,
<abbr title="Library\Helper\string/null">string/null</abbr> $url = false)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Get the value of an URL parameter</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
<abbr title="Library\Helper\string/bool">string/bool</abbr></td>
<td>$param</td>
<td>A parameter to get, or <code>false</code> to get the global parameters array</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/null">string/null</abbr></td>
<td>$url</td>
<td>The URL to work on (<code>self::getRequestUrl()</code> by default)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
<abbr title="Library\Helper\string/array">string/array</abbr></td>
<td>The parameter value or the global array of parameters</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_setParameter">
<div class="location">at line 259</div>
<code> static
<abbr title="Library\Helper\string/array">string/array</abbr>
<strong>setParameter</strong>(
<abbr title="Library\Helper\string/bool">string/bool</abbr> $var = '',
<abbr title="Library\Helper\string/false">string/false</abbr> $val = false,
<abbr title="Library\Helper\string/false">string/false</abbr> $url = false,
bool $rebuild = true)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Set the value of an URL parameter</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
<abbr title="Library\Helper\string/bool">string/bool</abbr></td>
<td>$var</td>
<td>A parameter to get, or <code>false</code> to get the global parameters array</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/false">string/false</abbr></td>
<td>$val</td>
<td>The value of the <code>$param</code> argument (if <code>null</code>, the argument is stripped)</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/false">string/false</abbr></td>
<td>$url</td>
<td>The URL to work on (<code>self::getRequestUrl()</code> by default)</td>
</tr>
<tr>
<td>
bool</td>
<td>$rebuild</td>
<td>Return a rebuilt URL (<code>true</code> by dfault - if <code>false</code>, the URL components array is returned)</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
<abbr title="Library\Helper\string/array">string/array</abbr></td>
<td>The final URL</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_build">
<div class="location">at line 281</div>
<code> static
string
<strong>build</strong>(
array $url_components = null,
<abbr title="Library\Helper\string/array/boolean">string/array/boolean</abbr> $not_toput = null)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Rebuild a full URL string from an array of elements</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
array</td>
<td>$url_components</td>
<td>The array of the URL components:: <code>scheme</code>, <code>user</code>,
<code>pass</code>, <code>host</code>, <code>port</code>, <code>path</code>, <code>params</code>, <code>hash</code></td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\string/array/boolean">string/array/boolean</abbr></td>
<td>$not_toput</td>
<td>The name of an array of elements to not include</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>The final URL as a string</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_isUrl">
<div class="location">at line 314</div>
<code> static
bool
<strong>isUrl</strong>(
string $url = null,
array $protocols = array('http', 'https', 'ftp'),
<abbr title="Library\Helper\bool/string">bool/string</abbr> $localhost = false)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Validate an URL (without a hash content)</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$url</td>
<td>The string to validate</td>
</tr>
<tr>
<td>
array</td>
<td>$protocols</td>
<td>Table of Internet protocols to verify (by default : 'http', 'https', 'ftp')</td>
</tr>
<tr>
<td>
<abbr title="Library\Helper\bool/string">bool/string</abbr></td>
<td>$localhost</td>
<td>Is it locally (useful for validating 'http://localhost ...') (FALSE by default) - You can specify a string to check</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
bool</td>
<td>Returns <code>true</code> if this is a URL in one of the specified protocols</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_isEmail">
<div class="location">at line 336</div>
<code> static
bool
<strong>isEmail</strong>(
string $email = null)</code>
</h3>
<div class="details">
<div class="method-description">
<p>Validate an email address</p> </div>
<div class="tags">
<h4>Parameters</h4>
<table class="table table-condensed">
<tr>
<td>
string</td>
<td>$email</td>
<td>The string to validate</td>
</tr>
</table>
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
bool</td>
<td>Returns <code>true</code> if this is an email</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
Generated by <a href="http://sami.sensiolabs.org/">Sami, the API Documentation Generator</a>.
</div>
</div>
</div>
</body>
</html>