mattstauffer / Torch

Examples of using each Illuminate component in non-Laravel applications
MIT License
1.84k stars 211 forks source link

Suggestion for Config #192

Open paxperscientiam opened 3 years ago

paxperscientiam commented 3 years ago

After much tinkering, I've come up with a way to access config data via Illuminate\Support\Facades\Config

This uses some code from the existing Config example and uses a container (using kint just for dumping):

<?PHP
use Illuminate\Support\Facades\Config;
use Illuminate\Container\Container;
use Illuminate\Config\Repository;

$config = new Repository(require(FILE_ROOT . "/config/app.php"));
$app = new Container();

$app->instance(
    'config',
    $config
);

Illuminate\Support\Facades\Facade::setFacadeApplication($app);
s($app->get('config')->get("app"));
s(Config::get('app'));

Output: Screen Shot 2021-08-31 at 1 42 25 AM

Current example uses a slim app, so is incompatible with the above. Would it make sense to add a separate file like "components/config/example2.php" (for instance)?

EDIT: This may tie in some how to PR #191 ... but maybe not.