diff --git a/class-G.php b/class-G.php index af046bf..db56871 100644 --- a/class-G.php +++ b/class-G.php @@ -1,71 +1,73 @@ . /** * Allows you to be sure that a global object exists. + * + * @deprecated */ class G { /** * Associative array of: expected global variable name => it's class */ private $added = []; /** * Register an expected global variable name to it's class. * * If it doesn't exists it will be created as global and istantiated. */ public function add($name, $class) { $this->added[ $name ] = $class; } /** * Be sure that a global object exists. * * This method allows you to use the power of PHP and spl_audoload() * loading resources only when you request them. * * E.g. if you create a database connection using something as * $GLOBAL['db'] = new DB(), and we do it, you can avoid starting a * database connection even in pages that don't require database connections * simply saying that you "expect" an initialized global '$db' object. * Let's say expect('db'). * * As you can see, in the best case it's only an isset() away from your code. * * @param string $name A global var name. */ public function expect($name) { if( ! isset( $GLOBALS[ $name ] ) ) { // Die if class was not registered isset( $this->added[ $name ] ) || error_die( sprintf( __("Variabile globale '%s' attesa ma mai registrata. L'hai scritta correttamente?"), esc_html($name) ) ); $class_name = $this->added[ $name ]; class_exists($class_name, true) || error_die( sprintf( __("La classe '%s' non esiste!"), esc_html($class_name) ) ); $GLOBALS[ $name ] = new $class_name(); } return $GLOBALS[ $name ]; } }