PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / fzaninotto / faker / src / Faker / UniqueGenerator.php
kubio / vendor / fzaninotto / faker / src / Faker Last commit date
Calculator 1 year ago Guesser 1 year ago ORM 1 year ago Provider 1 year ago DefaultGenerator.php 1 year ago Documentor.php 1 year ago Factory.php 1 year ago Generator.php 1 year ago UniqueGenerator.php 1 year ago ValidGenerator.php 1 year ago
UniqueGenerator.php
59 lines
1 <?php
2
3 namespace Faker;
4
5 /**
6 * Proxy for other generators, to return only unique values. Works with
7 * Faker\Generator\Base->unique()
8 */
9 class UniqueGenerator
10 {
11 protected $generator;
12 protected $maxRetries;
13 protected $uniques = array();
14
15 /**
16 * @param Generator $generator
17 * @param integer $maxRetries
18 */
19 public function __construct(Generator $generator, $maxRetries = 10000)
20 {
21 $this->generator = $generator;
22 $this->maxRetries = $maxRetries;
23 }
24
25 /**
26 * Catch and proxy all generator calls but return only unique values
27 * @param string $attribute
28 * @return mixed
29 */
30 public function __get($attribute)
31 {
32 return $this->__call($attribute, array());
33 }
34
35 /**
36 * Catch and proxy all generator calls with arguments but return only unique values
37 * @param string $name
38 * @param array $arguments
39 * @return mixed
40 */
41 public function __call($name, $arguments)
42 {
43 if (!isset($this->uniques[$name])) {
44 $this->uniques[$name] = array();
45 }
46 $i = 0;
47 do {
48 $res = call_user_func_array(array($this->generator, $name), $arguments);
49 $i++;
50 if ($i > $this->maxRetries) {
51 throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
52 }
53 } while (array_key_exists(serialize($res), $this->uniques[$name]));
54 $this->uniques[$name][serialize($res)]= null;
55
56 return $res;
57 }
58 }
59