Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
52 public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null) | 52 public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null) |
53 { | 53 { |
54 $file = $this->getIndexFilename(); | 54 $file = $this->getIndexFilename(); |
55 | 55 |
56 if (!file_exists($file)) { | 56 if (!file_exists($file)) { |
57 return array(); | 57 return []; |
58 } | 58 } |
59 | 59 |
60 $file = fopen($file, 'r'); | 60 $file = fopen($file, 'r'); |
61 fseek($file, 0, SEEK_END); | 61 fseek($file, 0, SEEK_END); |
62 | 62 |
63 $result = array(); | 63 $result = []; |
64 while (count($result) < $limit && $line = $this->readLineFromFile($file)) { | 64 while (\count($result) < $limit && $line = $this->readLineFromFile($file)) { |
65 $values = str_getcsv($line); | 65 $values = str_getcsv($line); |
66 list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values; | 66 list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values; |
67 $csvTime = (int) $csvTime; | 67 $csvTime = (int) $csvTime; |
68 | 68 |
69 if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) { | 69 if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) { |
76 | 76 |
77 if (!empty($end) && $csvTime > $end) { | 77 if (!empty($end) && $csvTime > $end) { |
78 continue; | 78 continue; |
79 } | 79 } |
80 | 80 |
81 $result[$csvToken] = array( | 81 $result[$csvToken] = [ |
82 'token' => $csvToken, | 82 'token' => $csvToken, |
83 'ip' => $csvIp, | 83 'ip' => $csvIp, |
84 'method' => $csvMethod, | 84 'method' => $csvMethod, |
85 'url' => $csvUrl, | 85 'url' => $csvUrl, |
86 'time' => $csvTime, | 86 'time' => $csvTime, |
87 'parent' => $csvParent, | 87 'parent' => $csvParent, |
88 'status_code' => $csvStatusCode, | 88 'status_code' => $csvStatusCode, |
89 ); | 89 ]; |
90 } | 90 } |
91 | 91 |
92 fclose($file); | 92 fclose($file); |
93 | 93 |
94 return array_values($result); | 94 return array_values($result); |
134 $file = $this->getFilename($profile->getToken()); | 134 $file = $this->getFilename($profile->getToken()); |
135 | 135 |
136 $profileIndexed = is_file($file); | 136 $profileIndexed = is_file($file); |
137 if (!$profileIndexed) { | 137 if (!$profileIndexed) { |
138 // Create directory | 138 // Create directory |
139 $dir = dirname($file); | 139 $dir = \dirname($file); |
140 if (!is_dir($dir) && false === @mkdir($dir, 0777, true) && !is_dir($dir)) { | 140 if (!is_dir($dir) && false === @mkdir($dir, 0777, true) && !is_dir($dir)) { |
141 throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $dir)); | 141 throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $dir)); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
149 $childrenToken = array_filter(array_map(function ($p) use ($profileToken) { | 149 $childrenToken = array_filter(array_map(function ($p) use ($profileToken) { |
150 return $profileToken !== $p->getToken() ? $p->getToken() : null; | 150 return $profileToken !== $p->getToken() ? $p->getToken() : null; |
151 }, $profile->getChildren())); | 151 }, $profile->getChildren())); |
152 | 152 |
153 // Store profile | 153 // Store profile |
154 $data = array( | 154 $data = [ |
155 'token' => $profileToken, | 155 'token' => $profileToken, |
156 'parent' => $parentToken, | 156 'parent' => $parentToken, |
157 'children' => $childrenToken, | 157 'children' => $childrenToken, |
158 'data' => $profile->getCollectors(), | 158 'data' => $profile->getCollectors(), |
159 'ip' => $profile->getIp(), | 159 'ip' => $profile->getIp(), |
160 'method' => $profile->getMethod(), | 160 'method' => $profile->getMethod(), |
161 'url' => $profile->getUrl(), | 161 'url' => $profile->getUrl(), |
162 'time' => $profile->getTime(), | 162 'time' => $profile->getTime(), |
163 'status_code' => $profile->getStatusCode(), | 163 'status_code' => $profile->getStatusCode(), |
164 ); | 164 ]; |
165 | 165 |
166 if (false === file_put_contents($file, serialize($data))) { | 166 if (false === file_put_contents($file, serialize($data))) { |
167 return false; | 167 return false; |
168 } | 168 } |
169 | 169 |
171 // Add to index | 171 // Add to index |
172 if (false === $file = fopen($this->getIndexFilename(), 'a')) { | 172 if (false === $file = fopen($this->getIndexFilename(), 'a')) { |
173 return false; | 173 return false; |
174 } | 174 } |
175 | 175 |
176 fputcsv($file, array( | 176 fputcsv($file, [ |
177 $profile->getToken(), | 177 $profile->getToken(), |
178 $profile->getIp(), | 178 $profile->getIp(), |
179 $profile->getMethod(), | 179 $profile->getMethod(), |
180 $profile->getUrl(), | 180 $profile->getUrl(), |
181 $profile->getTime(), | 181 $profile->getTime(), |
182 $profile->getParentToken(), | 182 $profile->getParentToken(), |
183 $profile->getStatusCode(), | 183 $profile->getStatusCode(), |
184 )); | 184 ]); |
185 fclose($file); | 185 fclose($file); |
186 } | 186 } |
187 | 187 |
188 return true; | 188 return true; |
189 } | 189 } |