Compare commits
No commits in common. "c90032486020f317a0eb2d25b9fdb6ba4ad21f91" and "9cc0f8581adda394aa2439a4180742bdafb44158" have entirely different histories.
c900324860
...
9cc0f8581a
7 changed files with 35 additions and 48 deletions
65
src/Url.php
65
src/Url.php
|
@ -79,14 +79,13 @@ class Url {
|
|||
* authenticated users (optional, default: true if the
|
||||
* special force_authentication function is defined,
|
||||
* false otherwise)
|
||||
* @param boolean $overwrite Allow overwrite if a command already exists with the
|
||||
* @param boolean $override Allow override if a command already exists with the
|
||||
* same name (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'))
|
||||
* @return bool
|
||||
**/
|
||||
public static function add_url_handler($pattern, $handler=null, $additional_info=null,
|
||||
$authenticated=null, $overwrite=true, $api_mode=false,
|
||||
$authenticated=null, $override=true, $api_mode=false,
|
||||
$methods=null) {
|
||||
$authenticated = (
|
||||
is_null($authenticated)?
|
||||
|
@ -98,42 +97,48 @@ class Url {
|
|||
elseif (!is_array($methods))
|
||||
$methods = array($methods);
|
||||
if (is_array($pattern)) {
|
||||
$error = false;
|
||||
if (is_null($handler))
|
||||
foreach($pattern as $p => $h)
|
||||
if (
|
||||
!self :: add_url_handler(
|
||||
$p, $h, $additional_info, $authenticated, $overwrite, $api_mode, $methods)
|
||||
) $error = true;
|
||||
self :: add_url_handler(
|
||||
$p, $h, $additional_info, $authenticated, $override, $api_mode, $methods);
|
||||
else
|
||||
foreach($pattern as $p)
|
||||
if (
|
||||
!self :: add_url_handler(
|
||||
$p, $handler, $additional_info, $authenticated, $overwrite, $api_mode, $methods)
|
||||
) $error = true;
|
||||
return !$error;
|
||||
self :: add_url_handler(
|
||||
$p, $handler, $additional_info, $authenticated, $override, $api_mode, $methods);
|
||||
}
|
||||
|
||||
if (!isset(self :: $patterns[$pattern]) || $overwrite) {
|
||||
if (isset(self :: $patterns[$pattern]))
|
||||
else {
|
||||
if (!isset(self :: $patterns[$pattern])) {
|
||||
self :: $patterns[$pattern] = array(
|
||||
'handler' => $handler,
|
||||
'additional_info' => (
|
||||
is_array($additional_info)?
|
||||
$additional_info:array()
|
||||
),
|
||||
'authenticated' => $authenticated,
|
||||
'api_mode' => $api_mode,
|
||||
'methods' => $methods,
|
||||
);
|
||||
}
|
||||
elseif ($override) {
|
||||
Log :: debug(
|
||||
"URL : overwrite pattern '%s' with handler '%s' (old handler = '%s')".
|
||||
"URL : override pattern '%s' with handler '%s' (old handler = '%s')".
|
||||
$pattern, format_callable($handler), vardump(self :: $patterns[$pattern])
|
||||
);
|
||||
self :: $patterns[$pattern] = array(
|
||||
'handler' => $handler,
|
||||
'additional_info' => (
|
||||
is_array($additional_info)?
|
||||
$additional_info:array()
|
||||
),
|
||||
'authenticated' => $authenticated,
|
||||
'api_mode' => $api_mode,
|
||||
'methods' => $methods,
|
||||
);
|
||||
return true;
|
||||
self :: $patterns[$pattern] = array(
|
||||
'handler' => $handler,
|
||||
'additional_info' => (
|
||||
is_array($additional_info)?
|
||||
$additional_info:array()
|
||||
),
|
||||
'authenticated' => $authenticated,
|
||||
'api_mode' => $api_mode,
|
||||
'methods' => $methods,
|
||||
);
|
||||
}
|
||||
else {
|
||||
Log :: debug("URL : pattern '$pattern' already defined : do not override.");
|
||||
}
|
||||
}
|
||||
Log :: debug("URL : pattern '$pattern' already defined : do not overwrite.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,6 +99,3 @@
|
|||
{if $webstats_js_code}{$webstats_js_code}{/if}
|
||||
</body>
|
||||
</html>
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
|
@ -2,6 +2,3 @@
|
|||
{block name="content"}
|
||||
<p class="center">{$message}</p>
|
||||
{/block}
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
|
@ -7,6 +7,3 @@
|
|||
</div>
|
||||
{/if}
|
||||
{/block}
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
|
@ -8,6 +8,3 @@
|
|||
|
||||
<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}
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
|
@ -6,6 +6,3 @@
|
|||
<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>
|
||||
{/block}
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
|
@ -7,6 +7,3 @@
|
|||
</div>
|
||||
{/if}
|
||||
{/block}
|
||||
{*
|
||||
# vim: autoindent expandtab tabstop=2 shiftwidth=2 softtabstop=2
|
||||
*}
|
||||
|
|
Loading…
Reference in a new issue