/** * Adds a service provider to the container * * @param string $provider * @param bool $as_dependency * * @return $this */ public function add($provider, $as_dependency = FALSE) { $this->providers[$provider] = ['registered' => FALSE, 'booted' => FALSE]; if ($as_dependency) { $this->forge->add([$provider, $provider]); } return $this; }
public function test02_add() { $this->assertTrue($this->forge->add('function', function () { return 'I am a function.'; }) === NULL); $this->assertEquals('I am a function.', $this->forge['function']); $this->forge->add('spanks', new TestServiceProvider($this->forge)); $this->assertTrue($this->forge->get('spanks') instanceof \Og\Providers\TestServiceProvider); }
/** * Execute an HTTP route. * * @param $input - HTTP input fields * @param $action - Route action * * @return mixed|Response */ public function executeRouteAction($input, $action) { // register the current Input object $this->forge->add(['input', Input::class], new Input($input)); $this->before_route_dispatch(); // If the route is a controller::method then first determine if the controller // implements __invoke(). We'll assume the signature is correct for Middleware. if (is_string($action) and Util::string_has(static::ROUTE_METHOD_SEPARATOR, $action)) { // extract controller and method list($controller, $method) = explode(static::ROUTE_METHOD_SEPARATOR, $action); // use the static::APP_NAMESPACE to normalize constructor names without namespace. $controller = $this->normalize_namespace($controller); // depending on the controller constructor signature, // find and instantiate the constructor $processor = $this->newConstructorWithInjection($controller); // transfer control over to the controller $result = $this->invoke_controller($processor, $method); } else { // Otherwise, transfer control to the controller::method directly. // Note that call() handles dependency injection. $result = $this->forge->callWithDependencyInjection($action); } $this->after_route_dispatch(); return $result; }
/** * @package Og * @version 0.1.0 * @author Greg Truesdell <*****@*****.**> */ use Dotenv\Dotenv; use Og\Kernel\Kernel; include 'paths.php'; include SUPPORT . 'helpers.php'; include SUPPORT . 'messages.php'; include VENDOR . 'autoload.php'; /** @noinspection PhpUnusedLocalVariableInspection */ $forge = new Forge(new \Illuminate\Container\Container()); // register the Config $forge->add(['config', Config::class], Config::createFromFolder(CONFIG)); // register the Kernel $forge->singleton(['kernel', Kernel::class], new Kernel($forge)); // set the timezone (as required by earlier versions of PHP before 7.0.0 date_default_timezone_set($forge['config']['app.timezone']); # load environment as a requirement if (file_exists(ROOT . '.env')) { $dotenv = new Dotenv(ROOT); $dotenv->overload(); } else { throw new \LogicException('Unable to find root environment file. Did you remember to rename `.env-example?'); } # install Tracy if in DEBUG mode if (strtolower(getenv('DEBUG')) === 'true') { # core debug utilities # note that debug requires that the environment has been loaded