Compare commits
2 commits
9cc0f8581a
...
c900324860
Author | SHA1 | Date | |
---|---|---|---|
c900324860 | |||
5ce273cfad |
7 changed files with 48 additions and 35 deletions
45
src/Url.php
45
src/Url.php
|
@ -79,13 +79,14 @@ class Url {
|
||||||
* authenticated users (optional, default: true if the
|
* authenticated users (optional, default: true if the
|
||||||
* special force_authentication function is defined,
|
* special force_authentication function is defined,
|
||||||
* false otherwise)
|
* false otherwise)
|
||||||
* @param boolean $override Allow override if a command already exists with the
|
* @param boolean $overwrite Allow overwrite if a command already exists with the
|
||||||
* same name (optional, default: false)
|
* same name (optional, default: false)
|
||||||
* @param boolean $api_mode Enable API mode (optional, default: false)
|
* @param boolean $api_mode Enable API mode (optional, default: false)
|
||||||
* @param array|string|null $methods HTTP method (optional, default: array('GET', 'POST'))
|
* @param array|string|null $methods HTTP method (optional, default: array('GET', 'POST'))
|
||||||
|
* @return bool
|
||||||
**/
|
**/
|
||||||
public static function add_url_handler($pattern, $handler=null, $additional_info=null,
|
public static function add_url_handler($pattern, $handler=null, $additional_info=null,
|
||||||
$authenticated=null, $override=true, $api_mode=false,
|
$authenticated=null, $overwrite=true, $api_mode=false,
|
||||||
$methods=null) {
|
$methods=null) {
|
||||||
$authenticated = (
|
$authenticated = (
|
||||||
is_null($authenticated)?
|
is_null($authenticated)?
|
||||||
|
@ -97,31 +98,26 @@ class Url {
|
||||||
elseif (!is_array($methods))
|
elseif (!is_array($methods))
|
||||||
$methods = array($methods);
|
$methods = array($methods);
|
||||||
if (is_array($pattern)) {
|
if (is_array($pattern)) {
|
||||||
|
$error = false;
|
||||||
if (is_null($handler))
|
if (is_null($handler))
|
||||||
foreach($pattern as $p => $h)
|
foreach($pattern as $p => $h)
|
||||||
self :: add_url_handler(
|
if (
|
||||||
$p, $h, $additional_info, $authenticated, $override, $api_mode, $methods);
|
!self :: add_url_handler(
|
||||||
|
$p, $h, $additional_info, $authenticated, $overwrite, $api_mode, $methods)
|
||||||
|
) $error = true;
|
||||||
else
|
else
|
||||||
foreach($pattern as $p)
|
foreach($pattern as $p)
|
||||||
self :: add_url_handler(
|
if (
|
||||||
$p, $handler, $additional_info, $authenticated, $override, $api_mode, $methods);
|
!self :: add_url_handler(
|
||||||
|
$p, $handler, $additional_info, $authenticated, $overwrite, $api_mode, $methods)
|
||||||
|
) $error = true;
|
||||||
|
return !$error;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (!isset(self :: $patterns[$pattern])) {
|
if (!isset(self :: $patterns[$pattern]) || $overwrite) {
|
||||||
self :: $patterns[$pattern] = array(
|
if (isset(self :: $patterns[$pattern]))
|
||||||
'handler' => $handler,
|
|
||||||
'additional_info' => (
|
|
||||||
is_array($additional_info)?
|
|
||||||
$additional_info:array()
|
|
||||||
),
|
|
||||||
'authenticated' => $authenticated,
|
|
||||||
'api_mode' => $api_mode,
|
|
||||||
'methods' => $methods,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
elseif ($override) {
|
|
||||||
Log :: debug(
|
Log :: debug(
|
||||||
"URL : override pattern '%s' with handler '%s' (old handler = '%s')".
|
"URL : overwrite pattern '%s' with handler '%s' (old handler = '%s')".
|
||||||
$pattern, format_callable($handler), vardump(self :: $patterns[$pattern])
|
$pattern, format_callable($handler), vardump(self :: $patterns[$pattern])
|
||||||
);
|
);
|
||||||
self :: $patterns[$pattern] = array(
|
self :: $patterns[$pattern] = array(
|
||||||
|
@ -134,11 +130,10 @@ class Url {
|
||||||
'api_mode' => $api_mode,
|
'api_mode' => $api_mode,
|
||||||
'methods' => $methods,
|
'methods' => $methods,
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
Log :: debug("URL : pattern '$pattern' already defined : do not overwrite.");
|
||||||
Log :: debug("URL : pattern '$pattern' already defined : do not override.");
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,3 +99,6 @@
|
||||||
{if $webstats_js_code}{$webstats_js_code}{/if}
|
{if $webstats_js_code}{$webstats_js_code}{/if}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
|
@ -2,3 +2,6 @@
|
||||||
{block name="content"}
|
{block name="content"}
|
||||||
<p class="center">{$message}</p>
|
<p class="center">{$message}</p>
|
||||||
{/block}
|
{/block}
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
|
@ -7,3 +7,6 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/block}
|
{/block}
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
|
@ -8,3 +8,6 @@
|
||||||
|
|
||||||
<div class="center"><a href="javascript:history.back()" class="btn btn-primary"><i class="fa fa-undo"></i> {t domain=$CORE_TEXT_DOMAIN}Back{/t}</a></div>
|
<div class="center"><a href="javascript:history.back()" class="btn btn-primary"><i class="fa fa-undo"></i> {t domain=$CORE_TEXT_DOMAIN}Back{/t}</a></div>
|
||||||
{/block}
|
{/block}
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
|
@ -6,3 +6,6 @@
|
||||||
<p class="lead">{t escape=off domain=$CORE_TEXT_DOMAIN}This is the default page of a new app using EesyPHP framework. Register your own templates directory and create a <em>homepage.tpl</em> file to overwrite it. You could also overwrite the URL handler for the root of the web application.{/t}</p>
|
<p class="lead">{t escape=off domain=$CORE_TEXT_DOMAIN}This is the default page of a new app using EesyPHP framework. Register your own templates directory and create a <em>homepage.tpl</em> file to overwrite it. You could also overwrite the URL handler for the root of the web application.{/t}</p>
|
||||||
</div>
|
</div>
|
||||||
{/block}
|
{/block}
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
|
@ -7,3 +7,6 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/block}
|
{/block}
|
||||||
|
{*
|
||||||
|
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||||
|
*}
|
||||||
|
|
Loading…
Reference in a new issue