<?php

class Builder
{
	public $limit;

	public function take($value)
    {
        return $this->limit($value);
    }

    public function limit($value)
    {
    	$this->limit = $value;
    	return $this;
    }

	public function when($value, $callback, $default = null)
    {
        if ($value) {
            return $callback($this, $value) ?: $this;
        } elseif ($default) {
            return $default($this, $value) ?: $this;
        }

        return $this;
    }

    public function tap($callback)
    {
        return $this->when(true, $callback);
    }
}

$builder = new Builder();

$builder
->when(1, function($q) {
	return $q->take(3);
})
->tap(function($q) {
	return $q->take(4);
});

print_r($builder);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
上次更新: 6/30/2020, 11:43:11 PM