![Quality Score][ico-code-quality], (*1)
Widgets back to basic, with Laravel support., (*2)
Install
``` bash
$ php artisan displore:install widgets, (*3)
This does everything for you, from the Composer requirement to the addition of Laravel service providers.
### Via Composer
``` bash
$ composer require displore/widgets
This requires the addition of the Widgets service provider and Widgets facade alias to config/app.php if you use the package with Laravel.
Displore\Widgets\WidgetsServiceProvider::class,
and
Displore\Widgets\Facades\Widget::class,, (*4)
Configuration
In the configuration file you can set up dynamic resolving or register the widgets in a similar fashion to how config/app.php works with aliases., (*5)
$ php artisan vendor:publish --tag=displore.widgets.config
Usage
The package does not rely on Laravel, as shows the following example.
``` php
$arrayOfProviders = [
'headline' => My\Widgets\Headline::class,
];
$service = new WidgetsProvider($arrayOfProviders);
$widget = $service->get('headline'); // Calls getWidget() on the Headline class., (*6)
With Laravel, the array of providers is found in a dedicated configuration file. In your views you can call the `Widget` facade to get widgets.
It is also possible, either with or without Laravel, to use a dynamic widgets provider, meaning that on every request, all classes in a given path will be searched for the widget needed. Especially useful during development.
For Laravel, set `dynamic` to true in the configuration file. For non-laravel:
```php
$service = (new DynamicWidgetsProvider)
->withPath('Path/To/Widgets/Classes')
->withNamespace('My\\Widgets')
->scanForProviders();
$widget = $service->get('headline');
You can also set widgets during runtime, with both the static and dynamic widgets provider:, (*7)
// Laravel facade
Widget::set('headline', new My\Widgets\Headline::class);
// Self instantiated service
$service->set('headline', new My\Widgets\Headline::class);
Change log
Please see changelog for more information what has changed recently., (*8)
Testing
The package comes with unit tests.
In a Laravel application, with Laravel Packager:
bash
$ php artisan packager:git *Displore Github url*
$ php artisan packager:tests Displore Widgets
$ phpunit, (*9)
Contributing
Please see contributing for details., (*10)
Credits
License
The EUPL License. Please see the License File for more information., (*11)