diff --git a/config/sleeping_owl.php b/config/sleeping_owl.php index 30dc1f7cd..64a715026 100644 --- a/config/sleeping_owl.php +++ b/config/sleeping_owl.php @@ -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 @@ -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 ] ]; diff --git a/src/AliasBinder.php b/src/AliasBinder.php index 5b459b4e8..6c0e9099f 100644 --- a/src/AliasBinder.php +++ b/src/AliasBinder.php @@ -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']); + } + } - }); + ); } /** @@ -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]; } /** @@ -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); } /** @@ -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); } } diff --git a/src/Facades/AdminSection.php b/src/Facades/Admin.php similarity index 84% rename from src/Facades/AdminSection.php rename to src/Facades/Admin.php index e1c9b44c0..b03558f13 100644 --- a/src/Facades/AdminSection.php +++ b/src/Facades/Admin.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Facade; -class AdminSection extends Facade +class Admin extends Facade { public static function getFacadeAccessor() { diff --git a/src/Display.php b/src/Facades/Display.php similarity index 66% rename from src/Display.php rename to src/Facades/Display.php index fcccfac98..eb6671ede 100644 --- a/src/Display.php +++ b/src/Facades/Display.php @@ -1,6 +1,8 @@ registerColumnFilters(); + $this->registerDisplays(); + $this->registerColumns(); + $this->registerForms(); + $this->registerFormElements(); + } + + protected function registerColumnFilters() + { + $this->app->singleton('sleeping_owl.column_filter', function () { + + $alias = new AliasBinder(); + + $alias->register('text', \SleepingOwl\Admin\Display\Column\Filter\Text::class); + $alias->register('date', \SleepingOwl\Admin\Display\Column\Filter\Date::class); + $alias->register('range', \SleepingOwl\Admin\Display\Column\Filter\Range::class); + $alias->register('select', \SleepingOwl\Admin\Display\Column\Filter\Select::class); + + return $alias; + }); + } + + protected function registerDisplays() + { + $this->app->singleton('sleeping_owl.display', function () { + + $alias = new AliasBinder(); + + $alias->register('datatables', \SleepingOwl\Admin\Display\DisplayDatatables::class); + $alias->register('datatablesAsync', \SleepingOwl\Admin\Display\DisplayDatatablesAsync::class); + $alias->register('tab', \SleepingOwl\Admin\Display\DisplayTab::class); + $alias->register('tabbed', \SleepingOwl\Admin\Display\DisplayTabbed::class); + $alias->register('table', \SleepingOwl\Admin\Display\DisplayTable::class); + $alias->register('tree', \SleepingOwl\Admin\Display\DisplayTree::class); + + return $alias; + }); + } + + protected function registerColumns() + { + $this->app->singleton('sleeping_owl.table.column', function () { + + $alias = new AliasBinder(); + + $alias->register('action', \SleepingOwl\Admin\Display\Column\Action::class); + $alias->register('checkbox', \SleepingOwl\Admin\Display\Column\Checkbox::class); + $alias->register('control', \SleepingOwl\Admin\Display\Column\Control::class); + $alias->register('count', \SleepingOwl\Admin\Display\Column\Count::class); + $alias->register('custom', \SleepingOwl\Admin\Display\Column\Custom::class); + $alias->register('datetime', \SleepingOwl\Admin\Display\Column\DateTime::class); + $alias->register('filter', \SleepingOwl\Admin\Display\Column\Filter::class); + $alias->register('image', \SleepingOwl\Admin\Display\Column\Image::class); + $alias->register('lists', \SleepingOwl\Admin\Display\Column\Lists::class); + $alias->register('order', \SleepingOwl\Admin\Display\Column\Order::class); + $alias->register('text', \SleepingOwl\Admin\Display\Column\Text::class); + $alias->register('link', \SleepingOwl\Admin\Display\Column\Link::class); + $alias->register('relatedLink', \SleepingOwl\Admin\Display\Column\RelatedLink::class); + $alias->register('email', \SleepingOwl\Admin\Display\Column\Email::class); + $alias->register('treeControl', \SleepingOwl\Admin\Display\Column\TreeControl::class); + + return $alias; + }); + } + + protected function registerFormElements() + { + $this->app->singleton('sleeping_owl.form.element', function () { + + $alias = new AliasBinder(); + + $alias->register('columns', \SleepingOwl\Admin\Form\Element\Columns::class); + $alias->register('text', \SleepingOwl\Admin\Form\Element\Text::class); + $alias->register('time', \SleepingOwl\Admin\Form\Element\Time::class); + $alias->register('date', \SleepingOwl\Admin\Form\Element\Date::class); + $alias->register('timestamp', \SleepingOwl\Admin\Form\Element\Timestamp::class); + $alias->register('textaddon', \SleepingOwl\Admin\Form\Element\TextAddon::class); + $alias->register('select', \SleepingOwl\Admin\Form\Element\Select::class); + $alias->register('multiselect', \SleepingOwl\Admin\Form\Element\MultiSelect::class); + $alias->register('hidden', \SleepingOwl\Admin\Form\Element\Hidden::class); + $alias->register('checkbox', \SleepingOwl\Admin\Form\Element\Checkbox::class); + $alias->register('ckeditor', \SleepingOwl\Admin\Form\Element\CKEditor::class); + $alias->register('custom', \SleepingOwl\Admin\Form\Element\Custom::class); + $alias->register('password', \SleepingOwl\Admin\Form\Element\Password::class); + $alias->register('textarea', \SleepingOwl\Admin\Form\Element\Textarea::class); + $alias->register('view', \SleepingOwl\Admin\Form\Element\View::class); + $alias->register('image', \SleepingOwl\Admin\Form\Element\Image::class); + $alias->register('images', \SleepingOwl\Admin\Form\Element\Images::class); + $alias->register('file', \SleepingOwl\Admin\Form\Element\File::class); + $alias->register('radio', \SleepingOwl\Admin\Form\Element\Radio::class); + $alias->register('wysiwyg', \SleepingOwl\Admin\Form\Element\Wysiwyg::class); + + return $alias; + }); + } + + protected function registerForms() + { + $this->app->singleton('sleeping_owl.form', function () { + + $alias = new AliasBinder(); + + $alias->register('form', \SleepingOwl\Admin\Form\FormDefault::class); + $alias->register('tabbed', \SleepingOwl\Admin\Form\FormTabbed::class); + $alias->register('panel', \SleepingOwl\Admin\Form\FormPanel::class); + + return $alias; + }); + } + + protected function registerFilters() + { + $this->app->singleton('sleeping_owl.display.filter', function () { + + $alias = new AliasBinder(); + + $alias->register('field', \SleepingOwl\Admin\Display\Filter\FilterField::class); + $alias->register('scope', \SleepingOwl\Admin\Display\Filter\FilterScope::class); + $alias->register('custom', \SleepingOwl\Admin\Display\Filter\FilterCustom::class); + $alias->register('related', \SleepingOwl\Admin\Display\Filter\FilterRelated::class); + + return $alias; + }); + } +} diff --git a/src/Providers/ColumnFilterServiceProvider.php b/src/Providers/ColumnFilterServiceProvider.php deleted file mode 100644 index 17e717e92..000000000 --- a/src/Providers/ColumnFilterServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ -