You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might supersede #192 idea and prior PR. Here is an example of how to get Cache, Config, and Env.
Some notes:
Not sure one would want to, but Illuminate\Support\Arr is needed to parse output of Cache::get(...) as it doesn't handle dot notation.
I can't beat Laravel's logic for handling cache/env for different environments. Not sure how that would be demonstrated other than copy/pasting from their source code.
Works-for-me example code:
<?PHP/* Note, these variables aren't directly accessible. Use globals EG: Illuminate\Support\Facades\Config::get("app.cnx") */useIlluminate\Container\Container;
useIlluminate\Support\Arr;
useIlluminate\Config\Repository;
useIlluminate\Support\Facades\Facade;
useIlluminate\Filesystem\Filesystem;
useIlluminate\Cache\CacheManager;
useDotenv\Dotenv;
useIlluminate\Support\Facades\Config;
useIlluminate\Support\Facades\Cache;
useIlluminate\Support\Env;
defined("FILE_ROOT") ? true : define("FILE_ROOT", realpath(".."));
// create dummy app$app = newContainer();
// would want to refactor to make sure cache is used in productiontry {
// check if file exists. if not, presume production enviroment$dotenv = Dotenv::createImmutable(FILE_ROOT);
$dotenv->load();
} catch (Exception$e) {
// presume productionerror_log($e->getMessage());
}
// config setup$config = newRepository(require(FILE_ROOT . "/backend/config/app.php"));
// bind $config to $app$app->instance(
'config',
$config
);
// cache stuff$cacheC = newContainer();
$cacheC['config'] = $config->get('app.cache');
$cacheC["files"] = newFilesystem();
$cacheManager = newCacheManager($cacheC);
$cache = $cacheManager->store();
// bind $cache to $app$app->instance(
'cache',
$cache
);
$cache->put('test', 'This is loaded from Redis cache.', 500);
$cache->put('app', $config->get('app'));
$config->set('test', 'rofl');
Facade::setFacadeApplication($app);
s(Config::get('test'));
s(Config::get('app.cnx'));
s(Cache::get('test'));
s(Arr::get(Cache::get('app'), 'cnx'));
s(Env::get('RUN_MODE'));
Output:
The text was updated successfully, but these errors were encountered:
Hey @mattstauffer ,
This might supersede #192 idea and prior PR. Here is an example of how to get Cache, Config, and Env.
Some notes:
Illuminate\Support\Arr
is needed to parse output ofCache::get(...)
as it doesn't handle dot notation.Works-for-me example code:
Output:
The text was updated successfully, but these errors were encountered: