Skip to content

Commit 53fa1eb

Browse files
author
Pablo Molina
committed
Improving namespace and adding Facade support
1 parent c2f64c2 commit 53fa1eb

9 files changed

Lines changed: 1218 additions & 308 deletions

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@
2222
"illuminate/container": "~5.4.36",
2323
"illuminate/http": "~5.4.36",
2424
"illuminate/support": "~5.4.36",
25+
"psr/log": "^1.0",
2526
"zumba/swivel": "^2.1"
2627
},
2728
"require-dev": {
2829
"mockery/mockery": "^1.2",
30+
"orchestra/testbench": "~3.4.0",
2931
"phpunit/phpunit": "~5.0",
3032
"squizlabs/php_codesniffer": "^3.4"
3133
},
3234
"autoload": {
3335
"psr-4": {
34-
"Webkod3r\\LaravelSwivel\\": "src"
36+
"LaravelSwivel\\": "src"
3537
}
3638
},
3739
"autoload-dev": {
3840
"psr-4": {
39-
"Tests\\Webkod3r\\LaravelSwivel\\": "tests"
41+
"Tests\\LaravelSwivel\\": "tests"
4042
}
4143
},
4244
"scripts": {
@@ -51,11 +53,12 @@
5153
},
5254
"laravel": {
5355
"providers": [
54-
"Webkod3r\\LaravelSwivel\\LaravelSwivelServiceProvider"
56+
"LaravelSwivel\\LaravelSwivelServiceProvider"
5557
]
5658
}
5759
},
5860
"config": {
61+
"optimize-autoloader": true,
5962
"sort-packages": true
6063
},
6164
"minimum-stability": "dev"

composer.lock

Lines changed: 1172 additions & 245 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/swivel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
| Defines the class used to load the swivel feature and handle the behavior
2222
|
2323
*/
24-
'loader_class' => env('SWIVEL_LOADER_CLASS', \Webkod3r\LaravelSwivel\SwivelLoader::class),
24+
'loader_class' => env('SWIVEL_LOADER_CLASS', \LaravelSwivel\SwivelLoader::class),
2525

2626
/*
2727
|--------------------------------------------------------------------------
@@ -31,7 +31,7 @@
3131
| Defines the class used to load features from Database
3232
|
3333
*/
34-
'model_class' => env('SWIVEL_MODEL_CLASS', \Webkod3r\LaravelSwivel\Entity\SwivelFeature::class),
34+
'model_class' => env('SWIVEL_MODEL_CLASS', \LaravelSwivel\Entity\SwivelFeature::class),
3535

