diff --git a/Classes/RequestMethod/CurlPostWithProxy.php b/Classes/RequestMethod/CurlPostWithProxy.php index 5b0dbb2..a4a4775 100644 --- a/Classes/RequestMethod/CurlPostWithProxy.php +++ b/Classes/RequestMethod/CurlPostWithProxy.php @@ -63,14 +63,17 @@ public function injectSettings(array $settings) throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option has to be a string."); } - $httpProxyParts = explode(':', $settings['httpProxy']); - if(count($httpProxyParts) !== 2 || (int)$httpProxyParts[1] === 0){ + $httpProxy = $settings['httpProxy']; + $this->emitHttpProxyRetrieved($httpProxy); + + $formatIsValid = preg_match('@^(.*):(\d{1,5})$@', $httpProxy, $httpProxyParts); + $this->proxyHost = $httpProxyParts[1]; + $this->proxyPort = (int)$httpProxyParts[2]; + + if(!$formatIsValid || !$this->proxyHost || !$this->proxyPort){ throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option should have the following format: 'http://yourproxy.com:1234'"); } - $this->proxyHost = $httpProxyParts[0]; - $this->proxyPort = $httpProxyParts[1]; - $this->settings = $settings; } @@ -110,9 +113,6 @@ public function submit(RequestParameters $params) CURLOPT_SSL_VERIFYPEER => true, ]; - $httpProxy = $this->settings['httpProxy']; - $this->emitHttpProxyRetrieved($httpProxy); - $options[CURLOPT_RETURNTRANSFER] = 1; $options[CURLOPT_PROXY] = $this->proxyHost; $options[CURLOPT_PROXYPORT] = $this->proxyPort; diff --git a/README.md b/README.md index dab0b46..9744be1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,17 @@ composer require wegmeister/recaptcha Afterwards, go to [http://www.google.com/recaptcha](http://www.google.com/recaptcha) and create a key for your website. Select the API version you wish to use based on the list above. +## Configuration + +### HTTP Proxy +If you are using a http proxy on your server you need to add this configuration: +``` +Wegmeister: + Recaptcha: + requestMethod: 'Wegmeister\Recaptcha\RequestMethod\CurlPostWithProxy' + httpProxy: 'http://yourproxy.com:1234' +``` + ## Usage with [Neos.Form](https://github.com/neos/form) Simply add the new form element to your form definition renderables: