Activity Stream
48,167 MEMBERS
61357 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default Advanced PHP (Registry System) - Guide/Tutorial

    Heya everyone,

    Introduction

    What you will learning to day is how to create a registry type of system for your "Framwork/Website" and how it will help you to manage all of your objects.

    What is a Registry you say?
    A registry is a class that will be used to hold other classes in an array/stdClass and create a type of "SperGlobal" for your script.

    The Steps.
    1. 1. Create index.php
    2. 2. Create create a bootloader
    3. 3. Create the registry
    4. 4. Create create some sub-classes
    5. 5. Use sub-class via registry


    Step 1. (Create index.php)

    The index.php is extreamy simple to create as this is the just an output file so to speak.... its the very first file that initiates the core logic and is what files you will be creating for new pages on your site.. this is why it has to be simple.

    PHP Code: 
    <?php

    /*
    **
    *** First lets create a constant that we will be using for 2 main things.
    *** 1. Used for security
    *** 2. Used to help know where we am on the filesystem.
    *** E.G. of the value is /root/sites/mySite/htdocs/
    **
    */

    define("APPLICATION_PATH" str_replace("\\","/",dirname(__FILE__)) . "/");

    /*
    **
    *** No lets include the bootloader file
    **
    */
    require_once APPLICATION_PATH "system/boot.php";
    ?>
    Step 2. (Create the bootloader)

    What the bootloader will be doing in this "system" is
    1. 1. including all the main class files[/*]
    2. 2. Creating an instance of the registry object[/*]
    3. 3. Creating an instance of other objects and adding to the registry.[/*]


    Create a new directory next to "index.php" and call it system.. after that just create a new php document and call it "boot.php"

    PHP Code: 
    <?php

    /*
    **
    *** In step one we created a constant called APPLICATION_PATH.
    *** Now a smarty security check is to make sure that constant is set.
    *** This will stope hackers from directly accessing the file from the browser.
    *** So we just make sure that the APPLICATION_PATH is in the scope
    **
    */

    if(!defined("APPLICATION_PATH")){ die("No DIRECT Access"); }

    /*
    **
    *** Now at this point we can start including our files, and creating the objects etc.
    *** The first object were going to be including is the regsitry object.
    **
    */

    require_once APPLICATION_PATH "system/includes/classes/registry.php";

    /*
    **
    *** As the object will be a "static" class we wont need to create an instance of the object
    **
    */
    ?>
    At a later date in the script we will add more includes etc to the bootloader but nothing for now
    [*]3. (Create the registry)[/*]
    Firstly we nned to create a 2 new directories and a new php file so

    1st. create a directory in "system" called "includes" and then within includes called "classes" so we have this structure "system/includes/classes/"

    2nd. Create a new php file called Registry.php with capital R for consistancy.

    lets take a look at the Regsitry class now
    PHP Code: 
    <?php

    /*
    **
    *** The registry class contains 2 "Magic Methods" and one object holder
    *** Tip: if your not sure about magic methods, please look at Stephans videos on PHP6
    *** http://killerphp.com/tutorials/advanced-php/
    *** Lets create the object now
    **
    */

    class Registry{
        
        
    /*
        **
        *** The $objects variable will contain all the classes/variables/data
        **
        */
        
    var $objects = array();

        
    /*
        **
        *** The __constructor method will run when the class is first created
        *** Please not that in the constructor it should take 0 args if posible
        **
        */
        
    public function __construct(){
        }
        
        
    /*
        **
        *** The __set magic method will be used to add new objects to the $objects
        *** (http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members)
        **
        */
        
        
    public function __set($index,$value){
            
    $this->objects[$index] = $value;
        }
        
        
    /*
        **
        *** The magic method __get will be used when were trying to pull objects from the storage variable
        **
        */
        
        
    public function __get($index){
            return 
    $this->objects[$index];
        }
        
        
    /*
        **
        *** The magic methos sleep and wake are used to compress the data when there not being used, this helps save system
        *** Resources if your Registry gets on the larger side.
        **
        */
        
        
    function __sleep(){ /*serialize on sleep*/
            
    $this->objects serialize($this->objects);
        }
        function 
    __wake(){ /*un serialize on wake*/
            
    $this->$objects unserialize($this->objects);
        }
    }
    ?>
    Ok so the basic outlay of the Registry is like a big box... and this box floats in mid air "so to speak" the reason its a box is because you can put any thing inside it.. I.e Data/Objects/Arrays etc.. and the reason i used the metaphore "Floats in mid air" is due to the fact its a static class and you will be able to used it everywhere in the script!

    step 4. (Create create some sub-classes)

    Ok now first what were going to be doing is creating a libary folder so we can store a web related classes there.

    so if you like to go a head and create a directory called "libary" within the includes folder

    our directory structure should be like "system/includes/libary/"...

    After you have that folder we can now add our first class witch will be an Http input class
    (used for working with the global $_GET,$_POST,$_COOKIE).

    Go ahead and create a file called HTTPInput.class.php and place within the "libary" folder

    Below is just an small example of a HTTP Input. if you want to look at one more in-depth the download the CodeIgnighter source package and look in there libary.

    PHP Code: 
    <?php
    if(!defined("APPLICATION_PATH")){ die("No DIRECT Access"); }

    final class 
    HttpInput{
        
        function 
    __construct(){
            
    $this->unregistryGlobals(); // sample function you ahve to build.
            //Clean user input
            
    $_GET        $this->_processGET($_GET);
            
    $_POST        $this->_processPOST($_POST);
            
    $_COOKIE    $this->_processCOOKIE($_COOKIE);
            
    $_FILES        $this->_processCOOKIE($_FILES);
        }
        
        
    //Cleaning Functiions
        
    private function _processGET($_){
            
    //Here we will just be recursivly escaping the data for example usage
            
    if(is_array($_)){
                
    $tmp = array();
                foreach(
    $_ as $key => $val){
                    
    //Check the $key is valid here if you wish
                    
    $tmp[$key] = $this->_processGET($val);
                }
                return 
    $tmp;
            }
            
    //Here we can check the single values
            
    if(get_magic_quotes_gpc()){
                
    $_ stripslashes($_);
            }
        
    //Other checking here....
        
        //Return
        
    return $_;
        }
        private function 
    _processPOST($_){
            
    //Check Post
        
    }
        private function 
    _processCOOKIE($_){
            
    //Check Cookie    
        
    }
        private function 
    _processFILES($_){
            
    //Check Files
        
    }    
        private function 
    unregistryGlobals(){
            
    //Here you can do some work on unregistering globals for security etc
        
    }
    }
    ?>
    No we have created the HTTP-Input class we have to tell the boot.php to use it and we need to place it within the registry.

    so withing your boot.php we will be adding some more code at the bottom.. so it should now look like the following.

    PHP Code: 
    <?php

    /*
    **
    *** In step one we created a constant called APPLICATION_PATH.
    *** Now a smarty security check is to make sure that constant is set.
    *** This will stope hackers from directly accessing the file from the browser.
    *** So we just make sure that the APPLICATION_PATH is in the scope
    **
    */

    if(!defined("APPLICATION_PATH")){ die("No DIRECT Access"); }

    /*
    **
    *** Now at this point we can start including our files, and creating the objects etc.
    *** The first object were going to be including is the regsitry object.
    **
    */

    //System::
    require_once APPLICATION_PATH "system/includes/classes/registry.php";

    //Libary::
    require_once APPLICATION_PATH "system/includes/libary/HTTPInput.class.php";

    /*
    **
    *** As the object will be a "static" class we wont need to create an instance of the object
    **
    */

    ?>
    You will notice we have just added the require_once line
    PHP Code: 
    //Libary::
    require_once APPLICATION_PATH "system/includes/libary/HTTPInput.class.php"
    No this means that we have pulled the un registered class into the boot but it wont be
    doing any thing unto we make and instance of the class so now were just going to add one line of code "after" the comment
    PHP Code: 
    /*
    **
    *** As the object will be a "static" class we wont need to create an instance of the object
    **
    */ 
    and were going to add

    PHP Code: 
    //Create the $Registry Object
    $Registry = new Registry;

    //Add Httpnput to the registry
    $Registry->HttpInput = new HttpInput(); 
    Ok so now we have a libary file thats used for accessing Http input globals such as $_GET and $_POST but we want to access them..

    Well as you have loaded all this class objects etc etc before any real work in index.php this means where ever yu include the bootloader (boot.php) you have accesss to all your classes within 1 single variable called $Registry..

    step 5. (Using the subclasses via Registry on yopur root pages)


    so now if you if you would just like to run the scipt you should ge no errors atall... should be a blank page.

    but now lets test the $Regsitry variable. within the index... ive added some more code to the index.php and heres what it looks like now

    PHP Code: 
    <?php

    /*
    **
    *** First lets create a constant that we will be using for 2 main things.
    *** 1. Used for security
    *** 2. Used to help know where we am on the filesystem.
    *** E.G. of the value is /root/sites/mySite/htdocs/
    **
    */

    define("APPLICATION_PATH" str_replace("\\","/",dirname(__FILE__)) . "/");

    /*
    **
    *** No lets include the bootloader file
    **
    */

    require_once APPLICATION_PATH "system/boot.php";


    /*
    **
    *** Anything below the inclusion of the system/boot.php should have all your libaries ready for usage!
    **
    */


    //lets do a test now.

    $id $Registry->HttpInput->get("id");

    echo 
    $id// this outputs 7 when the uri is index.php?id=7
    ?>

    as you can see by the ablove you have all your classes based around one registry system..
    Now as we come to the end of this tutorial i would just like to point out the possibilities by
    using a system like this.

    I have a website running like this with some big libaries loaded into the registry such as

    > Session Manager
    > Database Wrapper
    > Debug System
    > PHP Speed logging class
    > Smarty Template Engine
    > Sub Database classes AKA Models (18 or more classes loaded)
    > stdClass type DB config wrapper.

    And with this system i have a bog/forum/directory and admin etc all running threw the primary Regsitry class...

    And this is running a website with about 10-12K hits per day.... and is a very stable structure.

    So if you are just learning PHP5-6 then you will need to know that the concepts i have showed yout today has only scratched the surface... PHP i believe is untapped potential and its only limited by the programmer. and i hope i have shared a nice tutorial here with you all

    Files:
    http://rapidshare.com/files/31192729...Files.zip.html
    litewarez Reviewed by litewarez on . Advanced PHP (Registry System) - Guide/Tutorial Heya everyone, Introduction What you will learning to day is how to create a registry type of system for your "Framwork/Website" and how it will help you to manage all of your objects. What is a Registry you say? A registry is a class that will be used to hold other classes in an array/stdClass and create a type of "SperGlobal" for your script. The Steps. Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    yea really good tutorial.

    php has endless of possiblities

  4.     
    #3
    Member
    Website's:
    warezxtc.com
    God bless.

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    lol why god bless and thanks Deleted
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    Member
    Website's:
    warezxtc.com
    Quote Originally Posted by litewarez View Post
    lol why god bless and thanks Deleted
    Because you are the chosen one.

  7.     
    #6
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    ooooh yea..... lol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  8.     
    #7
    Member
    Website's:
    warezxtc.com
    Quote Originally Posted by litewarez View Post
    ooooh yea..... lol
    You must guide the Indians.

  9.     
    #8
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    hahahahha made me lol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  10.     
    #9
    Member
    Website's:
    warezxtc.com
    Quote Originally Posted by litewarez View Post
    hahahahha made me lol
    Please, young one, listen to the words of our friend "gill".


  11.     
    #10
    Member
    lmfao wow cyb

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Advanced Bash Loops Tutorial
    By Albert.Nawaro in forum Tutorials and Guides
    Replies: 0
    Last Post: 9th Feb 2012, 10:56 AM
  2. [AMS] xCleaner - Cleans your System & Registry ;)
    By l0calh0st in forum Web Development Area
    Replies: 1
    Last Post: 24th Jul 2010, 05:10 PM
  3. Tutorial [Creating a PHP Framework] {advanced} (PART 3)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 4th Feb 2010, 02:12 AM
  4. Tutorial [Creating a PHP Framework] {advanced} (PART 2)
    By litewarez in forum Tutorials and Guides
    Replies: 2
    Last Post: 3rd Feb 2010, 05:37 AM

Tags for this Thread

BE SOCIAL