|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the BazingaGeocoderBundle package. |
| 5 | + * For the full copyright and license information, please view the LICENSE |
| 6 | + * file that was distributed with this source code. |
| 7 | + * |
| 8 | + * @license MIT License |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Bazinga\GeocoderBundle\DataCollector; |
| 12 | + |
| 13 | +use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin; |
| 14 | +use Symfony\Component\HttpFoundation\Request; |
| 15 | +use Symfony\Component\HttpFoundation\Response; |
| 16 | +use Symfony\Component\HttpKernel\Kernel; |
| 17 | + |
| 18 | +if (Kernel::VERSION_ID >= 40308) { |
| 19 | + trait DataCollectorSymfonyCompatibilityTrait |
| 20 | + { |
| 21 | + /** |
| 22 | + * {@inheritdoc} |
| 23 | + */ |
| 24 | + public function collect(Request $request, Response $response, \Throwable $exception = null) |
| 25 | + { |
| 26 | + if (!empty($this->data['queries'])) { |
| 27 | + // To avoid collection more that once. |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + /** @var ProfilingPlugin[] $instances */ |
| 32 | + $instances = $this->instances; |
| 33 | + |
| 34 | + foreach ($instances as $instance) { |
| 35 | + foreach ($instance->getQueries() as $query) { |
| 36 | + $query['query'] = $this->cloneVar($query['query']); |
| 37 | + $query['result'] = $this->cloneVar($query['result']); |
| 38 | + $this->data['queries'][] = $query; |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} else { |
| 44 | + trait DataCollectorSymfonyCompatibilityTrait |
| 45 | + { |
| 46 | + /** |
| 47 | + * {@inheritdoc} |
| 48 | + */ |
| 49 | + public function collect(Request $request, Response $response, \Exception $exception = null) |
| 50 | + { |
| 51 | + if (!empty($this->data['queries'])) { |
| 52 | + // To avoid collection more that once. |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + /** @var ProfilingPlugin[] $instances */ |
| 57 | + $instances = $this->instances; |
| 58 | + |
| 59 | + foreach ($instances as $instance) { |
| 60 | + foreach ($instance->getQueries() as $query) { |
| 61 | + $query['query'] = $this->cloneVar($query['query']); |
| 62 | + $query['result'] = $this->cloneVar($query['result']); |
| 63 | + $this->data['queries'][] = $query; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments