From 2612004339b24aa508cc2e9c788447a0349c7602 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 11 Apr 2018 09:49:02 +0200 Subject: [PATCH 1/2] change captcha.php destination folder depending on symfony version --- .gitignore | 1 + Support/Path.php | 8 +- Support/UserCaptchaConfiguration.php | 20 +- composer.json | 1 + composer.lock | 424 +++++++++++++++++++++++++++ 5 files changed, 447 insertions(+), 7 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index e69de29..22d0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/Support/Path.php b/Support/Path.php index 053aab4..85ab666 100644 --- a/Support/Path.php +++ b/Support/Path.php @@ -2,6 +2,8 @@ namespace Captcha\Bundle\CaptchaBundle\Support; +use Symfony\Component\HttpKernel\Kernel; + final class Path { /** @@ -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); + } } } diff --git a/Support/UserCaptchaConfiguration.php b/Support/UserCaptchaConfiguration.php index 35a64bd..27489b8 100644 --- a/Support/UserCaptchaConfiguration.php +++ b/Support/UserCaptchaConfiguration.php @@ -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 */ @@ -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] @@ -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; @@ -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) diff --git a/composer.json b/composer.json index 0840589..74f53ea 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ }, "require": { "captcha-com/captcha": "4.*", + "symfony/http-kernel": "~2.0|~3.0|~4.0", "php": ">=5.3.9" }, "autoload": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..830d447 --- /dev/null +++ b/composer.lock @@ -0,0 +1,424 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "7095d91fcbcdaf9c704f2b90c3d93707", + "packages": [ + { + "name": "captcha-com/captcha", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://git.captcha.com/botdetect-php-captcha-library.git", + "reference": "09e9db1913e2ae7f58ef9160783c5e6388e7ba11" + }, + "require": { + "php": ">=5.2.1" + }, + "suggest": { + "captcha-com/cakephp-captcha": "BotDetect 4 PHP Captcha generator integration for the CakePHP framework.", + "captcha-com/laravel-captcha": "BotDetect 4 PHP Captcha generator integration for the Laravel framework.", + "captcha-com/symfony-captcha-bundle": "BotDetect 4 PHP Captcha generator integration for the Symfony framework." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "BotDetect Captcha", + "email": "botdetect.support@captcha.com", + "homepage": "http://captcha.com/php-captcha.html" + } + ], + "description": "BotDetect 4 PHP Captcha Generator -- Free composer package.", + "homepage": "http://captcha.com/php-captcha.html", + "keywords": [ + "captcha" + ], + "time": "2018-02-15T17:27:52+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "symfony/debug", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "5961d02d48828671f5d8a7805e06579d692f6ede" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/5961d02d48828671f5d8a7805e06579d692f6ede", + "reference": "5961d02d48828671f5d8a7805e06579d692f6ede", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2018-04-03T05:24:00+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "63353a71073faf08f62caab4e6889b06a787f07b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/63353a71073faf08f62caab4e6889b06a787f07b", + "reference": "63353a71073faf08f62caab4e6889b06a787f07b", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "conflict": { + "symfony/dependency-injection": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2018-04-06T07:35:43+00:00" + }, + { + "name": "symfony/http-foundation", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-foundation.git", + "reference": "d0864a82e5891ab61d31eecbaa48bed5a09b8e6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/d0864a82e5891ab61d31eecbaa48bed5a09b8e6c", + "reference": "d0864a82e5891ab61d31eecbaa48bed5a09b8e6c", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.1" + }, + "require-dev": { + "symfony/expression-language": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpFoundation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony HttpFoundation Component", + "homepage": "https://symfony.com", + "time": "2018-04-03T05:24:00+00:00" + }, + { + "name": "symfony/http-kernel", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-kernel.git", + "reference": "6dd620d96d64456075536ffe3c6c4658dd689021" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/6dd620d96d64456075536ffe3c6c4658dd689021", + "reference": "6dd620d96d64456075536ffe3c6c4658dd689021", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0", + "symfony/debug": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/http-foundation": "~3.4.4|~4.0.4" + }, + "conflict": { + "symfony/config": "<3.4", + "symfony/dependency-injection": "<3.4.5|<4.0.5,>=4", + "symfony/var-dumper": "<3.4", + "twig/twig": "<1.34|<2.4,>=2" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/cache": "~1.0", + "symfony/browser-kit": "~3.4|~4.0", + "symfony/config": "~3.4|~4.0", + "symfony/console": "~3.4|~4.0", + "symfony/css-selector": "~3.4|~4.0", + "symfony/dependency-injection": "^3.4.5|^4.0.5", + "symfony/dom-crawler": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/finder": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0", + "symfony/routing": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0", + "symfony/templating": "~3.4|~4.0", + "symfony/translation": "~3.4|~4.0", + "symfony/var-dumper": "~3.4|~4.0" + }, + "suggest": { + "symfony/browser-kit": "", + "symfony/config": "", + "symfony/console": "", + "symfony/dependency-injection": "", + "symfony/var-dumper": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpKernel\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony HttpKernel Component", + "homepage": "https://symfony.com", + "time": "2018-04-06T16:25:03+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-01-30T19:27:44+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.9" + }, + "platform-dev": [] +} From cf842a9eae1066169deb1c5b7593e23d41a87ae4 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 11 Apr 2018 09:53:05 +0200 Subject: [PATCH 2/2] set captcha service public --- Resources/config/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 7976937..f2d219b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -7,6 +7,7 @@ parameters: services: captcha: class: '%botdetect_captcha.class%' + public: true arguments: - '@service_container'