-
Notifications
You must be signed in to change notification settings - Fork 26
get app in legacy way
koriym edited this page Sep 30, 2014
·
1 revision
/**
* @param string $appName
* @param string $context
* @param string $tmpDir
* @param Cache $cache
*
* @return \BEAR\Sunday\Extension\Application\AppInterface
*/
public static function getModuleCachedApp($appName, $context, $tmpDir, Cache $cache = null)
{
$appModule = $appName . '\Module\AppModule';
$cache = $cache ?: (function_exists('apc_fetch') ? new ApcCache : new FilesystemCache($tmpDir));
$cacheKey = 'module-' . $appName . $context;
$moduleProvider = function () use ($appModule, $context) {return new $appModule($context);};
$injector = ModuleCacheInjector::create($moduleProvider, $cache, $cacheKey, $tmpDir);
$app = $injector->getInstance('BEAR\Sunday\Extension\Application\AppInterface');
/** $app \BEAR\Sunday\Extension\Application\AppInterface */
return $app;
}
/**
* Return cached application instance
*
* (experimental)
*
* @param string $appName
* @param string $context
* @param string $tmpDir
* @param Cache $cache
*
* @return \BEAR\Sunday\Extension\Application\AppInterface
*/
public static function getCachedApp($appName, $context, $tmpDir, Cache $cache = null)
{
$appModule = $appName . '\Module\AppModule';
$cache = $cache ?: function_exists('apc_fetch') ? new ApcCache : new FilesystemCache($tmpDir);
$cacheKey = $appName . $context;
$initialization = function () {
// initialize per system startup (not per each request)
};
$injector = function () use ($appModule, $cache) {
return Injector::create([new $appModule], $cache, __DIR__ . '/tmp');
};
$injector = new CacheInjector($injector, $initialization, $cacheKey, $cache);
$app = $injector->getInstance('BEAR\Sunday\Extension\Application\AppInterface');
/** $app \BEAR\Sunday\Extension\Application\AppInterface */
return $app;
}