1 | <?php |
||
2 | |||
3 | namespace Sunnysideup\Vardump; |
||
4 | |||
5 | use SilverStripe\ORM\FieldType\DBField; |
||
6 | |||
7 | /** |
||
8 | * small trait to make non-Viewable objects printable. |
||
9 | */ |
||
10 | trait DebugTrait |
||
11 | { |
||
12 | /** |
||
13 | * Get the value of a field on this object, automatically inserting the value into any available casting objects |
||
14 | * that have been specified. |
||
15 | * |
||
16 | * @param string $fieldName |
||
17 | * @param array $arguments |
||
18 | * @param bool $cache Cache this object |
||
19 | * @param string $cacheName a custom cache name |
||
20 | * |
||
21 | * @return null|DBField |
||
22 | */ |
||
23 | public function obj($fieldName, $arguments = [], $cache = false, $cacheName = null) |
||
24 | { |
||
25 | if (Vardump::inst()->isSafe()) { |
||
26 | $data = call_user_func_array([$this, $fieldName], $arguments ?: []); |
||
27 | |||
28 | return Vardump::inst()->vardumpMe($data, $fieldName, $this->VardumpClassName()); |
||
29 | } |
||
30 | |||
31 | return null; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * for debug purposes! |
||
36 | * |
||
37 | * @param string $method |
||
38 | * @param array $arguments - optional |
||
39 | */ |
||
40 | public function XML_val(?string $method, $arguments = []) |
||
41 | { |
||
42 | if (Vardump::inst()->isSafe()) { |
||
43 | if (! is_array($arguments)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
44 | $arguments = [$arguments]; |
||
45 | } |
||
46 | |||
47 | $data = $this->{$method}(...$arguments); |
||
48 | |||
49 | return Vardump::inst()->vardumpMe($data, $method, $this->VardumpClassName()); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | public function VardumpMe(string $method) |
||
54 | { |
||
55 | return Vardump::inst()->vardumpMe($this->{$method}(), $method, static::class); |
||
56 | } |
||
57 | |||
58 | public function ClassName(): string |
||
59 | { |
||
60 | return static::class; |
||
61 | } |
||
62 | |||
63 | public function VardumpClassName(): string |
||
64 | { |
||
65 | return static::class; |
||
66 | } |
||
67 | } |
||
68 |