/** * Get all user's captcha configuration. * * @return array * * @throw FileNotFoundException */ public static function all() { $configPath = Path::getConfigDirPath('captcha.php'); if (!file_exists($configPath)) { throw new FileNotFoundException('File "app/config/captcha.php" could not be found.'); } $captchaConfigs = (require $configPath); return $captchaConfigs; }
/** * Get contents of Captcha resources (js, css, gif files). * * @param string $filename * * @throws BadRequestHttpException */ public function indexAction($filename) { if (!preg_match('/^[a-z-]+\\.(css|gif|js)$/', $filename)) { throw new BadRequestHttpException('Invalid file name.'); } $resourcePath = realpath(Path::getPublicDirPathInLibrary() . $filename); if (!is_file($resourcePath)) { throw new BadRequestHttpException(sprintf('File "%s" could not be found.', $filename)); } $mimesType = array('css' => 'text/css', 'gif' => 'image/gif', 'js' => 'application/x-javascript'); $fileInfo = pathinfo($resourcePath); return new Response(file_get_contents($resourcePath), 200, array('content-type' => $mimesType[$fileInfo['extension']])); }
/** * Load the captcha configuration defaults. * * @param SessionInterface $session */ private static function loadCaptchaConfigDefaults(SessionInterface $session) { self::includeFile(Path::getCaptchaConfigDefaultsFilePath(), true, $session); }