Added root object

This commit is contained in:
Pierre 2017-05-17 13:51:22 +02:00
parent 06f59e70c6
commit 09eaa2171c
2 changed files with 67 additions and 1 deletions

50
classes/comunicAPI.php Normal file
View 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;
}
}

View File

@ -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();