Download the PHP package rtablada/inspector-gadget without Composer
On this page you can find all versions of the php package rtablada/inspector-gadget. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rtablada/inspector-gadget
More information about rtablada/inspector-gadget
Files in rtablada/inspector-gadget
Package inspector-gadget
Short Description A web-component inspired data flow library for Laravel views.
License MIT
Homepage https://github.com/rtablada/inspector-gadget
Informations about the package inspector-gadget
Inspector Gadget
Inspector Gadget is a web-component and Ember.js inspired library for improving data-flow, maintainability, and template reusability.
Gadgets, in inspector gadget allow for template partials or even plain strings to be rendered in a smart, explicit fashion while reducing weight and overloaded controllers or domain layers.
Install
Via Composer
In the app.php
config file, add 'Rtablada\InspectorGadget\GadgetServiceProvider',
to the providers
array.
Then publish the configuration file with php artisan vendor:publish
to publish the config/inspector-gadget.php
file.
Note
You can optionally install install the Rtablada\InspectorGadget\Facades\Gadget'
to the facades array as Gadget
to use gadget facades in your views.
Usage
Gadget Classes
Gadgets are just plain PHP objects with a render
method.
The string returned by the render
function will be sent back to your views.
Since the gadgets are resolved using the application container, you can dependency inject like any other class in your application.
Making Gadgets with the GadgetFactory
In you views, you can render gadgets using the make
function on the gadgetFactory
variable that is available in your views.
The make
function accepts a string argument for the gadget class that you want to render in your view.
Passing Arguments to Gadgets
To allow greater flexibility, you can pass arguments to the render
function in your gadget.
Shortcuts
If you have registered the Gadget
facade, then you can have the following in your views:
If you're using blade templates, there is a @gadget
helper that calls $gadgetFactory->make()
Better Data Flow
Consider the following controller action:
And the accompanying view:
This can be cleaned up using gadgets:
Configuring
Default Namespace
To shorten the need for full class names in your Gadget::make
calls, Inspector Gadget has a namespace
configuration option in the config/inspector-gadget.php
file.
This is used as a default namespace to look up gadgets.
If a class is not found in your configured default namespace, then Inspector Gadget will attempt to load from the full class name.
Aliases
To further shorthand and ease, you can register aliases in the aliases
array in the config/inspector-gadget.php
file.
This allows for gadgets to be aliased without poluting the app container.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Ryan Tablada
- All Contributors
License
The MIT License (MIT). Please see License File for more information.