OOP Class Can someonehelp me?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fantomel
Forum Newbie
Posts: 3
Joined: Sun Oct 19, 2008 5:13 pm

OOP Class Can someonehelp me?

Post 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
    }
}
 
?>
Last edited by Benjamin on Thu May 07, 2009 11:37 am, edited 1 time in total.
Reason: Changed code type from text to php.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: OOP Class Can someonehelp me?

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: OOP Class Can someonehelp me?

Post by jaoudestudios »

For starters I would not use var, use private/protected/public
fantomel
Forum Newbie
Posts: 3
Joined: Sun Oct 19, 2008 5:13 pm

Re: OOP Class Can someonehelp me?

Post 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.
Last edited by Benjamin on Thu May 07, 2009 11:38 am, edited 1 time in total.
Reason: Removed quoted code already posted.
Post Reply