PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.5
Independent Analytics – WordPress Analytics Plugin v2.15.5
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Eloquent / Concerns / HasTimestamps.php
independent-analytics / vendor / illuminate / database / Eloquent / Concerns Last commit date
GuardsAttributes.php 1 month ago HasAttributes.php 1 month ago HasEvents.php 1 month ago HasGlobalScopes.php 1 month ago HasRelationships.php 1 month ago HasTimestamps.php 1 month ago HasUlids.php 1 month ago HasUuids.php 1 month ago HidesAttributes.php 1 month ago QueriesRelationships.php 1 month ago
HasTimestamps.php
195 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Eloquent\Concerns;
4
5 use IAWPSCOPED\Illuminate\Support\Facades\Date;
6 /** @internal */
7 trait HasTimestamps
8 {
9 /**
10 * Indicates if the model should be timestamped.
11 *
12 * @var bool
13 */
14 public $timestamps = \true;
15 /**
16 * The list of models classes that have timestamps temporarily disabled.
17 *
18 * @var array
19 */
20 protected static $ignoreTimestampsOn = [];
21 /**
22 * Update the model's update timestamp.
23 *
24 * @param string|null $attribute
25 * @return bool
26 */
27 public function touch($attribute = null)
28 {
29 if ($attribute) {
30 $this->{$attribute} = $this->freshTimestamp();
31 return $this->save();
32 }
33 if (!$this->usesTimestamps()) {
34 return \false;
35 }
36 $this->updateTimestamps();
37 return $this->save();
38 }
39 /**
40 * Update the model's update timestamp without raising any events.
41 *
42 * @param string|null $attribute
43 * @return bool
44 */
45 public function touchQuietly($attribute = null)
46 {
47 return static::withoutEvents(fn() => $this->touch($attribute));
48 }
49 /**
50 * Update the creation and update timestamps.
51 *
52 * @return $this
53 */
54 public function updateTimestamps()
55 {
56 $time = $this->freshTimestamp();
57 $updatedAtColumn = $this->getUpdatedAtColumn();
58 if (!\is_null($updatedAtColumn) && !$this->isDirty($updatedAtColumn)) {
59 $this->setUpdatedAt($time);
60 }
61 $createdAtColumn = $this->getCreatedAtColumn();
62 if (!$this->exists && !\is_null($createdAtColumn) && !$this->isDirty($createdAtColumn)) {
63 $this->setCreatedAt($time);
64 }
65 return $this;
66 }
67 /**
68 * Set the value of the "created at" attribute.
69 *
70 * @param mixed $value
71 * @return $this
72 */
73 public function setCreatedAt($value)
74 {
75 $this->{$this->getCreatedAtColumn()} = $value;
76 return $this;
77 }
78 /**
79 * Set the value of the "updated at" attribute.
80 *
81 * @param mixed $value
82 * @return $this
83 */
84 public function setUpdatedAt($value)
85 {
86 $this->{$this->getUpdatedAtColumn()} = $value;
87 return $this;
88 }
89 /**
90 * Get a fresh timestamp for the model.
91 *
92 * @return \Illuminate\Support\Carbon
93 */
94 public function freshTimestamp()
95 {
96 return Date::now();
97 }
98 /**
99 * Get a fresh timestamp for the model.
100 *
101 * @return string
102 */
103 public function freshTimestampString()
104 {
105 return $this->fromDateTime($this->freshTimestamp());
106 }
107 /**
108 * Determine if the model uses timestamps.
109 *
110 * @return bool
111 */
112 public function usesTimestamps()
113 {
114 return $this->timestamps && !static::isIgnoringTimestamps($this::class);
115 }
116 /**
117 * Get the name of the "created at" column.
118 *
119 * @return string|null
120 */
121 public function getCreatedAtColumn()
122 {
123 return static::CREATED_AT;
124 }
125 /**
126 * Get the name of the "updated at" column.
127 *
128 * @return string|null
129 */
130 public function getUpdatedAtColumn()
131 {
132 return static::UPDATED_AT;
133 }
134 /**
135 * Get the fully qualified "created at" column.
136 *
137 * @return string|null
138 */
139 public function getQualifiedCreatedAtColumn()
140 {
141 return $this->qualifyColumn($this->getCreatedAtColumn());
142 }
143 /**
144 * Get the fully qualified "updated at" column.
145 *
146 * @return string|null
147 */
148 public function getQualifiedUpdatedAtColumn()
149 {
150 return $this->qualifyColumn($this->getUpdatedAtColumn());
151 }
152 /**
153 * Disable timestamps for the current class during the given callback scope.
154 *
155 * @param callable $callback
156 * @return mixed
157 */
158 public static function withoutTimestamps(callable $callback)
159 {
160 return static::withoutTimestampsOn([static::class], $callback);
161 }
162 /**
163 * Disable timestamps for the given model classes during the given callback scope.
164 *
165 * @param array $models
166 * @param callable $callback
167 * @return mixed
168 */
169 public static function withoutTimestampsOn($models, $callback)
170 {
171 static::$ignoreTimestampsOn = \array_values(\array_merge(static::$ignoreTimestampsOn, $models));
172 try {
173 return $callback();
174 } finally {
175 static::$ignoreTimestampsOn = \array_values(\array_diff(static::$ignoreTimestampsOn, $models));
176 }
177 }
178 /**
179 * Determine if the given model is ignoring timestamps / touches.
180 *
181 * @param string|null $class
182 * @return bool
183 */
184 public static function isIgnoringTimestamps($class = null)
185 {
186 $class ??= static::class;
187 foreach (static::$ignoreTimestampsOn as $ignoredClass) {
188 if ($class === $ignoredClass || \is_subclass_of($class, $ignoredClass)) {
189 return \true;
190 }
191 }
192 return \false;
193 }
194 }
195