Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
webpatser committed Jul 18, 2013
0 parents commit 69376dd
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 Christoph Kempen

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Laravel Countries
Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.


## Installation

Add `webpatser/laravel-countries` to `composer.json`.

"webpatser/laravel-countries": "dev-master"

Run `composer update` to pull down the latest version of Country List.

Edit `app/config/app.php` and add the `provider` and `filter`

'providers' => array(
'Webpatser\Countries\CountriesServiceProvider',
)

Now add the alias.

'aliases' => array(
'Countries' => 'Webpatser\Countries\CountriesFacade',
)
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name" : "webpatser/laravel-countries",
"description" : "Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.",
"version" : "0.2",
"authors" : [{
"name" : "Christoph Kempen",
"email" : "[email protected]",
"homepage" : "http://downsized.nl/",
"role" : "developer"
}
],
"keywords" : [],
"license" : [
"MIT"
],
"require" : {
"php" : ">=5.3.0"
},
"autoload" : {
"psr-0" : {
"Webpatser\\Countries" : "src/"
}
},
"minimum-stability" : "dev"
}
53 changes: 53 additions & 0 deletions src/Webpatser/Countries/Countries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Webpatser\Countries;

/**
* CountryList
*
*/
class Countries {

/**
* @var string
* Path to the directory containing countries data.
*/
protected $countries;

/**
* Constructor.
*
* @param string|null $dataDir Path to the directory containing countries data
*/
public function __construct()
{
$this->countries = json_decode(file_get_contents(__DIR__ . '/Models/countries.json'), true);
}

/**
* Returns one country
*
* @param string $country The country
* @param string $locale The locale (default: en)
* @param string $format The format (default: php)
* @param string $source Data source: "icu" or "cldr"
* @return string
*/
public function getOne($id)
{
return $this->countries[$id];
}

/**
* Returns a list of countries
*
* @param string $locale The locale (default: en)
* @param string $locale The format (default: php)
* @param string $source Data source: "icu" or "cldr"
* @return array
*/
public function getList()
{
return $this->countries;
}
}
20 changes: 20 additions & 0 deletions src/Webpatser/Countries/CountriesFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Webpatser\Countries;

use Illuminate\Support\Facades\Facade;

/**
* CountriesFacade
*
*/
class CountriesFacade extends Facade {

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'countries'; }

}
44 changes: 44 additions & 0 deletions src/Webpatser/Countries/CountriesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Webpatser\Countries;

use Illuminate\Support\ServiceProvider;

/**
* CountryListServiceProvider
*
*/

class CountriesServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['countries'] = $this->app->share(function($app)
{
return new Countries;
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('countries');
}

}
1 change: 1 addition & 0 deletions src/Webpatser/Countries/Models/countries.json

Large diffs are not rendered by default.

0 comments on commit 69376dd

Please sign in to comment.