Skip to content
Draft
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
51 changes: 13 additions & 38 deletions src/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
use const E_USER_WARNING;

/**
* Render and verify ReCaptchas
* Render and verify v2 ReCaptchas
*
* @final This class should not be extended and will be marked final in version 4.0
*/
class ReCaptcha implements Stringable
class ReCaptcha implements ReCaptchaServiceInterface, Stringable
{
/**
* URI to the API
Expand Down Expand Up @@ -185,11 +185,7 @@ public function getIp()
}

/**
* Set a single parameter
*
* @param string $key
* @param mixed $value
* @return self
* @inheritDoc
*/
public function setParam($key, $value)
{
Expand Down Expand Up @@ -227,9 +223,7 @@ public function setParams($params)
}

/**
* Get the parameter array
*
* @return array<string, mixed>
* @inheritDoc
*/
public function getParams()
{
Expand All @@ -252,11 +246,7 @@ public function getParam($key)
}

/**
* Set a single option
*
* @param string $key
* @param mixed $value
* @return self
* @inheritDoc
*/
public function setOption($key, $value)
{
Expand All @@ -269,7 +259,7 @@ public function setOption($key, $value)
* Set options
*
* @param iterable<string, mixed> $options
* @return self
* @return $this
* @throws Exception
*/
public function setOptions($options)
Expand All @@ -290,9 +280,7 @@ public function setOptions($options)
}

/**
* Get the options array
*
* @return array<string, mixed>
* @inheritDoc
*/
public function getOptions()
{
Expand All @@ -315,20 +303,15 @@ public function getOption($key)
}

/**
* Get the site key
*
* @return string
* @inheritDoc
*/
public function getSiteKey()
{
return $this->siteKey;
}

/**
* Set the site key
*
* @param string $siteKey
* @return self
* @inheritDoc
*/
public function setSiteKey($siteKey)
{
Expand All @@ -338,20 +321,15 @@ public function setSiteKey($siteKey)
}

/**
* Get the secret key
*
* @return string
* @inheritDoc
*/
public function getSecretKey()
{
return $this->secretKey;
}

/**
* Set the secret key
*
* @param string $secretKey
* @return self
* @inheritDoc
*/
public function setSecretKey($secretKey)
{
Expand Down Expand Up @@ -478,17 +456,14 @@ protected function post($responseField)
}

/**
* Verify the user input
* {@inheritDoc}
*
* This method calls up the post method and returns a
* \Laminas\ReCaptcha\Response object.
*
* @param string $responseField
* @return Response
*/
public function verify($responseField)
{
$response = $this->post($responseField);
return new Response(null, null, $response);
return new Response(null, [], $response);
}
}
81 changes: 81 additions & 0 deletions src/ReCaptchaServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Laminas\ReCaptcha;

/**
* An interface for interacting with a recaptcha service provider
*/
interface ReCaptchaServiceInterface
{
/**
* Get the options array
*
* @return array<string, mixed>
*/
public function getOptions();

/**
* Set a single option
*
* @param string $key
* @param mixed $value
* @return $this
*/
public function setOption($key, $value);

/**
* Get the parameter array
*
* @return array<string, mixed>
*/
public function getParams();

/**
* Set a single parameter
*
* @param string $key
* @param mixed $value
* @return $this
*/
public function setParam($key, $value);

/**
* Get the site key
*
* @return string
*/
public function getSiteKey();

/**
* Set the site key
*
* @param string $siteKey
* @return $this
*/
public function setSiteKey($siteKey);

/**
* Get the secret key
*
* @return string
*/
public function getSecretKey();

/**
* Set the secret key
*
* @param string $secretKey
* @return $this
*/
public function setSecretKey($secretKey);

/**
* Verify the user input
*
* @param string $responseField
* @return Response
*/
public function verify($responseField);
}