PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.41
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.41
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / vendor / wpfluent / framework / src / WPFluent / Support / Once.php

Once.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.41, at vendor/wpfluent/framework/src/WPFluent/Support/Once.php

92 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\Framework\Support;
4
5 class Once
6 {
7 protected $trace = null;
8
9 protected $zeroStack = null;
10
11 public function __construct(array $trace)
12 {
13 $this->trace = $trace[1];
14
15 $this->zeroStack = $trace[0];
16 }
17
18 public function getArguments()
19 {
20 return $this->trace['args'];
21 }
22
23 public function getFunctionName()
24 {
25 return $this->trace['function'];
26 }
27
28 public function getObjectName()
29 {
30 return $this->trace['class'] ?? null;
31 }
32
33 public function getObject()
34 {
35 if ($this->globalFunction()) {
36 return $this->zeroStack['file'];
37 }
38
39 return $this->staticCall() ? $this->trace['class'] : $this->trace['object'];
40 }
41
42 public function getHash($strict)
43 {
44 $normalizedArguments = array_map(function ($argument) {
45 return is_object($argument) ? spl_object_hash($argument) : $argument;
46 }, $this->getArguments());
47
48 $object = $this->getObject();
49
50 $prefix = $this->getObjectName() . $this->getFunctionName();
51
52 if ($strict) {
53 $prefix .= is_object($object) ? spl_object_id($object) : $object;
54 }
55
56 if (str_contains($prefix, '{closure')) {
57 $prefix = $this->zeroStack['line'];
58 }
59
60 return md5($prefix.serialize($normalizedArguments));
61 }
62
63 protected function staticCall()
64 {
65 return $this->trace['type'] === '::';
66 }
67
68 protected function globalFunction()
69 {
70 return !isset($this->trace['type']);
71 }
72
73 public static function call(callable $callback, $strict = false)
74 {
75 $backtrace = new static(debug_backtrace(
76 DEBUG_BACKTRACE_PROVIDE_OBJECT, 2
77 ));
78
79 $hash = $backtrace->getHash($strict);
80
81 if (!$result = wp_cache_get($hash)) {
82 wp_cache_set(
83 $hash, call_user_func_array(
84 $callback, $backtrace->getArguments()
85 )
86 );
87 }
88
89 return wp_cache_get($hash);
90 }
91 }
92