Ejemplo n.º 1
0
 public static function _($arg1 = null, $arg2 = null, $arg3 = null)
 {
     if (isset($arg1) && !isset($arg2) && !isset($arg3)) {
         // Calling require('name') to get the object.
         $arg1 = RequirePHP::parseAlias($arg1);
         if (!RequirePHP::runModule($arg1)) {
             throw new RequireModuleFailedException("Can't load module {$arg1}.");
         }
         return RequirePHP::$modules[$arg1]['return'];
     } elseif (!isset($arg3) && is_array($arg1) && is_callable($arg2)) {
         // Calling require(['dependency'], function(){}) to run a function when dependencies are met.
         RequirePHP::$functions[] = array('requires' => $arg1, 'function' => $arg2);
     } elseif (is_string($arg1) && is_array($arg2) && is_callable($arg3)) {
         // Calling require('name', ['dependency'], function(){}) to declare a named module.
         RequirePHP::$modules[$arg1] = array('requires' => $arg2, 'function' => $arg3);
     }
     RequirePHP::runFunctions();
 }