Skip to content

Commit

Permalink
Refactored alias registering.
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Feb 28, 2016
1 parent 33194f1 commit 9766b82
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 201 deletions.
25 changes: 10 additions & 15 deletions config/sleeping_owl.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@
*/

'providers' => [
SleepingOwl\Admin\Providers\ColumnFilterServiceProvider::class,
SleepingOwl\Admin\Providers\ColumnServiceProvider::class,
SleepingOwl\Admin\Providers\DisplayServiceProvider::class,
SleepingOwl\Admin\Providers\FilterServiceProvider::class,
SleepingOwl\Admin\Providers\FormServiceProvider::class,
SleepingOwl\Admin\Providers\FormElementsServiceProvider::class,
SleepingOwl\Admin\Providers\AliasesServiceProvider::class,
KodiCMS\Assets\AssetsServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
SleepingOwl\Admin\Providers\AdminServiceProvider::class
Expand All @@ -134,14 +129,14 @@
'Form' => Collective\Html\FormFacade::class,
'HTML' => Collective\Html\HtmlFacade::class,

'AdminSection' => SleepingOwl\Admin\Facades\AdminSection::class,
'AdminTemplate' => SleepingOwl\Admin\Facades\AdminTemplate::class,
'AdminNavigation' => SleepingOwl\Admin\Facades\AdminNavigation::class,
'AdminColumn' => SleepingOwl\Admin\TableColumn::class,
'AdminColumnFilter' => SleepingOwl\Admin\TableColumnFilter::class,
'AdminDisplayFilter' => SleepingOwl\Admin\DisplayFilter::class,
'AdminForm' => SleepingOwl\Admin\Form::class,
'AdminFormElement' => SleepingOwl\Admin\FormElement::class,
'AdminDisplay' => SleepingOwl\Admin\Display::class
'AdminSection' => SleepingOwl\Admin\Facades\Admin::class,
'AdminTemplate' => SleepingOwl\Admin\Facades\Template::class,
'AdminNavigation' => SleepingOwl\Admin\Facades\Navigation::class,
'AdminColumn' => SleepingOwl\Admin\Facades\TableColumn::class,
'AdminColumnFilter' => SleepingOwl\Admin\Facades\TableColumnFilter::class,
'AdminDisplayFilter' => SleepingOwl\Admin\Facades\DisplayFilter::class,
'AdminForm' => SleepingOwl\Admin\Facades\Form::class,
'AdminFormElement' => SleepingOwl\Admin\Facades\FormElement::class,
'AdminDisplay' => SleepingOwl\Admin\Facades\Display::class
]
];
43 changes: 25 additions & 18 deletions src/AliasBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

namespace SleepingOwl\Admin;

use Route;
use BadMethodCallException;

