Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Migrate to ReCaptcha's v2 API #11

Merged
merged 20 commits into from
Feb 9, 2017
Merged
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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ cache:
matrix:
fast_finish: true
include:
- php: 5.5
- php: 5.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

env:
- EXECUTE_CS_CHECK=true
- php: 7
- php: hhvm
- php: 7.0
- php: 7.1
- php: hhvm
allow_failures:
- php: 7
- php: hhvm

before_install:
- composer self-update

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs --prefer-source
- travis_retry composer install --no-interaction --prefer-source
- composer info -i

script:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

## Install

You can install using:
You can install using [Composer][1]:

```
curl -s https://getcomposer.org/installer | php
php composer.phar install
composer require zendframework/zendservice-recaptcha
```

Expand All @@ -17,4 +15,8 @@ usage of the component.

Documentation is on the Zend Framework website:

- http://framework.zend.com/manual/current/en/modules/zendservice.re-captcha.html
- [http://framework.zend.com/manual/current/en/modules/zendservice.re-captcha.html][2]


[1]: https://getcomposer.org/download/
[2]: http://framework.zend.com/manual/current/en/modules/zendservice.re-captcha.html
20 changes: 7 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@
"ZendServiceTest\\ReCaptcha\\": "test/"
}
},
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"php": ">=5.5",
"zendframework/zend-config": "~2.0",
"zendframework/zend-http": "~2.0",
"zendframework/zend-json": "~2.0"
"php": "^5.6 || ^7.0",
"zendframework/zend-http": "^2.5.4",
"zendframework/zend-json": "^2.6.1 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "^2.3",
"zendframework/zend-validator": "~2.0"
"phpunit/phpunit": "^5.7 || ^6.0",
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-config": "^2.0",
"zendframework/zend-validator": "^2.8.2"
},
"suggest": {
"zendframework/zend-validator": "~2.0, if using ReCaptcha's Mailhide API"
Expand Down
19 changes: 5 additions & 14 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<description>Zend Framework coding standard</description>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
5 changes: 3 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<ini name="date.timezone" value="UTC"/>

<!-- ZendService\ReCaptcha online test env variables -->
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY" value="public key"/>
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY" value="private key"/>
<!-- Change these if you want to use your own keys -->
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY" value="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"/>
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY" value="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"/>
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY" value="public mailhide key"/>
<env name="TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY" value="private mailhide key"/>
</php>
Expand Down
58 changes: 50 additions & 8 deletions src/MailHide.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function setEmailValidator(ValidatorInterface $validator)
*/
protected function requireMcrypt()
{
if (!extension_loaded('mcrypt')) {
if (! extension_loaded('mcrypt')) {
throw new MailHideException(sprintf(
'Use of the %s component requires the mcrypt extension to be enabled in PHP',
__CLASS__
Expand Down Expand Up @@ -177,23 +177,65 @@ public function getDefaultOptions()
}

/**
* Override the setPrivateKey method
* Set the private key property
*
* Override the parent method to store a binary representation of the private key as well.
*
* Note that we use the nomenclature "private key" as this is what MailHide's API
* uses, even though the parent ReCaptcha API uses "secret key"
*
* @param string $privateKey
* @return MailHide
*/
public function setPrivateKey($privateKey)
{
parent::setPrivateKey($privateKey);
parent::setSecretKey($privateKey);

/* Pack the private key into a binary string */
$this->privateKeyPacked = pack('H*', $this->privateKey);
$this->privateKeyPacked = pack('H*', $this->getSecretKey());

return $this;
}

/**
* get the private key property
*
* Note that we use the nomenclature "private key" as this is what MailHide's API
* uses, even though the parent ReCaptcha API uses "secret key"
*
* @return string
*/
public function getPrivateKey()
{
return parent::getSecretKey();
}

/**
* set the public key property
*
* Note that we use the nomenclature "public key" as this is what MailHide's API
* uses, even though the parent ReCaptcha API uses "site key"
*
* @param string $publicKey
*/
public function setPublicKey($publicKey)
{
return parent::setSiteKey($publicKey);
}

/**
* Get the public key property
*
* Note that we use the nomenclature "public key" as this is what MailHide's API
* uses, even though the parent ReCaptcha API uses "site key"
*
* @return string
*/
public function getPublicKey()
{
return parent::getSiteKey();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these proxy methods maybe be marked deprecated now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't actually deprecated for MailHide as that's the correct wording for its API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sounds good.


/**
* Set the email property
*
Expand All @@ -207,7 +249,7 @@ public function setEmail($email)
$this->email = $email;

$validator = $this->getEmailValidator();
if (!$validator->isValid($email)) {
if (! $validator->isValid($email)) {
throw new MailHideException('Invalid email address provided');
}

Expand Down Expand Up @@ -273,11 +315,11 @@ public function getHtml($email = null)
throw new MailHideException('Missing email address');
}

if ($this->publicKey === null) {
if ($this->getPublicKey() === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why getPublicKey() and not getSiteKey()?

Copy link
Contributor Author

@akrabat akrabat Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MailHide is still on v1's API which uses the nomenclature "public_key" and "private_key".

Seemed sensible to be consistent within this class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Maybe add some verbiage indicating that, then?

throw new MailHideException('Missing public key');
}

if ($this->privateKey === null) {
if ($this->getPrivateKey() === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why getPrivateKey() and not getSecretKey()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MailHide is still on v1's API which uses the nomenclature "public_key" and "private_key".

throw new MailHideException('Missing private key');
}

Expand Down Expand Up @@ -330,7 +372,7 @@ protected function getUrl()
return sprintf(
'%s?k=%s&c=%s',
self::MAILHIDE_SERVER,
$this->publicKey,
$this->getSiteKey(),
strtr(base64_encode($emailEncrypted), '+/', '-_')
);
}
Expand Down
Loading