Skip to content

Commit

Permalink
Implement Country class..pretty straight forward and mostly depends o…
Browse files Browse the repository at this point in the history
…n the Config class
  • Loading branch information
Mulkave committed Jun 2, 2013
0 parents commit 4aa6b8e
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: php

php:
- 5.3
- 5.4

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "vinelab/country",
"description": "",
"authors": [
{
"name": "Abed Halawi",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},

"require-dev": {
"mockery/mockery": "dev-master"
},

"autoload": {
"psr-0": {
"Vinelab\\Country": "src/"
}
},
"minimum-stability": "dev"
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
52 changes: 52 additions & 0 deletions src/Vinelab/Country/CountryServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php namespace Vinelab\Country;

use Illuminate\Support\ServiceProvider;

class CountryServiceProvider extends ServiceProvider {

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

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('vinelab/country');
}

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

$this->app->booting(function() {

$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Country', 'Vinelab\Country\Facades\Guide');
});
}

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

}
14 changes: 14 additions & 0 deletions src/Vinelab/Country/Facades/Guide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Vinelab\COuntry\Facades;

use Illuminate\Support\Facades\Facade;

Class Guide extends Facade {

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

}
21 changes: 21 additions & 0 deletions src/Vinelab/Country/Guide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php namespace Vinelab\Country;

Class Guide {

function __construct($config)
{
$this->config = $config;
}

public function name($abbreviation)
{
$abbreviation = strtoupper($abbreviation);
return $this->config->get("country::countries.{$abbreviation}");
}

public function abbreviation($name)
{
$countries = $this->config->get('country::countries');
return array_search(ucwords($name), $countries);
}
}
Empty file added src/config/.gitkeep
Empty file.
Loading

0 comments on commit 4aa6b8e

Please sign in to comment.