mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
Added root object
This commit is contained in:
parent
06f59e70c6
commit
09eaa2171c
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;
|
||||
}
|
||||
}
|
18
init.php
18
init.php
@ -3,4 +3,20 @@
|
||||
* Page initiator
|
||||
*
|
||||
* @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();
|
Loading…
Reference in New Issue
Block a user