98a3faf462b8a103a24b8695dcb4e4b65ff07b68
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / DataCollector / DrupalDataCollectorTrait.php
1 <?php
2
3 namespace Drupal\webprofiler\DataCollector;
4
5 /**
6  * Class DrupalDataCollectorTrait
7  */
8 trait DrupalDataCollectorTrait {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getPanelSummary() {
14     return NULL;
15   }
16
17   /**
18    * {@inheritdoc}
19    */
20   public function hasPanel() {
21     return TRUE;
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getLibraries() {
28     return [];
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getDrupalSettings() {
35     return [];
36   }
37
38   /**
39    * @return mixed
40    */
41   public function getData() {
42     return $this->data;
43   }
44
45   /**
46    * @param $class
47    * @param $method
48    *
49    * @return array
50    *
51    * @throws \ReflectionException
52    */
53   public function getMethodData($class, $method) {
54     $class = is_object($class) ? get_class($class) : $class;
55     $data = [];
56
57     try {
58       $reflectedMethod = new \ReflectionMethod($class, $method);
59
60       $data = [
61         'class' => $class,
62         'method' => $method,
63         'file' => $reflectedMethod->getFilename(),
64         'line' => $reflectedMethod->getStartLine(),
65       ];
66     } catch (\ReflectionException $re) {
67       // TODO: handle the exception.
68     } finally {
69       return $data;
70     }
71   }
72
73   /**
74    * @param $value
75    *
76    * @return int|string
77    */
78   private function convertToBytes($value) {
79     if ('-1' === $value) {
80       return -1;
81     }
82
83     $value = strtolower($value);
84     $max = strtolower(ltrim($value, '+'));
85     if (0 === strpos($max, '0x')) {
86       $max = intval($max, 16);
87     }
88     elseif (0 === strpos($max, '0')) {
89       $max = intval($max, 8);
90     }
91     else {
92       $max = intval($max);
93     }
94
95     switch (substr($value, -1)) {
96       case 't':
97         $max *= 1024;
98         break;
99
100       case 'g':
101         $max *= 1024;
102         break;
103
104       case 'm':
105         $max *= 1024;
106         break;
107
108       case 'k':
109         $max *= 1024;
110         break;
111     }
112
113     return $max;
114   }
115 }