Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Faker;
4
 
5
use Faker\Extension\Extension;
6
 
7
/**
8
 * This generator returns a default value for all called properties
9
 * and methods. It works with Faker\Generator::optional().
10
 *
11
 * @mixin Generator
12
 */
13
class ChanceGenerator
14
{
15
    private $generator;
16
    private $weight;
17
    protected $default;
18
 
19
    /**
20
     * @param Extension|Generator $generator
21
     */
22
    public function __construct($generator, float $weight, $default = null)
23
    {
24
        $this->default = $default;
25
        $this->generator = $generator;
26
        $this->weight = $weight;
27
    }
28
 
29
    public function ext(string $id)
30
    {
31
        return new self($this->generator->ext($id), $this->weight, $this->default);
32
    }
33
 
34
    /**
35
     * Catch and proxy all generator calls but return only valid values
36
     *
37
     * @param string $attribute
38
     *
39
     * @deprecated Use a method instead.
40
     */
41
    public function __get($attribute)
42
    {
43
        trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute);
44
 
45
        return $this->__call($attribute, []);
46
    }
47
 
48
    /**
49
     * @param string $name
50
     * @param array  $arguments
51
     */
52
    public function __call($name, $arguments)
53
    {
54
        if (mt_rand(1, 100) <= (100 * $this->weight)) {
55
            return call_user_func_array([$this->generator, $name], $arguments);
56
        }
57
 
58
        return $this->default;
59
    }
60
}