示例#1
0
 }
 $dataDir = sprintf('%s/data/%s', dirname(__DIR__), $instanceId);
 if (!file_exists($dataDir)) {
     if (false === @mkdir($dataDir, 0700, true)) {
         throw new RuntimeException(sprintf('unable to create folder "%s"', $dataDir));
     }
 }
 $config = Config::fromFile(sprintf('%s/config/%s/config.yaml', dirname(__DIR__), $instanceId));
 $templateDirs = [sprintf('%s/views', dirname(__DIR__)), sprintf('%s/config/%s/views', dirname(__DIR__), $instanceId)];
 $templateCache = null;
 if ($config->v('enableTemplateCache')) {
     $templateCache = sprintf('%s/tpl', $dataDir);
 }
 $tpl = new TwigTpl($templateDirs, $templateCache);
 $tpl->addFilter(TwigFilters::sizeToHuman());
 $tpl->setDefault(['requestUri' => $request->getUri(), 'requestRoot' => $request->getRoot(), 'requestRootUri' => $request->getRootUri()]);
 $service = new Service($tpl);
 $service->addBeforeHook('referrer_check', new ReferrerCheckHook());
 $service->addAfterHook('no_cache', new NoCacheHook());
 // Authentication
 $authMethod = $config->v('authMethod');
 $tpl->addDefault(['authMethod' => $authMethod]);
 $session = new Session($request->getServerName(), $request->getRoot(), $config->v('secureCookie'));
 switch ($authMethod) {
     case 'MellonAuthentication':
         $service->addBeforeHook('auth', new MellonAuthenticationHook($config->v('MellonAuthentication', 'attribute')));
         break;
     case 'FormAuthentication':
         $tpl->addDefault(['_show_logout' => true]);
         $service->addBeforeHook('auth', new FormAuthenticationHook($session, $tpl));
         $service->addModule(new FormAuthenticationModule($config->v('FormAuthentication'), $session, $tpl));