abstract class AliasBinder
class AliasBinder
{
/**
* @var array
*/
protected $aliases = [];

/**
* Register new alias.
*
* @param string $alias
* @param string $class
*/
public static function register($alias, $class)
public function register($alias, $class)
{
static::$aliases[$alias] = $class;
Route::group([
'prefix' => config('sleeping_owl.url_prefix'),
'middleware' => config('sleeping_owl.middleware'),
], function () use ($class) {
if (method_exists($class, 'registerRoutes')) {
call_user_func([$class, 'registerRoutes']);
$this->aliases[$alias] = $class;

app('router')->group(
['prefix' => config('sleeping_owl.url_prefix'), 'middleware' => config('sleeping_owl.middleware')],
function () use ($class) {

if (method_exists($class, 'registerRoutes')) {
call_user_func([$class, 'registerRoutes']);
}

}
});
);
}

/**
Expand All @@ -33,9 +40,9 @@ public static function register($alias, $class)
*
* @return string
*/
public static function getAlias($alias)
public function getAlias($alias)
{
return static::$aliases[$alias];
return $this->aliases[$alias];
}

/**
Expand All @@ -45,9 +52,9 @@ public static function getAlias($alias)
*
* @return bool
*/
public static function hasAlias($alias)
public function hasAlias($alias)
{
return array_key_exists($alias, static::$aliases);
return array_key_exists($alias, $this->aliases);
}

/**
Expand All @@ -58,12 +65,12 @@ public static function hasAlias($alias)
*
* @return mixed
*/
public static function __callStatic($name, $arguments)
public function __call($name, $arguments)
{
if (! static::hasAlias($name)) {
if (! $this->hasAlias($name)) {
throw new BadMethodCallException($name);
}

return app(static::getAlias($name), $arguments);
return app($this->getAlias($name), $arguments);
}
}
2 changes: 1 addition & 1 deletion src/Facades/AdminSection.php → src/Facades/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Facade;

class AdminSection extends Facade
class Admin extends Facade
{
public static function getFacadeAccessor()
{
Expand Down
18 changes: 12 additions & 6 deletions src/Display.php → src/Facades/Display.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static \SleepingOwl\Admin\Display\DisplayDatatables datatables()
Expand All @@ -10,11 +12,15 @@
* @method static \SleepingOwl\Admin\Display\DisplayTable table()
* @method static \SleepingOwl\Admin\Display\DisplayTree tree()
*/
class Display extends AliasBinder
class Display extends Facade
{

/**
* Display class aliases.
* @var string[]
* @return string
*/
protected static $aliases = [];
}
protected static function getFacadeAccessor()
{
return 'sleeping_owl.display';
}

}
13 changes: 9 additions & 4 deletions src/DisplayFilter.php → src/Facades/DisplayFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class Filter.
Expand All @@ -9,10 +11,13 @@
* @method static \SleepingOwl\Admin\Display\Filter\FilterRelated related($name)
* @method static \SleepingOwl\Admin\Display\Filter\FilterScope scope($name)
*/
class DisplayFilter extends AliasBinder
class DisplayFilter extends Facade
{
/**
* @var array
* @return string
*/
protected static $aliases = [];
protected static function getFacadeAccessor()
{
return 'sleeping_owl.display.filter';
}
}
15 changes: 8 additions & 7 deletions src/Form.php → src/Facades/Form.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static \SleepingOwl\Admin\Form\FormDefault form()
* @method static \SleepingOwl\Admin\Form\FormTabbed tabbed()
* @method static \SleepingOwl\Admin\Form\FormPanel panel()
*/
class Form extends AliasBinder
class Form extends Facade
{
/**
* Form class aliases.
* @var string[]
*/
protected static $aliases = [];
public static function getFacadeAccessor()
{
return 'sleeping_owl.form';
}
}
12 changes: 8 additions & 4 deletions src/FormElement.php → src/Facades/FormElement.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;
/**
* Class AdminForm.
* @method static \SleepingOwl\Admin\Form\Element\Text text($name, $label = null)
Expand All @@ -25,10 +26,13 @@
* @method static \SleepingOwl\Admin\Form\Element\Radio radio($name, $label = null)
* @method static \SleepingOwl\Admin\Form\Element\Wysiwyg wysiwyg($name, $label = null)
*/
class FormElement extends AliasBinder
class FormElement extends Facade
{
/**
* @var array
* @return string
*/
protected static $aliases = [];
protected static function getFacadeAccessor()
{
return 'sleeping_owl.form.element';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Facade;

class AdminNavigation extends Facade
class Navigation extends Facade
{

/**
Expand Down
16 changes: 9 additions & 7 deletions src/TableColumn.php → src/Facades/TableColumn.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static \SleepingOwl\Admin\Display\Column\Action action($name)
Expand All @@ -20,11 +22,11 @@
* @method static \SleepingOwl\Admin\Display\Column\TreeControl treeControl()
* @method static \SleepingOwl\Admin\Display\Column\Url url($name)
*/
class TableColumn extends AliasBinder
class TableColumn extends Facade
{
/**
* Column class aliases.
* @var string[]
*/
protected static $aliases = [];

public static function getFacadeAccessor()
{
return 'sleeping_owl.table.column';
}
}
14 changes: 8 additions & 6 deletions src/TableColumnFilter.php → src/Facades/TableColumnFilter.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php

namespace SleepingOwl\Admin;
namespace SleepingOwl\Admin\Facades;

use SleepingOwl\Admin\AliasBinder;
use Illuminate\Support\Facades\Facade;

/**
* @method static \SleepingOwl\Admin\Display\Column\Filter\Text text()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Date date()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Select select()
* @method static \SleepingOwl\Admin\Display\Column\Filter\Range range()
*/
class TableColumnFilter extends AliasBinder
class TableColumnFilter extends Facade
{
/**
* Column filter class aliases.
* @var string[]
* @return string
*/
protected static $aliases = [];
protected static function getFacadeAccessor()
{
return 'sleeping_owl.column_filter';
}
}
2 changes: 1 addition & 1 deletion src/Facades/AdminTemplate.php → src/Facades/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Facade;

class AdminTemplate extends Facade
class Template extends Facade
{

/**
Expand Down
Loading

0 comments on commit 9766b82

Please sign in to comment.