Skip to content

Commit

Permalink
Use random_bytes instead of uniqid (#183)
Browse files Browse the repository at this point in the history
* use random_bytes instead of uniqid

on windows there is a chance to get the same uuid by using uniqid

* added PHP 5.x polyfill for the PHP7 random_bytes() method
  • Loading branch information
saimaz authored Jan 18, 2017
1 parent 41d449c commit 12a601d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
],
"require": {
"php": ">=5.4",
"symfony/serializer": "~2.7|~3.0"
"symfony/serializer": "~2.7|~3.0",
"paragonie/random_compat": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.4|^5.6",
Expand Down
3 changes: 2 additions & 1 deletion src/Query/BoolQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
use Ramsey\Uuid\Uuid;

/**
* Represents Elasticsearch "bool" query.
Expand Down Expand Up @@ -85,7 +86,7 @@ public function add(BuilderInterface $query, $type = self::MUST, $key = null)
}

if (!$key) {
$key = uniqid();
$key = bin2hex(random_bytes(30));
}

$this->container[$type][$key] = $query;
Expand Down

0 comments on commit 12a601d

Please sign in to comment.