Skip to content

Core\App

Fariz Luqman edited this page Jun 29, 2016 · 5 revisions

The Application container

The application container or the App container is a tool used for dependency injection. Dependency injection is a method for writing better code. For simplicity, the application container will link any variables or objects using the method Core\App::link().

Say that you have database service:

// returns the Illuminate\Database\Capsule\Manager into $database
$database = Core\Database::connect();

Link them with the App container

$app->link('database', $database);

To access the linked objects / variables in the container:

$users = $app->database
	     ->table('users')
	     ->where('id','1')
	     ->get();

To access the container within any other defined scopes, the container will need to be "shared". Read about Core\Sharer.

Visit our website for tutorials: stupidlysimple.github.io

Clone this wiki locally