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 Illuminate\Database\Eloquent\Casts;
4
 
5
class Attribute
6
{
7
    /**
8
     * The attribute accessor.
9
     *
10
     * @var callable
11
     */
12
    public $get;
13
 
14
    /**
15
     * The attribute mutator.
16
     *
17
     * @var callable
18
     */
19
    public $set;
20
 
21
    /**
22
     * Indicates if caching is enabled for this attribute.
23
     *
24
     * @var bool
25
     */
26
    public $withCaching = false;
27
 
28
    /**
29
     * Indicates if caching of objects is enabled for this attribute.
30
     *
31
     * @var bool
32
     */
33
    public $withObjectCaching = true;
34
 
35
    /**
36
     * Create a new attribute accessor / mutator.
37
     *
38
     * @param  callable|null  $get
39
     * @param  callable|null  $set
40
     * @return void
41
     */
42
    public function __construct(callable $get = null, callable $set = null)
43
    {
44
        $this->get = $get;
45
        $this->set = $set;
46
    }
47
 
48
    /**
49
     * Create a new attribute accessor / mutator.
50
     *
51
     * @param  callable|null  $get
52
     * @param  callable|null  $set
53
     * @return static
54
     */
55
    public static function make(callable $get = null, callable $set = null): static
56
    {
57
        return new static($get, $set);
58
    }
59
 
60
    /**
61
     * Create a new attribute accessor.
62
     *
63
     * @param  callable  $get
64
     * @return static
65
     */
66
    public static function get(callable $get)
67
    {
68
        return new static($get);
69
    }
70
 
71
    /**
72
     * Create a new attribute mutator.
73
     *
74
     * @param  callable  $set
75
     * @return static
76
     */
77
    public static function set(callable $set)
78
    {
79
        return new static(null, $set);
80
    }
81
 
82
    /**
83
     * Disable object caching for the attribute.
84
     *
85
     * @return static
86
     */
87
    public function withoutObjectCaching()
88
    {
89
        $this->withObjectCaching = false;
90
 
91
        return $this;
92
    }
93
 
94
    /**
95
     * Enable caching for the attribute.
96
     *
97
     * @return static
98
     */
99
    public function shouldCache()
100
    {
101
        $this->withCaching = true;
102
 
103
        return $this;
104
    }
105
}