Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
services:
captcha:
class: '%botdetect_captcha.class%'
public: true
arguments:
- '@service_container'

Expand Down
8 changes: 7 additions & 1 deletion Support/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Captcha\Bundle\CaptchaBundle\Support;

use Symfony\Component\HttpKernel\Kernel;

final class Path
{
/**
Expand Down Expand Up @@ -58,6 +60,10 @@ public static function getCaptchaConfigDefaultsFilePath()
*/
public static function getConfigDirPath($path = '')
{
return __DIR__ . '/../../../../app/config' . ($path ? '/' . $path : $path);
if (Kernel::VERSION < 4) {
return __DIR__ . '/../../../../app/config' . ($path ? '/' . $path : $path);
} else {
return __DIR__ . '/../../../../config/packages' . ($path ? '/' . $path : $path);
}
}
}
20 changes: 14 additions & 6 deletions Support/UserCaptchaConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
namespace Captcha\Bundle\CaptchaBundle\Support;

use Captcha\Bundle\CaptchaBundle\Support\Exception\FileNotFoundException;
use Captcha\Bundle\CaptchaBundle\Support\Path;
use Symfony\Component\HttpKernel\Kernel;

final class UserCaptchaConfiguration
{
/**
* Disable instance creation.
*/
private function __construct() {}
private function __construct()
{
}

/**
* Get user's captcha configuration by captcha id.
*
* @param string $captchaId
* @param string $captchaId
*
* @return array
*/
Expand All @@ -24,7 +26,7 @@ public static function get($captchaId)
$captchaId = trim($captchaId);

$captchaIdTemp = strtolower($captchaId);
$configs = array_change_key_case(self::all(), CASE_LOWER);
$configs = array_change_key_case(self::all(), CASE_LOWER);

$config = (is_array($configs) && array_key_exists($captchaIdTemp, $configs))
? $configs[$captchaIdTemp]
Expand All @@ -49,7 +51,12 @@ 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.');
if (Kernel::VERSION < 4) {
$path = 'app/config/captcha.php';
} else {
$path = 'config/packages/captcha.php';
}
throw new FileNotFoundException(sprintf('File "%s" could not be found.', $path));
}

$captchaConfigs = require $configPath;
Expand All @@ -60,7 +67,8 @@ public static function all()
/**
* Save user's captcha configuration options.
*
* @param array $config
* @param array $config
*
* @return void
*/
public static function save(array $config)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"require": {
"captcha-com/captcha": "4.*",
"symfony/http-kernel": "~2.0|~3.0|~4.0",
"php": ">=5.3.9"
},
"autoload": {
Expand Down
Loading