Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready to use in Symfony3 #28

Merged
merged 6 commits into from
Apr 12, 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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: php
sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand All @@ -16,7 +15,6 @@ matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: 7.0

before_install:
- composer selfupdate
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name":"vivait/string-generator-bundle",
"license": "MIT",
"description":"Generate random strings for IDs or keys using property annotations",
Expand All @@ -11,11 +11,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.3.3",
"php": ">=5.5.3",
"doctrine/common": "~2.2",
"doctrine/orm": "~2.2",
"symfony/security": "~2.1",
"symfony/options-resolver": "~2.1",
"symfony/polyfill-php70": "^1.3",
"symfony/security": "^2.8|^3.0",
"symfony/options-resolver": "^2.8|^3.0",
"ircmaxell/random-lib": "~1.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Security\Core\Util\SecureRandom;

class SecureBytesGeneratorSpec extends ObjectBehavior
{
Expand All @@ -13,12 +12,6 @@ function it_is_initializable()
$this->shouldHaveType('Vivait\StringGeneratorBundle\Generator\SecureBytesGenerator');
}

function let()
{
$secureRandom = new SecureRandom();
$this->beConstructedWith($secureRandom);
}

function it_generates_random_string()
{
$this->setLength(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Vivait\StringGeneratorBundle\Generator;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Util\SecureRandom;
use Vivait\StringGeneratorBundle\Model\ConfigurableGeneratorInterface;

class SecureBytesGenerator implements ConfigurableGeneratorInterface
Expand All @@ -14,14 +13,6 @@ class SecureBytesGenerator implements ConfigurableGeneratorInterface
private $secureRandom;
private $length = 8;

/**
* @param SecureRandom $secureRandom
*/
public function __construct(SecureRandom $secureRandom)
{
$this->secureRandom = $secureRandom;
}

/**
* @param integer $length
* @return ConfigurableGeneratorInterface
Expand All @@ -37,7 +28,7 @@ public function setLength($length)
*/
public function generate()
{
return $this->secureRandom->nextBytes($this->length);
return random_bytes($this->length);
Copy link
Contributor

@leightonthomas leightonthomas Mar 28, 2017

Choose a reason for hiding this comment

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

random_bytes() only seems to be available in PHP 7 - perhaps https://github.com/symfony/polyfill-php70 could be used?

edit: didn't realise this was already included by symfony security stuff, my bad!

Copy link
Contributor

Choose a reason for hiding this comment

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

However, I think if we're going to rely on random_bytes, we need to be explicit in the polyfill package as a dependency of ours.

We can't necessarily rely on the security component including it.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:

vivait_generator.generator.secure_bytes:
class: Vivait\StringGeneratorBundle\Generator\SecureBytesGenerator
arguments: ["@security.secure_random"]

vivait_generator.generator.secure_string:
class: Vivait\StringGeneratorBundle\Generator\SecureStringGenerator
Expand Down