Update vendored libs

This commit is contained in:
Frédéric Guillot
2020-06-08 22:46:20 -07:00
parent dfb0a2d915
commit f60e4a0c59
292 changed files with 9402 additions and 9487 deletions

View File

@@ -122,6 +122,12 @@ You can also pass directly the wanted phrase to the builder:
$captcha = new CaptchaBuilder('hello');
```
Complete example
================
If you want to see an example you can have a look at he ``demo/form.php``, which uses ``demo/session.php`` to
render a captcha and check it after the submission
Symfony Bundle
================

View File

@@ -20,7 +20,7 @@
"php": ">=5.3.0",
"ext-gd": "*",
"ext-mbstring": "*",
"symfony/finder": "~3.0"
"symfony/finder": "*"
},
"autoload": {
"psr-4": {

32
vendor/gregwar/captcha/demo/form.php vendored Normal file
View File

@@ -0,0 +1,32 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\PhraseBuilder;
// We need the session to check the phrase after submitting
session_start();
?>
<html>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Checking that the posted phrase match the phrase stored in the session
if (isset($_SESSION['phrase']) && PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['phrase'])) {
echo "<h1>Captcha is valid !</h1>";
} else {
echo "<h1>Captcha is not valid!</h1>";
}
// The phrase can't be used twice
unset($_SESSION['phrase']);
}
?>
<form method="post">
Copy the CAPTCHA:
<?php
// See session.php, where the captcha is actually rendered and the session phrase
// is set accordingly to the image displayed
?>
<img src="session.php" />
<input type="text" name="phrase" />
<input type="submit" />
</form>
</html>

22
vendor/gregwar/captcha/demo/inline.php vendored Normal file
View File

@@ -0,0 +1,22 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;
$captcha = new CaptchaBuilder();
$captcha->build();
?>
<!DOCTYPE html>
<body>
<html>
<meta charset="utf-8" />
</html>
<body>
<h1>Inline Captcha</h1>
<img src="<?php echo $captcha->inline(); ?>"/><br/>
Phrase: <?php echo $captcha->getPhrase(); ?>
</body>
</body>

22
vendor/gregwar/captcha/demo/session.php vendored Normal file
View File

@@ -0,0 +1,22 @@
<?php
// We need the session to store the correct phrase for later check
session_start();
// Including the autoload (you need to composer install in the main directory)
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;
// Creating the captcha instance and setting the phrase in the session to store
// it for check when the form is submitted
$captcha = new CaptchaBuilder;
$_SESSION['phrase'] = $captcha->getPhrase();
// Setting the header to image jpeg because we here render an image
header('Content-Type: image/jpeg');
// Running the actual rendering of the captcha image
$captcha
->build()
->output()
;

View File

@@ -26,7 +26,7 @@ class CaptchaBuilder implements CaptchaBuilderInterface
/**
* @var array
*/
protected $textColor = null;
protected $textColor = array();
/**
* @var array
@@ -135,12 +135,8 @@ class CaptchaBuilder implements CaptchaBuilderInterface
} else {
$this->builder = $builder;
}
if ($phrase === null) {
$phrase = $this->builder->build();
}
$this->phrase = $phrase;
$this->phrase = is_string($phrase) ? $phrase : $this->builder->build($phrase);
}
/**

View File

@@ -21,7 +21,7 @@ class PhraseBuilder implements PhraseBuilderInterface
/**
* Constructs a PhraseBuilder with given parameters
*/
public function __construct($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789')
public function __construct($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$this->length = $length;
$this->charset = $charset;
@@ -53,7 +53,23 @@ class PhraseBuilder implements PhraseBuilderInterface
* "Niceize" a code
*/
public function niceize($str)
{
return self::doNiceize($str);
}
/**
* A static helper to niceize
*/
public static function doNiceize($str)
{
return strtr(strtolower($str), '01', 'ol');
}
/**
* A static helper to compare
*/
public static function comparePhrases($str1, $str2)
{
return self::doNiceize($str1) === self::doNiceize($str2);
}
}