OOP Class Can someonehelp me?
Posted: Thu May 07, 2009 3:39 am
Hello guys i'm new to oop so i'm playing a little with it. Can please someone check my class test it a little bit look over the functions see if they will work how it should? Please
Code: Select all
<?php
class Front
{
var $controllerName;
var $controller;
var $action;
var $url;
var $urlArray;
var $QueryString;
var $value;
/**
* Our construct method.
* @return
*/
function __construct()
{
$this->SetReporting();
$this->RemoveMagicQuotes();
$this->UnregisterGlobals();
}
/**
* This function allows us to create a routing system.
* @return
* @param object $url
*/
private function routeURL($url)
{
global $routing;
foreach ( $routing as $pattern => $result)
{
if ( preg_match($pattern, $url))
return preg_replace($pattern, $result, $url);
}
return ($url);
}
/**
*
* This function is for $_GET['url'] option.
* It take the $url and tries to load the requested controller.
* @return
*/
private function GetControllers()
{
global $url;
global $default;
$QueryString = array();
if(!isset($url))
{
$controller = $default['controller'];
$action = $default['action'];
}
else
{
$url = routeURL($url);
$urlArray = array();
$urlArray = explode("/", $url);
$controller = $urlArray[0];
array_shift($urlArray);
if( isset($urlArray[0]))
{
$action = $urlArray[0];
array_shift($urlArray);
}
else
{
$action = 'index'; // Default Action
}
$QueryString = $urlArray;
$controllerName = ucfirst($controller) . 'Controller';
$dispatch = new $controllerName($controller, $action);
if ((int)method_exists($controllerName, $action))
{
call_user_func_array(array($dispatch, $action), $QueryString);
}
else
{
/* Error Code Here */
}
}
}
/**
*
* Sets your development enviorment
* @return
*/
private function SetReporting()
{
if (DEV == true)
{
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
else
{
error_reporting(E_ALL);
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
ini_set('error_log', '../tmp/logs/error.log');
}
}
/**
* It does what it says
* @return
*/
private function UnregisterGlobals()
{
if (ini_get('register_globals'))
{
$array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
foreach ($GLOBALS[$value] as $key => $var)
{
if ($var === $GLOBALS[$value])
unset($GLOBALS[$key]);
}
}
}
/**
* This two functions didn't work well and i've did in onther way.
*
* private function StripSlashesDeep($value)
* {
* $value = is_array($value) ? array_map('StripSlashesDeep', $value) : stripslashes($value);
*
* return $value;
* }
*
* private function RemoveMagicQuotes()
* {
* if ( get_magic_quotes_gpc())
* {
* $_GET = StripSlashesDeep($_GET);
* $_POST = StripSlashesDeep($_POST);
* $_COOKIE = StripSlashesDeep($_COOKIE);
* }
* }
* @return
* @param object $arr
*/
/**
*
* StripSlashesDeep() and RemoveMagicQuotes this two functions are for securing the site.
* @return
* @param object $arr
*/
private function stripslashesdeep($arr)
{
if (is_array($arr))
{
array_map('stripslashes', $arr);
}
}
private function RemoveMagicQuotes()
{
if (get_magic_quotes_gpc())
{
$this->stripslashesdeep($_GET);
$this->stripslashesdeep($_POST);
$this->stripslashesdeep($_COOKIE);
}
}
/**
*
*/
function __destruct()
{
//TODO Auto generated method stub
}
}
?>