mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Added root object
This commit is contained in:
		
							
								
								
									
										50
									
								
								classes/comunicAPI.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								classes/comunicAPI.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Comunic API Server root object
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CS{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var CS $instance Instance object copy
 | 
			
		||||
     */
 | 
			
		||||
    private static $instance;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Public constructor
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(){
 | 
			
		||||
        //Backup object in instance storing
 | 
			
		||||
        self::$instance = $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register a new child object
 | 
			
		||||
     *
 | 
			
		||||
     * @param String $name The name of the object to register
 | 
			
		||||
     * @param Mixed $obj The object to register
 | 
			
		||||
     * @return Boolean Depend of the success of the operation
 | 
			
		||||
     */
 | 
			
		||||
    public function register($name, &$obj){
 | 
			
		||||
        //Check if an object already exists with this name or not
 | 
			
		||||
        if(isset($this->{$name}))
 | 
			
		||||
            return false; //Conflict
 | 
			
		||||
        
 | 
			
		||||
        //Else we can register object
 | 
			
		||||
        $this->{$name} = &$obj;
 | 
			
		||||
        $this->{$name}->parent = $this;
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns current active  object instance
 | 
			
		||||
     *
 | 
			
		||||
     * @return CS An instance pointing on current object
 | 
			
		||||
     */
 | 
			
		||||
    public static function &get() : CS {
 | 
			
		||||
        return self::$instance;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								init.php
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								init.php
									
									
									
									
									
								
							@@ -4,3 +4,19 @@
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
//Define the base of the project
 | 
			
		||||
define("PROJECT_PATH", __DIR__."/");
 | 
			
		||||
 | 
			
		||||
//Include classes
 | 
			
		||||
foreach(glob(PROJECT_PATH."classes/*.php") as $classFile){
 | 
			
		||||
    require_once $classFile;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Include functions
 | 
			
		||||
foreach(glob(PROJECT_PATH."functions/*.php") as $funcFile){
 | 
			
		||||
    require_once $funcFile;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Create root object
 | 
			
		||||
$cs = new CS();
 | 
			
		||||
		Reference in New Issue
	
	Block a user