Skip to content

Commit 392de1c

Browse files
authored
First idea of how version 5 will look (#127)
* Starting to support geocoder v4 * Using provider factories to create providers * Factory fixes * Adding profiling provider * Do not profile if not debug * Remove services.xml * Added chain factory * Bugfixes * Bugfixes * Bugfixes * Fixed tests * Travis config update * Adding support for cache * Added change log
1 parent a814e09 commit 392de1c

37 files changed

+700
-1196
lines changed

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
language: php
22

3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache
8+
39
php:
4-
- 5.4
5-
- 5.5
6-
- 5.6
10+
- 7.0
11+
- 7.1
712

813
env:
9-
- SYMFONY_VERSION=2.3.*
10-
- SYMFONY_VERSION=2.5.*
11-
- SYMFONY_VERSION=2.7.*
12-
- SYMFONY_VERSION=2.8.*
14+
- SYMFONY_VERSION=3.3.*
1315
- SYMFONY_VERSION=dev-master
1416

1517
matrix:
1618
allow_failures:
1719
- env: SYMFONY_VERSION=dev-master
18-
- php: hhvm
19-
dist: trusty
20-
env: SYMFONY_VERSION=2.7.*
2120

2221
before_script:
2322
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
2423
# This command must be run with `--prefer-source`, otherwise the `Doctrine\Tests\OrmTestCase` class
2524
# won't be found.
2625
- composer update --prefer-source
2726

28-
script: phpunit --coverage-text
27+
script:
28+
- phpunit --coverage-text --coverage-clover=build/coverage.xml

BazingaGeocoderBundle.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use Symfony\Component\DependencyInjection\ContainerBuilder;
1313
use Symfony\Component\HttpKernel\Bundle\Bundle;
1414
use Bazinga\Bundle\GeocoderBundle\DependencyInjection\Compiler\AddProvidersPass;
15-
use Bazinga\Bundle\GeocoderBundle\DependencyInjection\Compiler\AddDumperPass;
16-
use Bazinga\Bundle\GeocoderBundle\DependencyInjection\Compiler\LoggablePass;
15+
use Bazinga\Bundle\GeocoderBundle\DependencyInjection\Compiler\ProfilerPass;
1716

1817
/**
1918
* @author William Durand <[email protected]>
@@ -27,8 +26,7 @@ public function build(ContainerBuilder $container)
2726
{
2827
parent::build($container);
2928

29+
$container->addCompilerPass(new ProfilerPass());
3030
$container->addCompilerPass(new AddProvidersPass());
31-
$container->addCompilerPass(new AddDumperPass());
32-
$container->addCompilerPass(new LoggablePass());
3331
}
3432
}

Changelog.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Changelog
2+
3+
The changelog describes what have been "Added", "Changed", "Removed" or "Fixed" between versions.
4+
5+
## Version 5.0.0
6+
7+
Version 5 does only support Symfony 3.3+ and PHP7. We dropped some complexity and added plenty of type hints.
8+
9+
### Added
10+
11+
- Support for Geocoder 4.0
12+
- Provider factories
13+
14+
### Changed
15+
16+
- We moved cache support to `geocoder-php/cache-provider`
17+
18+
### Removed
19+
20+
- `DumperManager`
21+
- `LoggableGeocoder`
22+
- Configuration for default provider
23+
24+
## Version 4.1.0
25+
26+
No changelog before this version

DataCollector/GeocoderDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GeocoderDataCollector extends DataCollector
2222
/**
2323
* @var GeocoderLogger
2424
*/
25-
protected $logger;
25+
private $logger;
2626

2727
/**
2828
* @param GeocoderLogger $logger
@@ -38,7 +38,7 @@ public function __construct(GeocoderLogger $logger)
3838
public function collect(Request $request, Response $response, \Exception $exception = null)
3939
{
4040
$this->data = array(
41-
'requests' => null !== $this->logger ? $this->logger->getRequests() : array(),
41+
'requests' => $this->logger->getRequests(),
4242
);
4343
}
4444

DataCollector/ProfilingProvider.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Bazinga\Bundle\GeocoderBundle\DataCollector;
4+
5+
use Bazinga\Bundle\GeocoderBundle\Logger\GeocoderLogger;
6+
use Geocoder\Collection;
7+
use Geocoder\Provider\Provider;
8+
use Geocoder\Query\GeocodeQuery;
9+
use Geocoder\Query\ReverseQuery;
10+
11+
/**
12+
* @author Tobias Nyholm <[email protected]>
13+
*/
14+
class ProfilingProvider implements Provider
15+
{
16+
/**
17+
* @var Provider
18+
*/
19+
private $realProvider;
20+
21+
/**
22+
* @var GeocoderLogger
23+
*/
24+
private $logger;
25+
26+
/**
27+
* @param Provider $realProvider
28+
* @param GeocoderLogger $logger
29+
*/
30+
public function __construct(Provider $realProvider, GeocoderLogger $logger)
31+
{
32+
$this->realProvider = $realProvider;
33+
$this->logger = $logger;
34+
}
35+
36+
public function geocodeQuery(GeocodeQuery $query): Collection
37+
{
38+
$startTime = microtime(true);
39+
try {
40+
$results = $this->realProvider->geocodeQuery($query);
41+
} finally {
42+
$duration = (microtime(true) - $startTime) * 1000;
43+
44+
$this->logger->logRequest(
45+
sprintf('[Geocoding] %s', $query),
46+
$duration,
47+
$this->getName(),
48+
$results
49+
);
50+
}
51+
52+
return $results;
53+
}
54+
55+
public function reverseQuery(ReverseQuery $query): Collection
56+
{
57+
$startTime = microtime(true);
58+
try {
59+
$results = $this->realProvider->reverseQuery($query);
60+
} finally {
61+
$duration = (microtime(true) - $startTime) * 1000;
62+
63+
$this->logger->logRequest(
64+
sprintf('[Geocoding] %s', $query),
65+
$duration,
66+
$this->getName(),
67+
$results
68+
);
69+
}
70+
71+
return $results;
72+
}
73+
74+
public function __call($method, $args)
75+
{
76+
return call_user_func_array([$this->realProvider, $method], $args);
77+
}
78+
79+
public function getName(): string
80+
{
81+
return $this->realProvider->getName();
82+
}
83+
}

0 commit comments

Comments
 (0)