Guest User

Untitled

a guest
Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2.  
  3. Class Application {
  4.  
  5.     // Hold an instance of the class
  6.     private static $instances;
  7.    
  8.     // Active page object
  9.     private static $page;
  10.    
  11.     // Active section object
  12.     private static $section;
  13.    
  14.     // Active action object
  15.     private static $action;
  16.    
  17.     // Active Session object
  18.     private static $session;
  19.    
  20.     // Data storage object
  21.     private static $data;
  22.    
  23.     // Instance counter
  24.     private static $called;
  25.  
  26.     // The singleton method
  27.     final public static function instance() {
  28.    
  29.         $c = get_called_class();
  30.  
  31.         if( ! isset( self::$instances[$c] ) ) {
  32.        
  33.             self::$instances[$c] = new $c;
  34.            
  35.         }
  36.        
  37.         if( ! isset ( self::$instances[$c]->called ) ){
  38.        
  39.             self::$instances[$c]->called = 1;
  40.        
  41.         } else {
  42.        
  43.             self::$instances[$c]->called++;
  44.        
  45.         }
  46.        
  47.         if( ! isset( self::$instances[$c]->storage ) ) {
  48.        
  49.             self::$instances[$c]->storage = array();
  50.        
  51.         }
  52.        
  53.         return self::$instances[$c];
  54.        
  55.     }
  56.  
  57.     // A private constructor; prevents direct creation of object
  58.     final private function __construct() {}
  59.  
  60.     // Prevent users to clone the instance
  61.     final private function __clone() {}
  62.    
  63.     final public function __get($variable=FALSE) {
  64.    
  65.         if( !$variable == FALSE ){
  66.            
  67.             if( isset( self::$$variable ) ) {
  68.            
  69.                 return self::$$variable;
  70.            
  71.             }
  72.        
  73.         }
  74.        
  75.         return false;
  76.    
  77.     }
  78.    
  79.     final public function __set($variable=FALSE,$data=FALSE) {
  80.    
  81.         if( !$variable == FALSE ){
  82.            
  83.             if( isset( self::$$variable ) ) {
  84.            
  85.                 if( is_array( self::$$variable ) && !$data == FALSE ) {
  86.                
  87.                     return array_push( self::$$variable , $data );
  88.                
  89.                 } elseif( is_string( self::$$variable ) && !$data == FALSE  ) {
  90.                
  91.                     return self::$$variable = $data;
  92.                
  93.                 }
  94.            
  95.             }
  96.        
  97.         }
  98.        
  99.         return false;
  100.    
  101.     }
  102.    
  103.     final public function Initialize() {
  104.        
  105.         self::ParseUrl();
  106.    
  107.     }
  108.    
  109.     // Alias for self::Initialize()
  110.     final public function init() {
  111.    
  112.         self::Initialize();
  113.    
  114.     }
  115.    
  116.     // Requested Page, Action or Module
  117.     final protected function ParseUrl() {
  118.        
  119.         $query_string = $_SERVER['REQUEST_URI'];
  120.        
  121.        
  122.         if( substr( $query_string , 0 , 1 ) == '/' ) {
  123.        
  124.             $query_string = substr( $query_string , 1 );
  125.        
  126.         }
  127.        
  128.         if( substr( $query_string , -1 ) == '/' ) {
  129.        
  130.             $query_string = substr( $query_string , 0 , -1 );
  131.        
  132.         }
  133.        
  134.        
  135.         if( strlen( $query_string ) > 0 ) {
  136.        
  137.             self::$section = explode("/", str_replace("options=","",$query_string) );
  138.            
  139.             foreach( self::$section as $key => $value ) {
  140.            
  141.                 self::$section[$key] = strtolower( $value );
  142.            
  143.             }
  144.            
  145.         } else {
  146.        
  147.             self::$section[] = 'home';
  148.        
  149.         }
  150.        
  151.        
  152.         if( preg_match( "/index(\d*)\.html/" , self::$section[ count( self::$section ) -1 ] , $matches ) ) {
  153.            
  154.             $matches[1] = intval( $matches[1] );
  155.            
  156.             var_dump( $matches );
  157.             var_dump( is_int( $matches[1] ) );
  158.            
  159.             echo "<hr>\r\n";
  160.            
  161.             if( is_int( $matches[1] ) ) {
  162.                
  163.                 if( $matches[1] == 0 | $matches[1] == 1 ) {
  164.                
  165.                     self::$section[ count( self::$section ) -1 ] = 'index.html';
  166.                
  167.                 } else {
  168.                
  169.                     self::$section[ count( self::$section ) -1 ] = $matches[1];
  170.                
  171.                 }
  172.  
  173.             }
  174.        
  175.             unset( $matches );
  176.        
  177.         }
  178.        
  179.        
  180.         if( isset( self::$section ) ) {
  181.        
  182.             return self::$section;
  183.        
  184.         }
  185.        
  186.         return false;
  187.    
  188.     }
  189.  
  190. }
Add Comment
Please, Sign In to add comment