Login   Register  
PHP Classes
elePHPant
Icontem

File: code/includes/url.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Junaid Hassan  >  PHP MVC  >  code/includes/url.php  >  Download  
File: code/includes/url.php
Role: Class source
Content type: text/plain
Description: url.php
Class: PHP MVC
MVC framework that loads XML configuration files
Author: By
Last change:
Date: 2013-04-27 07:17
Size: 2,870 bytes
 

Contents

Class file image Download
<?php
/* Class name       : Url
 * Inherited from   : 
 * Created by       : Junaid Hassan (email : junaidhassanalvi@gmail.com , blog : junaidhassanalvi.wordpress.com)
 * Created On       : 15-April-2103
 * Description      : To handle all operations regarding recieved URL request
 * 
 * Change Logs      :
 * 
 */
class Url {

    var 
$controller$action$controller_path$qParams$request$controller_class$controller_action;
    
    protected 
$catalog;

    function 
__construct($catalog) {
        
$this->catalog $catalog;
    }

    
// jha-- parse recieved URL to route the request to appropriate controller and action
    //jha-- explode url in an array to form request array
    //jha-- check if controller is provided, if not, take it from configuration
    //jha-- check if action is provided, if not, take it from configuration
    //jha-- check if required controller and action is present, if not, die
    //jha-- push controller and action name from request array to create parameter list for action's function
    
public function parse_current() {

        global 
$utilities;
        
        
$config $this->catalog->get('config');

        
$qs = isset($_GET['qs']) ? $_GET['qs'] : '';
        
$this->request $qs;
        
$this->qParams explode('/'$qs);

        if (!@
$utilities->isNullOrEmpty($this->qParams[0])) {
            
$this->controller $this->qParams[0];
        } else {
            
$this->controller $config->default->controller;
        }

        if (!@
$utilities->isNullOrEmpty($this->qParams[1])) {
            
$this->action $this->qParams[1];
        } else {
            
$this->action $config->default->action;
        }

        
$this->controller_path $config->base_path '/' $config->paths->controllers '/' $this->controller '.php';

        
$this->controller_class $this->controller 'Controller';
        
$this->controller_action $this->action 'Action';

        if (
file_exists($this->controller_path)) {
            require(
$this->controller_path);
            if (
class_exists($this->controller_class)) {
                
$obj = new $this->controller_class($this->catalog);
                if (
method_exists($obj$this->controller_action)) {
                    
                } else {
                    die(
'Required action is not found');
                }
            } else {
                die(
'Required controller is not found');
            }
        } else {
            die(
'Required controller is not found');
        }

        if (
is_array($this->qParams))
            if (
count($this->qParams) > 0)
                
array_shift($this->qParams);

        if (
is_array($this->qParams))
            if (
count($this->qParams) > 0)
                
array_shift($this->qParams);
    }

}
?>