3636
/*
3737
|--------------------------------------------------------------------------

src/Entity/SwivelFeature.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel\Entity;
3+
namespace LaravelSwivel\Entity;
44

55
use Illuminate\Container\Container;
66
use Illuminate\Database\Eloquent\Model;
@@ -10,15 +10,15 @@
1010
/**
1111
* Class SwivelFeature
1212
*
13-
* @package Webkod3r\LaravelSwivel\Entity
13+
* @package LaravelSwivel\Entity
1414
* @property integer $id
1515
* @property string $slug
1616
* @property string $buckets
1717
* @property \DateTime $created_at
1818
* @property \DateTime $updated_at
1919
*/
20-
class SwivelFeature extends Model implements SwivelModelInterface {
21-
20+
class SwivelFeature extends Model implements SwivelModelInterface
21+
{
2222
/**
2323
* The table associated with the model.
2424
*
@@ -57,7 +57,8 @@ protected function getContainer()
5757
* ]
5858
* </pre>
5959
*/
60-
public function getMapData() {
60+
public function getMapData()
61+
{
6162
// load configuration settings
6263
$config = (array)$this->getContainer()->make('config')->get('swivel');
6364

@@ -81,10 +82,11 @@ public function getMapData() {
8182
/**
8283
* Format data from database to the data swivel expects
8384
*
84-
* @param array $feature
85+
* @param array $feature Feature record with behavior and buckets
8586
* @return array
8687
*/
87-
protected function formatRow(array $feature) {
88+
protected function formatRow(array $feature)
89+
{
8890
if (!empty($feature['id'])) {
8991
return [$feature['slug'] => explode(static::DELIMITER, $feature['buckets'])];
9092
}

src/Entity/SwivelModelInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel\Entity;
3+
namespace LaravelSwivel\Entity;
44

5-
interface SwivelModelInterface {
5+
interface SwivelModelInterface
6+
{
67
/**
78
* Return an array of map data in the format that Swivel expects
89
*
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel\Support\Facades;
3+
namespace LaravelSwivel\Support\Facades;
44

55
use Illuminate\Support\Facades\Facade;
66

@@ -13,6 +13,6 @@ class Swivel extends Facade
1313
*/
1414
protected static function getFacadeAccessor()
1515
{
16-
return 'Swivel';
16+
return 'swivel';
1717
}
1818
}
Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel;
3+
namespace LaravelSwivel;
44

55
use \Illuminate\Contracts\Container\Container;
66
use \Illuminate\Support\ServiceProvider;
@@ -9,13 +9,12 @@
99

1010
class LaravelSwivelServiceProvider extends ServiceProvider
1111
{
12-
1312
/**
1413
* The package version.
1514
*
1615
* @var string
1716
*/
18-
const VERSION = '0.2.2';
17+
const VERSION = '1.0.1';
1918

2019
/**
2120
* Indicates if loading of the provider is deferred.
@@ -36,6 +35,21 @@ public function boot()
3635
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
3736
}
3837

38+
/**
39+
* Register the application services.
40+
*
41+
* @return void
42+
*/
43+
public function register()
44+
{
45+
$this->app->singleton('swivel', function (Container $app) {
46+
$request = $app->make(\Illuminate\Http\Request::class);
47+
return new SwivelComponent($request);
48+
});
49+
50+
$this->app->alias('swivel', SwivelComponent::class);
51+
}
52+
3953
/**
4054
* Returns the configuration path for the component
4155
*
@@ -62,52 +76,16 @@ protected function setupConfig(Container $app)
6276
$app->configure('swivel');
6377
}
6478

65-
// merge specific configurations
66-
$source = $app->getConfigurationPath('swivel') ?: $source;
6779
$this->mergeConfigFrom($source, 'swivel');
6880
}
6981

70-
/**
71-
* Sets swivel configuration
72-
*
73-
* @return void
74-
*/
75-
private function publishAssets()
76-
{
77-
app()->make('config')->set('swivel', app()->getConfigurationPath('swivel'));
78-
app()->configure('swivel');
79-
}
80-
81-
/**
82-
* @return void
83-
*/
84-
public function register()
85-
{
86-
$this->registerClass();
87-
}
88-
89-
/**
90-
* Register single service provider
91-
*
92-
* @return void
93-
*/
94-
private function registerClass()
95-
{
96-
$this->app->singleton('Swivel', function (Container $app) {
97-
$request = app(\Illuminate\Http\Request::class);
98-
return new SwivelComponent($request);
99-
});
100-
101-
$this->app->alias('Swivel', SwivelComponent::class);
102-
}
103-
10482
/**
10583
* Get the services provided by the provider.
10684
*
10785
* @return array
10886
*/
10987
public function provides()
11088
{
111-
return ['Swivel'];
89+
return ['swivel'];
11290
}
11391
}

src/SwivelComponent.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel;
3+
namespace LaravelSwivel;
44

55
use Illuminate\Http\Request;
66

77
/**
8-
* @package Webkod3r\LaravelSwivel
8+
* @package LaravelSwivel
99
* @author Pablo Molina <web.kod3r@gmail.com>
1010
*/
1111
class SwivelComponent
1212
{
13-
1413
/**
15-
* @var \Webkod3r\LaravelSwivel\SwivelLoader
14+
* @var \LaravelSwivel\SwivelLoader
1615
*/
1716
protected $loader;
1817

@@ -59,7 +58,7 @@ public function __construct(Request $request)
5958
/**
6059
* Get the loader instance to access it easily
6160
*
62-
* @return \Webkod3r\LaravelSwivel\SwivelLoader
61+
* @return \LaravelSwivel\SwivelLoader
6362
*/
6463
public function getLoader()
6564
{

src/SwivelLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Webkod3r\LaravelSwivel;
3+
namespace LaravelSwivel;
44

5-
use Webkod3r\LaravelSwivel\Entity\SwivelFeature;
5+
use LaravelSwivel\Entity\SwivelFeature;
66

77
/**
88
* @package Webkod3r\LaravelSwivel

0 commit comments

Comments
 (0)