Update composer dependencies

This commit is contained in:
Frédéric Guillot
2017-12-15 13:27:25 -08:00
parent a93b8e10f5
commit 8e6476b402
290 changed files with 8037 additions and 2176 deletions

View File

@@ -1,3 +1,4 @@
demo/*.jpg
demo/*.pgm
demo/temp/
vendor/

View File

@@ -6,6 +6,10 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
script:
- composer install

View File

@@ -1,4 +1,4 @@
Copyright (c) <2012-2015> Grégoire Passault
Copyright (c) <2012-2017> Grégoire Passault
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,34 +0,0 @@
<?php
namespace Gregwar\Captcha;
/**
* Generates random phrase
*
* @author Gregwar <g.passault@gmail.com>
*/
class PhraseBuilder implements PhraseBuilderInterface
{
/**
* Generates random phrase of given length with given charset
*/
public function build($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789')
{
$phrase = '';
$chars = str_split($charset);
for ($i = 0; $i < $length; $i++) {
$phrase .= $chars[array_rand($chars)];
}
return $phrase;
}
/**
* "Niceize" a code
*/
public function niceize($str)
{
return strtr(strtolower($str), '01', 'ol');
}
}

View File

@@ -2,6 +2,7 @@ Captcha
=======
![Captchas examples](http://gregwar.com/captchas.png)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L)
Installation
============
@@ -96,12 +97,43 @@ You can use theses functions :
* **setMaxBehindLines($lines)**, sets the maximum number of lines behind the code
* **setMaxFrontLines($lines)**, sets the maximum number of lines on the front of the code
Symfony 2 Bundle
If you want to change the number of character, you can call the phrase builder directly using
extra parameters:
```php
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
// Will build phrases of 3 characters
$phraseBuilder = new PhraseBuilder(4)
// Will build phrases of 5 characters, only digits
$phraseBuilder = new PhraseBuilder(5, '0123456789');
// Pass it as first argument of CaptchaBuilder, passing it the phrase
// builder
$captcha = new CaptchaBuilder(null, $phraseBuilder);
```
You can also pass directly the wanted phrase to the builder:
```php
// Building a Captcha with the "hello" phrase
$captcha = new CaptchaBuilder('hello');
```
Symfony Bundle
================
You can have a look at the following repository to enjoy the Symfony 2 bundle packaging this captcha generator :
https://github.com/Gregwar/CaptchaBundle
Yii2 Extension
===============
You can use the following extension for integrating with Yii2 Framework :
https://github.com/juliardi/yii2-captcha
License
=======

View File

@@ -1,16 +0,0 @@
<?php
/**
* Registers an autoload for all the classes in Gregwar\Captcha
*/
spl_autoload_register(function ($className) {
$namespace = 'Gregwar\\Captcha';
if (strpos($className, $namespace) === 0) {
$className = str_replace($namespace, '', $className);
$fileName = __DIR__ . '/' . str_replace('\\', '/', $className) . '.php';
if (file_exists($fileName)) {
require($fileName);
}
}
});

View File

@@ -18,11 +18,16 @@
],
"require": {
"php": ">=5.3.0",
"ext-gd": "*"
"ext-gd": "*",
"ext-mbstring": "*",
"symfony/finder": "~3.0"
},
"autoload": {
"psr-4": {
"Gregwar\\Captcha\\": "/"
"Gregwar\\": "src/Gregwar"
}
},
"require-dev": {
"phpunit/phpunit": "^6.4"
}
}

View File

@@ -1,9 +1,6 @@
<?php
include(__DIR__.'/../CaptchaBuilderInterface.php');
include(__DIR__.'/../PhraseBuilderInterface.php');
include(__DIR__.'/../CaptchaBuilder.php');
include(__DIR__.'/../PhraseBuilder.php');
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;

View File

@@ -1,9 +1,6 @@
<?php
include(__DIR__.'/../CaptchaBuilderInterface.php');
include(__DIR__.'/../PhraseBuilderInterface.php');
include(__DIR__.'/../CaptchaBuilder.php');
include(__DIR__.'/../PhraseBuilder.php');
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;

View File

@@ -1,9 +1,6 @@
<?php
include(__DIR__.'/../CaptchaBuilderInterface.php');
include(__DIR__.'/../PhraseBuilderInterface.php');
include(__DIR__.'/../CaptchaBuilder.php');
include(__DIR__.'/../PhraseBuilder.php');
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;

View File

@@ -1,9 +1,6 @@
<?php
include(__DIR__.'/../CaptchaBuilderInterface.php');
include(__DIR__.'/../PhraseBuilderInterface.php');
include(__DIR__.'/../CaptchaBuilder.php');
include(__DIR__.'/../PhraseBuilder.php');
require_once __DIR__.'/../vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;

