Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class Application {
- // Hold an instance of the class
- private static $instances;
- // Active page object
- private static $page;
- // Active section object
- private static $section;
- // Active action object
- private static $action;
- // Active Session object
- private static $session;
- // Data storage object
- private static $data;
- // Instance counter
- private static $called;
- // The singleton method
- final public static function instance() {
- $c = get_called_class();
- if( ! isset( self::$instances[$c] ) ) {
- self::$instances[$c] = new $c;
- }
- if( ! isset ( self::$instances[$c]->called ) ){
- self::$instances[$c]->called = 1;
- } else {
- self::$instances[$c]->called++;
- }
- if( ! isset( self::$instances[$c]->storage ) ) {
- self::$instances[$c]->storage = array();
- }
- return self::$instances[$c];
- }
- // A private constructor; prevents direct creation of object
- final private function __construct() {}
- // Prevent users to clone the instance
- final private function __clone() {}
- final public function __get($variable=FALSE) {
- if( !$variable == FALSE ){
- if( isset( self::$$variable ) ) {
- return self::$$variable;
- }
- }
- return false;
- }
- final public function __set($variable=FALSE,$data=FALSE) {
- if( !$variable == FALSE ){
- if( isset( self::$$variable ) ) {
- if( is_array( self::$$variable ) && !$data == FALSE ) {
- return array_push( self::$$variable , $data );
- } elseif( is_string( self::$$variable ) && !$data == FALSE ) {
- return self::$$variable = $data;
- }
- }
- }
- return false;
- }
- final public function Initialize() {
- self::ParseUrl();
- }
- // Alias for self::Initialize()
- final public function init() {
- self::Initialize();
- }
- // Requested Page, Action or Module
- final protected function ParseUrl() {
- $query_string = $_SERVER['REQUEST_URI'];
- if( substr( $query_string , 0 , 1 ) == '/' ) {
- $query_string = substr( $query_string , 1 );
- }
- if( substr( $query_string , -1 ) == '/' ) {
- $query_string = substr( $query_string , 0 , -1 );
- }
- if( strlen( $query_string ) > 0 ) {
- self::$section = explode("/", str_replace("options=","",$query_string) );
- foreach( self::$section as $key => $value ) {
- self::$section[$key] = strtolower( $value );
- }
- } else {
- self::$section[] = 'home';
- }
- if( preg_match( "/index(\d*)\.html/" , self::$section[ count( self::$section ) -1 ] , $matches ) ) {
- $matches[1] = intval( $matches[1] );
- var_dump( $matches );
- var_dump( is_int( $matches[1] ) );
- echo "<hr>\r\n";
- if( is_int( $matches[1] ) ) {
- if( $matches[1] == 0 | $matches[1] == 1 ) {
- self::$section[ count( self::$section ) -1 ] = 'index.html';
- } else {
- self::$section[ count( self::$section ) -1 ] = $matches[1];
- }
- }
- unset( $matches );
- }
- if( isset( self::$section ) ) {
- return self::$section;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment