[
class tree: tangra_lib
] [
index: tangra_lib
] [
all elements
]
tangra_lib
Packages:
tangra_lib
Source for file redirect_composer_local.class.php
Documentation is available at
redirect_composer_local.class.php
<?php
// *** Tangra (Application Framework and Tools for PHP)
// $Id$
//
/**
* Contains class Redirect_Composer_Local
*
*
@package
tangra_lib
*
@subpackage
web_site
*/
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'web_site/web_context.class.php'
)
;
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'exceptions/te_key_already_exists.class.php'
)
;
/**
*
*/
require_once
(
'redirect_composer.class.php'
)
;
/**
* Redirect_Composer_Local is intended to be used for internal redirect within site
*
*
@see
Redirect_Composer
*
@package
tangra_lib
*
@subpackage
web_site
*/
class
Redirect_Composer_Local
extends
Redirect_Composer
{
/**
* Holds Web_Context
*
*
@var
Web_Context
*/
private
$_context
;
/**
*
* Holds protocol: http, https or ''
* '' (empty) value means keep current
*
@var
string
*/
private
$protocol
;
/**
*
* Holds port that will be used for composing
*
@var
integer
*/
private
$port
;
/**
* Constructor
*
*
@param
string
$target
Target address
*
@param
array
$param_pairs
Parameters that will be added to target address ($key => $value pairs)
*
@throws
Tangra_Exception
*/
function
__construct
(
Web_Context
$context
,
$target
,
$param_pairs
=
array
(
)
,
$protocol
=
''
,
$port
=
0
)
{
$this
->
set_context
(
$context
)
;
parent
::
__construct
(
$target
,
$param_pairs
)
;
$this
->
set_protocol
(
$protocol
)
;
$this
->
set_port
(
$port
)
;
}
/**
* Sets context
*
*
@param
Web_Context
$context
*
@internal
*/
private
function
set_context
(
Web_Context
$context
)
{
$this
->
_context
=
$context
;
}
/**
* Returns reference to context
*
*
@return
Web_Context
*/
public
function
get__context
(
)
{
return
$this
->
_context
;
}
/**
*
* Sets protocol.
*
@param
string
$protocol
Valid values are http, https and '' (empty). Empty value means "use current" (autodetected)
*
@throws
Tangra_Expception
*/
public
function
set_protocol
(
$protocol
)
{
if
(
$protocol
==
''
||
$protocol
==
'http'
||
$protocolo
==
'https'
)
{
$this
->
protocol
=
$protocol
;
}
else
{
throw
new
Tangra_Expception
(
'Invalid protocol value. Must be "http", "https" or empty. Current value: '
.
$protocol
)
;
}
}
/**
*
* Returns $protocol
*/
public
function
get_protocol
(
)
{
return
$this
->
protocol
;
}
/**
*
* Sets port to be used when composing
* Valid values:
* integer - sets port to specified value
* 0 - "use current" (autodetected)
* NULL - sets port to NULL which means don't set port when composing
*
@param
integer
$port
*/
public
function
set_port
(
$port
=
0
)
{
if
(
$port
)
{
tangra_if_not_int_throw_e
(
$port
)
;
}
$this
->
port
=
$port
;
}
/**
*
* Returns port
*/
public
function
get_port
(
)
{
return
$this
->
port
;
}
/**
* Returns composed target address with parameters
*
*
@param
Web_Context
$context
*
@return
string
*/
public
function
get_target_address
(
)
{
$context
=
$this
->
get__context
(
)
;
$this
->
add_threads_manager_var
(
$context
)
;
$server
=
$context
->
get_from_server
(
'SERVER_NAME'
)
;
$port
=
$this
->
get_port
(
)
;
$protocol
=
$this
->
get_protocol
(
)
;
if
(
!
$protocol
)
{
if
(
$context
->
exists_in_server
(
'HTTPS'
))
{
$https
=
$context
->
get_from_server
(
'HTTPS'
)
;
}
else
{
$https
=
false
;
}
$protocol
=
(
$https
)
?
'https'
:
'http'
;
}
if
(
is_null
(
$port
))
{
$port
=
''
;
}
elseif
(
$port
==
0
)
{
$port
=
$context
->
get_from_server
(
'SERVER_PORT'
)
;
if
((
$port
==
'80'
&&
$protocol
==
'http'
)
||
(
$port
==
'443'
&&
$protocol
==
'https'
))
{
$port
=
''
;
}
else
{
$port
=
':'
.
$port
;
}
}
else
{
$port
=
':'
.
$port
;
}
$params
=
$this
->
get_params
(
)
;
$pi_vars
=
$this
->
get_pi_string
(
)
;
if
(
substr
(
$this
->
get_target
(
)
,
-
1
)
==
'/'
)
{
$ret
=
$protocol
.
'://'
.
$server
.
$port
.
'/'
.
$this
->
get_target
(
)
.
$pi_vars
.
$params
;
}
else
{
$ret
=
$protocol
.
'://'
.
$server
.
$port
.
'/'
.
$this
->
get_target
(
)
.
'/'
.
$pi_vars
.
$params
;
}
return
$ret
;
}
/**
* Adds threads manager var to parameters
*
*
@param
Web_Context
$context
*
@internal
*/
private
function
add_threads_manager_var
(
Web_Context
$context
)
{
if
(
defined
(
'THREADS_MANAGER_NAME'
))
{
$svm_var_name
=
Session_Vars_Manager
::
get_svm_var_name
(
)
;
$svm
=
$context
->
get_from_session
(
$svm_var_name
)
;
if
(
$svm
->
is_global_var_registered
(
THREADS_MANAGER_NAME
))
{
$tm
=
$svm
->
get_global_var
(
THREADS_MANAGER_NAME
)
;
// removing if already exists. Needed in case of login redirect or in case of user mistakes
if
(
$this
->
param_exists
(
THREADS_MANAGER_NAME
))
{
$this
->
remove_param
(
THREADS_MANAGER_NAME
)
;
}
$this
->
add_param_pair
(
$tm
->
get_url_rewrite_var_name
(
)
,
$tm
->
get_current_url_var
(
))
;
}
}
}
private
function
get_pi_string
(
)
{
$ret
=
''
;
if
(
function_exists
(
'_get_pi_string'
))
{
$ret
=
_get_pi_string
(
)
;
}
return
$ret
;
}
}