15
vendor/gregwar/captcha/phpunit.xml.dist vendored Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="KnpMenu Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -317,33 +317,34 @@ class CaptchaBuilder implements CaptchaBuilderInterface
*/
protected function writePhrase($image, $phrase, $font, $width, $height)
{
$length = strlen($phrase);
$length = mb_strlen($phrase);
if ($length === 0) {
return imagecolorallocate($image, 0, 0, 0);
return \imagecolorallocate($image, 0, 0, 0);
}
// Gets the text size and start position
$size = $width / $length - $this->rand(0, 3) - 1;
$box = imagettfbbox($size, 0, $font, $phrase);
$box = \imagettfbbox($size, 0, $font, $phrase);
$textWidth = $box[2] - $box[0];
$textHeight = $box[1] - $box[7];
$x = ($width - $textWidth) / 2;
$y = ($height - $textHeight) / 2 + $size;
if (!count($this->textColor)) {
if (!$this->textColor) {
$textColor = array($this->rand(0, 150), $this->rand(0, 150), $this->rand(0, 150));
} else {
$textColor = $this->textColor;
}
$col = imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]);
$col = \imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]);
// Write the letters one by one, with random angle
for ($i=0; $i<$length; $i++) {
$box = imagettfbbox($size, 0, $font, $phrase[$i]);
$symbol = mb_substr($phrase, $i, 1);
$box = \imagettfbbox($size, 0, $font, $symbol);
$w = $box[2] - $box[0];
$angle = $this->rand(-$this->maxAngle, $this->maxAngle);
$offset = $this->rand(-$this->maxOffset, $this->maxOffset);
imagettftext($image, $size, $angle, $x, $y + $offset, $col, $font, $phrase[$i]);
\imagettftext($image, $size, $angle, $x, $y + $offset, $col, $font, $symbol);
$x += $w;
}
@@ -682,7 +683,7 @@ class CaptchaBuilder implements CaptchaBuilderInterface
$imageType = finfo_file($finfo, $backgroundImage);
finfo_close($finfo);
if (!in_array ($imageType, $this->allowedBackgroundImageTypes)) {
if (!in_array($imageType, $this->allowedBackgroundImageTypes)) {
throw new Exception('Invalid background image type! Allowed types are: ' . join(', ', $this->allowedBackgroundImageTypes));
}

View File

@@ -27,4 +27,3 @@ interface CaptchaBuilderInterface
*/
public function output($quality);
}

View File

@@ -86,7 +86,7 @@ class ImageFileHandler
$finder->in($this->webPath . '/' . $this->imageFolder)
->date($criteria);
foreach($finder->files() as $file) {
foreach ($finder->files() as $file) {
unlink($file->getPathname());
}
@@ -103,4 +103,3 @@ class ImageFileHandler
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Gregwar\Captcha;
/**
* Generates random phrase
*
* @author Gregwar <g.passault@gmail.com>
*/
class PhraseBuilder implements PhraseBuilderInterface
{
/**
* @var int
*/
public $length;
/**
* @var string
*/
public $charset;
/**
* Constructs a PhraseBuilder with given parameters
*/
public function __construct($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789')
{
$this->length = $length;
$this->charset = $charset;
}
/**
* Generates random phrase of given length with given charset
*/
public function build($length = null, $charset = null)
{
if ($length !== null) {
$this->length = $length;
}
if ($charset !== null) {
$this->charset = $charset;
}
$phrase = '';
$chars = str_split($this->charset);
for ($i = 0; $i < $this->length; $i++) {
$phrase .= $chars[array_rand($chars)];
}
return $phrase;
}
/**
* "Niceize" a code
*/
public function niceize($str)
{
return strtr(strtolower($str), '01', 'ol');
}
}

View File

@@ -12,7 +12,7 @@ interface PhraseBuilderInterface
/**
* Generates random phrase of given length with given charset
*/
public function build($length, $charset);
public function build();
/**
* "Niceize" a code

View File

@@ -0,0 +1,30 @@
<?php
namespace Test;
use Gregwar\Captcha\CaptchaBuilder;
use PHPUnit\Framework\TestCase;
class CaptchaBuilderTest extends TestCase
{
public function testDemo()
{
$captcha = new CaptchaBuilder();
$captcha
->build()
->save('out.jpg')
;
$this->assertTrue(file_exists(__DIR__.'/../out.jpg'));
}
public function testFingerPrint()
{
$int = count(CaptchaBuilder::create()
->build()
->getFingerprint()
);
$this->assertTrue(is_int($int));
}
}