function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { /** @var ResponseInterface $response */ $response = $next(); $lang = $this->locale->locale(); // The check for app->translation is made here instead of conditionally adding this middleware // because loaded modules can change this setting. if (!$this->settings->translation || !$lang) { return $response; } if (!isset(self::$translation[$lang])) { // Load and merge all translation files now. self::$translation[$lang] = []; $trans =& self::$translation[$lang]; $folders = $this->settings->languageFolders; foreach ($folders as $folder) { $path = "{$folder}/{$lang}.ini"; $newTrans = fileExists($path) ? parse_ini_file($path) : null; if ($newTrans) { $trans = array_merge($trans, $newTrans); } } if (!$trans) { $paths = array_map(function ($path) { return "<li>" . ErrorConsole::shortFileName($path); }, $folders); throw new ConfigException("A translation file for language <b>{$lang}</b> was not found.\n<p>Search paths:\n<ul>" . implode('', $paths) . "</ul>", FlashType::ERROR); } } $out = preg_replace_callback(self::FIND_TRANS_KEY, function ($args) use($lang) { $a = $args[1]; return empty(self::$translation[$lang][$a]) ? '$' . $a : preg_replace('#\\r?\\n#', '<br>', self::$translation[$lang][$a]); }, $response->getBody()); return $response->withBody($this->responseFactory->makeBody($out)); }
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { $url = $request->getAttribute('virtualUri', ''); if (!str_beginsWith($url, "{$this->settings->fileBaseUrl()}/")) { return $next(); } // Strip prefix from URL $url = substr($url, strlen($this->settings->fileBaseUrl()) + 1); $path = "{$this->settings->fileArchivePath()}/{$url}"; if (!file_exists($path)) { return $this->responseFactory->make(404, "Not found: {$path}", 'text/plain'); } $mime = FileUtil::getMimeType($path); // Serve image file. if (FileUtil::isImageType($mime)) { // Use image manipulation parameters extracted from the request. return $this->glideServer->getImageResponse($url, $request->getQueryParams()); } // Server non-image file. return $this->responseFactory->makeStream(fopen($path, 'rb'), 200, ['Content-Type' => $mime, 'Content-Length' => (string) filesize($path), 'Cache-Control' => 'max-age=31536000, public', 'Expires' => date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT']); }
function to($url, $status = 302) { $this->validate(); $url = $this->normalizeUrl($url); return $this->responseFactory->make($status, '', '', ['Location' => $url]); }