Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 399 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Eloquent\Factories;
4
 
5
use Countable;
6
 
7
class Sequence implements Countable
8
{
9
    /**
10
     * The sequence of return values.
11
     *
12
     * @var array
13
     */
14
    protected $sequence;
15
 
16
    /**
17
     * The count of the sequence items.
18
     *
19
     * @var int
20
     */
21
    public $count;
22
 
23
    /**
24
     * The current index of the sequence iteration.
25
     *
26
     * @var int
27
     */
28
    public $index = 0;
29
 
30
    /**
31
     * Create a new sequence instance.
32
     *
33
     * @param  array  $sequence
34
     * @return void
35
     */
36
    public function __construct(...$sequence)
37
    {
38
        $this->sequence = $sequence;
39
        $this->count = count($sequence);
40
    }
41
 
42
    /**
43
     * Get the current count of the sequence items.
44
     *
45
     * @return int
46
     */
47
    public function count(): int
48
    {
49
        return $this->count;
50
    }
51
 
52
    /**
53
     * Get the next value in the sequence.
54
     *
55
     * @return mixed
56
     */
57
    public function __invoke()
58
    {
59
        return tap(value($this->sequence[$this->index % $this->count], $this), function () {
60
            $this->index = $this->index + 1;
61
        });
62
    }
63
}