Skip to content

Commit e7921e5

Browse files
committed
initial import
0 parents  commit e7921e5

13 files changed

+423
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
- curl -sS http://getcomposer.org/installer | php
10+
- php composer.phar install --dev --prefer-dist --no-interaction
11+
12+
script: phpunit --coverage-text --coverage-clover ./build/logs/clover.xml
13+
14+
after_script: php vendor/bin/coveralls

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
0.1.0 (xxxx-xx-xx)
5+
------------------
6+
7+
n/a

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Antoine Corcy <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Geocoder for Lavarel 4
2+
======================
3+
4+
This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/)
5+
in [**Laravel 4**](http://laravel.com/).
6+
7+
8+
Installation
9+
------------
10+
11+
It can be found on [Packagist](https://packagist.org/packages/toin0u/geocoder-laravel).
12+
The recommended way is through [composer](http://getcomposer.org).
13+
14+
Edit `compose.json` and add:
15+
16+
```json
17+
{
18+
"require": {
19+
"toin0u/geocoder-laravel": "~0.1"
20+
}
21+
}
22+
```
23+
24+
And install dependencies:
25+
26+
```bash
27+
$ curl -sS https://getcomposer.org/installer | php
28+
$ php composer.phar install
29+
```
30+
31+
32+
Usage
33+
-----
34+
35+
Find the `providers` key in `app/config/app.php` and register the **Geocoder Service Provider**.
36+
37+
```php
38+
'providers' => array(
39+
// ...
40+
41+
'Toin0u\Geocoder\GeocoderServiceProvider',
42+
)
43+
```
44+
45+
Find the `aliases` key in `app/config/app.php` and register the **Geocoder Facade**.
46+
47+
```php
48+
'aliases' => array(
49+
// ...
50+
51+
'Geocoder' => 'Toin0u\Geocoder\GeocoderFacade',
52+
)
53+
```
54+
55+
Configuration
56+
-------------
57+
58+
The service provider creates the following services:
59+
60+
* `geocoder`: the Geocoder instance.
61+
* `geocoder.provider`: the provider used by Geocoder.
62+
* `geocoder.adapter`: the HTTP adapter used to get data from remotes APIs.
63+
64+
By default, the `geocoder.provider` service uses FreeGeoIP and the `geocoder.adapter` service uses the cURL adapter.
65+
Override these services to use the adapter/provider you want.
66+
67+
See [the Geocoder documentation](http://geocoder-php.org/Geocoder/) for a list of available adapters and providers.
68+
69+
70+
Example with Facade
71+
-------------------
72+
73+
```php
74+
<?php
75+
76+
// ...
77+
try {
78+
$geocode = Geocoder::geocode('10 rue Gambetta, Paris, France');
79+
// ...
80+
} catch (\Exception $e) {
81+
echo $e->getMessage();
82+
}
83+
```
84+
85+
86+
Changelog
87+
---------
88+
89+
[See the changelog file](https://github.com/toin0u/Geocoder-laravel/blob/master/CHANGELOG.md)
90+
91+
92+
Support
93+
-------
94+
95+
[Please open an issues in github](https://github.com/toin0u/Geocoder-laravel/issues)
96+
97+
98+
License
99+
-------
100+
101+
Geocoder-laravel is released under the MIT License. See the bundled
102+
[LICENSE](https://github.com/toin0u/Geocoder-laravel/blob/master/LICENSE) file for details.

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name" : "toin0u/geocoder-laravel",
3+
"description" : "Geocoder library for Laravel 4",
4+
"keywords" : ["laravel", "geocoder", "geocoding"],
5+
"homepage" : "http://geocoder-php.org/",
6+
"license" : "MIT",
7+
8+
"authors" : [{
9+
"name" : "Antoine Corcy",
10+
"email" : "[email protected]",
11+
"homepage" : "http://sbin.dk",
12+
"role" : "Developer"
13+
}],
14+
15+
"require" : {
16+
"php" : ">=5.3.0",
17+
"illuminate/support" : "~4.0",
18+
"willdurand/geocoder" : "~2.2"
19+
},
20+
21+
"require-dev" : {
22+
"orchestra/testbench" : "~2.0",
23+
"satooshi/php-coveralls" : "~0.6"
24+
},
25+
26+
"autoload" : {
27+
"psr-0" : {
28+
"Toin0u\\Geocoder" : "src/"
29+
}
30+
},
31+
32+
"extra" : {
33+
"branch-alias" : {
34+
"dev-master" : "0.1-dev"
35+
}
36+
}
37+
}

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="tests/bootstrap.php"
12+
>
13+
<testsuites>
14+
<testsuite name="Geocoder library for Laravel4 Test Suite">
15+
<directory>./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory>./src/Toin0u/</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Geocoder-laravel library.
5+
*
6+
* (c) Antoine Corcy <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Toin0u\Geocoder;
13+
14+
use Illuminate\Support\Facades\Facade;
15+
16+
/**
17+
* Facade for Geocoder
18+
*
19+
* @author Antoine Corcy <[email protected]>
20+
*/
21+
class GeocoderFacade extends Facade
22+
{
23+
/**
24+
* Get the registered name of the component.
25+
*
26+
* @return string
27+
*/
28+
protected static function getFacadeAccessor() {
29+
return 'geocoder';
30+
}
31+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Geocoder-laravel library.
5+
*
6+
* (c) Antoine Corcy <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Toin0u\Geocoder;
13+
14+
use Geocoder\Geocoder;
15+
use Geocoder\Provider\FreeGeoIpProvider;
16+
use Geocoder\HttpAdapter\CurlHttpAdapter;
17+
use Illuminate\Support\ServiceProvider;
18+
19+
/**
20+
* Geocoder service provider
21+
*
22+
* @author Antoine Corcy <[email protected]>
23+
*/
24+
class GeocoderServiceProvider extends ServiceProvider
25+
{
26+
/**
27+
* Indicates if loading of the provider is deferred.
28+
*
29+
* @var bool
30+
*/
31+
protected $defer = false;
32+
33+
/**
34+
* Bootstrap the application events.
35+
*
36+
* @return void
37+
*/
38+
public function boot() {
39+
$this->package('willdurand/geocoder');
40+
}
41+
42+
/**
43+
* Register the service provider.
44+
*
45+
* @return void
46+
*/
47+
public function register()
48+
{
49+
$this->app['geocoder.adapter'] = $this->app->share(function() {
50+
return new CurlHttpAdapter;
51+
});
52+
53+
$this->app['geocoder.provider'] = $this->app->share(function() {
54+
return new FreeGeoIpProvider($this->app['geocoder.adapter']);
55+
});
56+
57+
$this->app['geocoder'] = $this->app->share(function() {
58+
$geocoder = new Geocoder;
59+
$geocoder->registerProvider($this->app['geocoder.provider']);
60+
61+
return $geocoder;
62+
});
63+
}
64+
65+
/**
66+
* Get the services provided by the provider.
67+
*
68+
* @return array
69+
*/
70+
public function provides()
71+
{
72+
return array('geocoder');
73+
}
74+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Geocoder-laravel library.
5+
*
6+
* (c) Antoine Corcy <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Geocoder\Tests;
13+
14+
/**
15+
* @author Antoine Corcy <[email protected]>
16+
*/
17+
class GeocoderFacadeTest extends TestCase
18+
{
19+
public function testGeocoderFacade()
20+
{
21+
$this->assertTrue(is_array($providers = \Geocoder::getProviders()));
22+
$this->assertArrayHasKey('free_geo_ip', $providers);
23+
$this->assertInstanceOf('Geocoder\\Provider\\FreeGeoipProvider', $providers['free_geo_ip']);
24+
}
25+
}

0 commit comments

Comments
 (0)