/** * Get the available container instance. * * @param string $key * @return mixed */ function container($key = null) { if (is_null($key)) { return Container::getInstance(); } return Container::getInstance()->get($key); }
/** * Create a new application. * * @param string $basePath */ public function __construct($basePath) { if (is_null($basePath)) { throw new \InvalidArgumentException("The base path has not been set."); } parent::__construct(); // Make the container instance used by this application // globally available. Container::setInstance($this->getContainer()); $this->setBasePath($basePath); $this->bootstrap(); }
// constants define('CONF_PATH', __DIR__ . '/config/'); define('COMMON_CONFIG_PATH', CONF_PATH . 'common/'); // env require CONF_PATH . 'env.php'; define('CONFIG_PATH', CONF_PATH . ENV . '/'); define('CORE_PATH', __DIR__ . '/core/'); define('API_PATH', __DIR__ . '/api/'); define('VIEW_PATH', __DIR__ . '/view/'); define('APP_PATH', __DIR__ . '/app/'); define('APP1_PATH', __DIR__ . '/app1/'); // autoload require CORE_PATH . 'Loader.php'; (new Loader())->addNamespace('core', CORE_PATH)->addNamespace('api', API_PATH)->addNamespace('app', APP_PATH)->addNamespace('app1', APP1_PATH)->register(); try { $di = Container::instance(); $di->set('route', function () { return new Route(); }); $di->set('request', function () { return new Request(); }); $di->set('response', function () { return new Response(); }); $di->set('view', function () { return new View(VIEW_PATH); }); $di->set('db1', function () { $db = (include CONFIG_PATH . 'db.php'); return new DBMysqli($db['db1']);
public function __construct() { $di = Container::instance(); $this->handle = $di->get($this->database); }
public function __construct($args = False) { parent::__construct($args); $this->_cls = static::get_class(); $this->_fcls = static::get_full_class(); }