Page 1 of 1

OOP Class Can someonehelp me?

Posted: Thu May 07, 2009 3:39 am
by fantomel
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
    }
}
 
?>

Re: OOP Class Can someonehelp me?

Posted: Thu May 07, 2009 6:46 am
by mickd
Was there an error (or did it run fine)? Or did you want comments on if it was designed well with OOP in mind?

Re: OOP Class Can someonehelp me?

Posted: Thu May 07, 2009 7:09 am
by jaoudestudios
For starters I would not use var, use private/protected/public

Re: OOP Class Can someonehelp me?

Posted: Thu May 07, 2009 7:20 am
by fantomel
fantomel wrote: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
as far as i can tell you i didn't had any errors i'm interested in the part if it was designed well with oop in mind and tested those functions removemagicquotes(), stripslashesdeep unregisterglobals() and setreporting() :) to see if they work as it should(the oppinion from someone who has more experience in oop and php);.

For starters I would not use var, use private/protected/public
thank you for your advice i will change the code.