File tree Expand file tree Collapse file tree 3 files changed +98
-2
lines changed Expand file tree Collapse file tree 3 files changed +98
-2
lines changed Original file line number Diff line number Diff line change 17
17
"igorw/get-in" : " ~1.0"
18
18
},
19
19
"require-dev" : {
20
- "geoip2/geoip2" : " ~0.6"
20
+ "geoip2/geoip2" : " ~0.6" ,
21
+ "symfony/stopwatch" : " ~2.5"
21
22
},
22
23
"suggest" : {
23
24
"ext-geoip" : " Enabling the geoip extension allows you to use the MaxMindProvider." ,
24
25
"geoip/geoip" : " If you are going to use the MaxMindBinaryProvider (conflict with geoip extension)." ,
25
- "geoip2/geoip2" : " If you are going to use the GeoIP2DatabaseProvider."
26
+ "geoip2/geoip2" : " If you are going to use the GeoIP2DatabaseProvider." ,
27
+ "symfony/stopwatch" : " If you want to use the TimedGeocoder"
26
28
},
27
29
"autoload" : {
28
30
"psr-0" : { "Geocoder" : " src/" }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * This file is part of the Geocoder 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 Geocoder ;
12
+
13
+ use Symfony \Component \Stopwatch \Stopwatch ;
14
+
15
+ /**
16
+ * This Geocoder allows you to profile your API/Database calls.
17
+ *
18
+ * @author Markus Bachmann <[email protected] >
19
+ */
20
+ class TimedGeocoder implements Geocoder
21
+ {
22
+ private $ delegate ;
23
+
24
+ private $ stopwatch ;
25
+
26
+ public function __construct (Geocoder $ delegate , Stopwatch $ stopwatch )
27
+ {
28
+ $ this ->delegate = $ delegate ;
29
+ $ this ->stopwatch = $ stopwatch ;
30
+ }
31
+
32
+ public function geocode ($ value )
33
+ {
34
+ $ this ->stopwatch ->start ('geocode ' , 'geocoder ' );
35
+ $ result = $ this ->delegate ->geocode ($ value );
36
+ $ this ->stopwatch ->stop ('geocode ' );
37
+
38
+ return $ result ;
39
+ }
40
+
41
+ public function reverse ($ latitude , $ longitude )
42
+ {
43
+ $ this ->stopwatch ->start ('reverse ' , 'geocoder ' );
44
+ $ result = $ this ->delegate ->reverse ($ latitude , $ longitude );
45
+ $ this ->stopwatch ->stop ('reverse ' );
46
+
47
+ return $ result ;
48
+ }
49
+
50
+ public function __call ($ method , $ args )
51
+ {
52
+ return call_user_func_array ([$ this ->delegate , $ method ], $ args );
53
+ }
54
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Geocoder \Tests ;
4
+
5
+ use Geocoder \TimedGeocoder ;
6
+ use Symfony \Component \Stopwatch \Stopwatch ;
7
+
8
+ class TimedGeocoderTest extends TestCase
9
+ {
10
+ protected function setUp ()
11
+ {
12
+ $ this ->stopwatch = new Stopwatch ();
13
+ $ this ->delegate = $ this ->getMock ('Geocoder\Geocoder ' );
14
+ $ this ->geocoder = new TimedGeocoder ($ this ->delegate , $ this ->stopwatch );
15
+ }
16
+
17
+ public function testGeocode ()
18
+ {
19
+ $ this ->delegate ->expects ($ this ->once ())
20
+ ->method ('geocode ' )
21
+ ->with ($ this ->equalTo ('foo ' ))
22
+ ->will ($ this ->returnValue ([]));
23
+
24
+ $ this ->geocoder ->geocode ('foo ' );
25
+
26
+ $ this ->assertCount (1 , $ this ->stopwatch ->getSectionEvents ('__root__ ' ));
27
+ }
28
+
29
+ public function testReverse ()
30
+ {
31
+ $ this ->delegate ->expects ($ this ->once ())
32
+ ->method ('reverse ' )
33
+ ->with ($ this ->equalTo (0 , 0 ))
34
+ ->will ($ this ->returnValue ([]));
35
+
36
+ $ this ->geocoder ->reverse (0 , 0 );
37
+
38
+ $ this ->assertCount (1 , $ this ->stopwatch ->getSectionEvents ('__root__ ' ));
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments