[
class tree: tangra_lib
] [
index: tangra_lib
] [
all elements
]
tangra_lib
Packages:
tangra_lib
Source for file web_site_config.class.php
Documentation is available at
web_site_config.class.php
<?php
// *** Tangra (Application Framework and Tools for PHP)
// $Id$
//
/**
* Contains class Web_Site_Config
*
*
@package
tangra_lib
*
@subpackage
web_site
*/
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'core/misc_functions.inc.php'
)
;
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'exceptions/te_web_site_config_error.class.php'
)
;
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'filesystem_toolbox/filesystem_functions.inc.php'
)
;
/**
* Basic web site configuration
*
*
@package
tangra_lib
*
@subpackage
web_site
*/
abstract
class
Web_Site_Config
extends
Tangra_Class
{
/**
* Development mode
*
*/
const
SITE_MODE_DEVELOPMENT
=
0
;
/**
* Production mode
*
*/
const
SITE_MODE_PRODUCTION
=
1
;
/**
* Site system name
*
*
@var
string
*
@internal
*/
private
$site_name
;
/**
* Site's root absolute path. It is not docroot, see bellow!
*
*
@var
string
*
@internal
*/
private
$root_dir
;
/**
* Document root absolute path
*
*
@var
string
*
@internal
*/
private
$document_root_dir
;
/**
* Document root relative to $document_root_dir
*
*
@var
string
*
@internal
*/
private
$document_root_relative
;
/**
* "Hidden" dir absolute path
*
*
@var
string
*
@internal
*/
private
$hidden_dir
;
//hidden absolute path
/**
* "Scratch" dir absolute path
*
*
@var
string
*
@internal
*/
private
$scratch_dir
;
/**
* ext_inc dir absolute path
*
*
@var
string
*
@internal
*/
private
$ext_inc_dir
;
/**
* Default encoding for the site
*
*
@var
string
*
@internal
*/
private
$default_encoding
;
/**
* Address of server error page
*
*
@var
string
*
@internal
*/
private
$server_error_page
=
'server_error.php'
;
/**
* Error reporting level
* Default is 4095
*
*
@var
integer
*
@internal
*/
private
$error_reporting
=
4095
;
/**
* Error reporting for PHP4 libs
* Default is 2047
*
*
@var
integer
*
@internal
*/
private
$error_reporting_php4_libs
=
2047
;
/**
* Site mode
*
*
@var
integer
*
@internal
*/
private
$site_mode
=
Web_Site_Config
::
SITE_MODE_DEVELOPMENT
;
/**
* Current hostname
*
*
@var
string
*
@internal
*/
private
$current_host
;
/**
* Current port
*
*
@var
integer
*
@internal
*/
private
$current_port
;
/**
* Current protocol
*
*
@var
string
*
@internal
*/
private
$current_protocol
;
/**
* Base URL
*
*
@var
string
*
@internal
*/
private
$base_url
;
/**
* Shall tangra be exposed as http header like X-Powered-By: Tangra Framework for PHP/2.*
*
*
@var
unknown_type
*/
private
$expose_tangra
;
/**
* Used to distigush installations on different servers.
* This is free form string
*/
private
$instance_name
;
/**
* Sets site name
*
*
@param
string
$site_name
*/
public
function
set_site_name
(
$site_name
)
{
$site_name
=
trim
(
$site_name
)
;
$this
->
site_name
=
$site_name
;
}
/**
* Gets site name
*
*
@return
unknown
*/
public
function
get_site_name
(
)
{
return
$this
->
site_name
;
}
/**
* Sets site's root directory absolute path. It is not docroot, see bellow!
*
*
@param
string
$root_dir
*/
public
function
set_root_dir
(
$root_dir
)
{
$root_dir
=
trim
(
$root_dir
)
;
if
(
tangra_dir_exists
(
$root_dir
))
{
$this
->
root_dir
=
tangra_normalize_path
(
$root_dir
)
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid $root_dir (MS_root_dir). Not exists or is not a dir. Current value: '
.
$root_dir
)
;
}
}
/**
* Returns site's root directory absolute path
*
*
@return
unknown
*/
public
function
get_root_dir
(
)
{
return
$this
->
root_dir
;
}
/**
* Sets document root absolute path
*
*
@param
string
$document_root_dir
*/
public
function
set_document_root_dir
(
$document_root_dir
=
NULL
)
{
if
(
$document_root_dir
!=
NULL
)
{
$this
->
_set_document_root_dir
(
$document_root_dir
)
;
}
else
{
$this
->
_set_document_root_dir
(
$this
->
get_root_dir
(
)
.
'/htdocs/'
)
;
}
}
/**
* Sets document root absolute path
*
*
@param
unknown_type
$document_root_dir
*
@internal
*
@throws
TE_Web_Site_Config_Error
*/
private
function
_set_document_root_dir
(
$document_root_dir
)
{
if
(
tangra_dir_exists
(
$document_root_dir
))
{
$this
->
document_root_dir
=
tangra_normalize_path
(
$document_root_dir
)
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid document_root_dir (MS_DOCUMENT_root_dir). Not exists or is not a dir. Current value: '
.
document_root_dir
)
;
}
}
/**
* Returns document root absolute path
*
*
@return
string
*/
public
function
get_document_root_dir
(
)
{
return
$this
->
document_root_dir
;
}
/**
* Alias of set_document_root_dir()
*
*
@param
string
$document_root_dir
*/
public
function
set_htdocs_dir
(
$document_root_dir
=
NULL
)
{
$this
->
set_document_root_dir
(
$document_root_dir
)
;
}
/**
* Alias of get_document_root_dir();
*
*
@return
string
*/
public
function
get_htdocs_dir
(
)
{
return
$this
->
get_document_root_dir
(
)
;
}
/**
* Sets hidden dir absolute path
*
*
@param
string
$hidden_dir
*/
public
function
set_hidden_dir
(
$hidden_dir
=
NULL
)
{
if
(
$hidden_dir
!=
NULL
)
{
$this
->
_set_hidden_dir
(
$hidden_dir
)
;
}
else
{
$this
->
_set_hidden_dir
(
$this
->
get_root_dir
(
)
.
'/hidden/'
)
;
}
}
/**
* Sets hidden dir absolute path
*
*
@param
string
$hidden_dir
*
@internal
*
@throws
TE_Web_Site_Config_Error
*/
private
function
_set_hidden_dir
(
$hidden_dir
)
{
if
(
tangra_dir_exists
(
$hidden_dir
))
{
$this
->
hidden_dir
=
tangra_normalize_path
(
$hidden_dir
)
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid $hidden_dir (MS_hidden_dir). Not exists or is not a dir. Current value: '
.
$hidden_dir
)
;
}
}
/**
* Returns hidden dir absolute path
*
*
@return
string
*/
public
function
get_hidden_dir
(
)
{
return
$this
->
hidden_dir
;
}
/**
* Sets scratch dir absolute path
*
*
@param
string
$scratch_dir
*/
public
function
set_scratch_dir
(
$scratch_dir
=
NULL
)
{
if
(
$scratch_dir
!=
NULL
)
{
$this
->
_set_scratch_dir
(
$scratch_dir
)
;
}
else
{
$this
->
_set_scratch_dir
(
$this
->
get_root_dir
(
)
.
'/scratch/'
)
;
}
}
/**
* Sets scratch dir absolute path
*
*
@param
string
$scratch_dir
*
@throws
TE_Web_Site_Config_Error
*/
private
function
_set_scratch_dir
(
$scratch_dir
)
{
if
(
tangra_dir_exists
(
$scratch_dir
))
{
$this
->
scratch_dir
=
tangra_normalize_path
(
$scratch_dir
)
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid $scratch_dir (MS_scratch_dir). Not exists or is not a dir. Current value: '
.
$scratch_dir
)
;
}
}
/**
* Returns scratch dir absolute path
*
*
@return
string
*/
public
function
get_scratch_dir
(
)
{
return
$this
->
scratch_dir
;
}
/**
* Sets ext_inc dir absolute path
*
*
@param
string
$ext_inc_dir
*/
public
function
set_ext_inc_dir
(
$ext_inc_dir
=
NULL
)
{
if
(
$ext_inc_dir
!=
NULL
)
{
$this
->
_set_ext_inc_dir
(
$ext_inc_dir
)
;
}
else
{
$this
->
_set_ext_inc_dir
(
$this
->
get_root_dir
(
)
.
'/ext_inc/'
)
;
}
}
/**
* Sets ext_inc dir absolute path
*
*
@param
string
$ext_inc_dir
*
@throws
TE_Web_Site_Config_Error
*/
private
function
_set_ext_inc_dir
(
$ext_inc_dir
)
{
if
(
tangra_dir_exists
(
$ext_inc_dir
))
{
$this
->
ext_inc_dir
=
tangra_normalize_path
(
$ext_inc_dir
)
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid $ext_inc_dir (MS_ext_inc_dir). Not exists or is not a dir. Current value: '
.
$ext_inc_dir
)
;
}
}
/**
* Returns ext_inc dir absolute path
*
*
@return
string
*/
public
function
get_ext_inc_dir
(
)
{
return
$this
->
ext_inc_dir
;
}
/**
* Sets default encoding for the site
* Example: set_default_encoding('utf-8');
*
*
@param
string
$default_encoding
*/
public
function
set_default_encoding
(
$default_encoding
)
{
//TODO - check against list of valid encodings
$this
->
default_encoding
=
$default_encoding
;
}
/**
* Returns default encoding of the site
*
*
@return
string
*/
public
function
get_default_encoding
(
)
{
return
$this
->
default_encoding
;
}
/**
* Returns boot dir
*
*
@return
string
*/
public
function
get_boot_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'boot/'
;
}
/**
* Returns conf dir
*
*
@return
string
*/
public
function
get_conf_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'conf/'
;
}
/**
* Returns cron_jobs dir
*
*
@return
string
*/
public
function
get_cron_jobs_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'cron_jobs/'
;
}
/**
* Returns site include dir
*
*
@return
string
*/
public
function
get_site_inc_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'inc/'
;
}
/**
* Alias of get_site_inc_dir()
*
*
@return
string
*/
public
function
get_inc_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'inc/'
;
}
/**
* Alias of get_site_inc_dir
*
*
@return
string
*/
public
function
get_sid
(
)
{
return
$this
->
get_site_inc_dir
(
)
;
}
/**
* Returns rc.d directory
*
*
@return
string
*/
public
function
get_rc_d_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'rc.d/'
;
}
/**
* Returns templates directory
*
*
@return
string
*/
public
function
get_tpl_dir
(
)
{
return
$this
->
get_hidden_dir
(
)
.
'tpl/'
;
}
/**
* Returns DB directory
*
* (For sqlite, if used)
*
*
@return
string
*/
public
function
get_db_dir
(
)
{
return
$this
->
get_scratch_dir
(
)
.
'db/'
;
}
/**
* Returns logs directory
*
*
@return
string
*/
public
function
get_logs_dir
(
)
{
return
$this
->
get_scratch_dir
(
)
.
'logs/'
;
}
/**
* Returns templates scratch directory
*
*
@return
string
*/
public
function
get_scratch_tpl_dir
(
)
{
return
$this
->
get_scratch_dir
(
)
.
'tpl/'
;
}
/**
* Return uplaods dir
*
*
@return
string
*/
public
function
get_uploads_dir
(
)
{
return
$this
->
get_scratch_dir
(
)
.
'uploads/'
;
}
/**
* Return debug dir
*
*
@return
string
*/
public
function
get_debug_dir
(
)
{
return
$this
->
get_scratch_dir
(
)
.
'debug/'
;
}
/**
* Sets document root relative directory (relative to document root (set with set_root_dir()))
*
*
@param
string
$document_root_relative
*/
public
function
set_document_root_relative
(
$document_root_relative
)
{
if
(
$document_root_relative
)
{
$this
->
document_root_relative
=
$document_root_relative
;
}
else
{
$this
->
document_root_relative
=
'/'
;
}
}
/**
* Gets document root relative directory
*
*
@return
string
*/
public
function
get_document_root_relative
(
)
{
return
$this
->
document_root_relative
;
}
/**
* Sets server error page address
*
*
@param
string
$server_error_page
*/
public
function
set_server_error_page
(
$server_error_page
)
{
$this
->
server_error_page
=
$server_error_page
?
$server_error_page
:
'server_error.php'
;
}
/**
* Returns server error page address
*
*
@return
string
*/
public
function
get_server_error_page
(
)
{
return
$this
->
server_error_page
;
}
/**
* Sets error reporting level
*
*
@param
integer
$error_reporting
*
@throws
TE_Web_Site_Config_Error
*/
public
function
set_error_reporting
(
$error_reporting
)
{
if
(
tangra_is_int
(
$error_reporting
))
{
$this
->
error_reporting
=
$error_reporting
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid value for $error_reporting. Must be integer. Current value: '
.
$err
)
;
}
}
/**
* Returns error_reporting level
*
*
@return
integer
*/
public
function
get_error_reporting
(
)
{
return
$this
->
error_reporting
;
}
/**
* Sets error reporting for PHP4 libraries
*
*
@param
integer
$error_reporting
*/
public
function
set_error_reporting_php4_libs
(
$error_reporting
)
{
if
(
tangra_is_int
(
$error_reporting
))
{
$this
->
error_reporting_php4_libs
=
$error_reporting
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid value for $error_reporting_php4_libs. Must be integer. Current value: '
.
$err
)
;
}
}
/**
* Returns error reporting for PHP4 libraries
*
*
@return
integer
*/
public
function
get_error_reporting_php4_libs
(
)
{
return
$this
->
error_reporting_php4_libs
;
}
/**
* Sets site mode
*
* Web_Site_Config::SITE_MODE_DEVELOPMENT or Web_Site_Config::SITE_MODE_PRODUCTION
*
*
@param
integer
$site_mode
*/
public
function
set_site_mode
(
$site_mode
)
{
if
(
$site_mode
==
Web_Site_Config
::
SITE_MODE_DEVELOPMENT
||
$site_mode
==
Web_Site_Config
::
SITE_MODE_PRODUCTION
)
{
$this
->
site_mode
=
$site_mode
;
}
else
{
throw
new
TE_Web_Site_Config_Error
(
'Invalid value for $site_mode. Current value: '
.
$site_mode
)
;
}
}
/**
* Returns site mode
*
*
@return
integer
*/
public
function
get_site_mode
(
)
{
return
$this
->
site_mode
;
}
/**
* Sets current hostname
*
*
@param
string
$current_host
*/
public
function
set_current_host
(
$current_host
)
{
$this
->
current_host
=
$current_host
;
}
/**
* Returns current hostname
*
*
@return
string
*/
public
function
get_current_host
(
)
{
return
$this
->
current_host
;
}
/**
* Sets current port
*
*
@param
integer
$current_port
*/
public
function
set_current_port
(
$current_port
)
{
tangra_if_not_int_throw_e
(
$current_port
)
;
$this
->
current_port
=
$current_port
;
}
/**
* Returns current port
*
*
@return
integer
*/
public
function
get_current_port
(
)
{
return
$this
->
current_port
;
}
/**
* Sets current protocol
*
*
@param
string
$current_protocol
*/
public
function
set_current_protocol
(
$current_protocol
)
{
$this
->
current_protocol
=
$current_protocol
;
}
/**
* Returns current protocol
*
*
@return
unknown
*/
public
function
get_current_protocol
(
)
{
return
$this
->
current_protocol
;
}
/**
* Sets base URL
*
*
@param
string
$base_url
*/
public
function
set_base_url
(
$base_url
)
{
$this
->
base_url
=
$base_url
;
}
/**
* Returns base URL
*
*
@return
string
*/
public
function
get_base_url
(
)
{
return
$this
->
base_url
;
}
/**
* Sets instance name
*
*
@param
string
$instance_name
*/
public
function
set_instance_name
(
$instance_name
)
{
$this
->
instance_name
=
$instance_name
;
}
/**
* Returns instance name
*
*
@return
string
*/
public
function
get_instance_name
(
)
{
return
$this
->
instance_name
;
}
/**
* Sets expose tangra flag. If true http header like X-Powered-By: Tangra Framework for PHP/2.* will be generated
*
*
@param
boolean
$expose_tangra
*/
public
function
set_expose_tangra
(
$expose_tangra
)
{
$this
->
expose_tangra
=
$expose_tangra
?
true
:
false
;
}
/**
* Returns expose tangra flag
*
*
@return
boolean
*/
public
function
get_expose_tangra
(
)
{
return
$this
->
expose_tangra
;
}
// public function set_($) {
// $this-> = $;
// }
//
//
// public function get_() {
// return $this->;
// }
}