A registry/factory for input widgets.
Can be used by helpers/view logic to build form widgets and other HTML widgets.
This class handles the mapping between names and concrete classes. It also has a basic name based dependency resolver that allows widgets to depend on each other.
Each widget should expect a StringTemplate instance as their first argument. All other dependencies will be included after.
Widgets can ask for the current view by using the
_resolveWidget() protectedResolves a widget spec into an instance.
add() publicAdds or replaces existing widget instances/configuration with new ones.
clear() publicClear the registry and reset the widgets.
get() publicGet a widget.
load() publicLoad a config file containing widgets.
__construct() public ¶
_resolveWidget() protected ¶
_resolveWidget( mixed $widget )
Resolves a widget spec into an instance.
- mixed $widget
- The widget to get
when class cannot be loaded or does not implement WidgetInterface.
add( array $widgets )
Adds or replaces existing widget instances/configuration with new ones.
Widget arrays can either be descriptions or instances. For example:
$registry->add([ 'label' => new MyLabelWidget($templates), 'checkbox' => ['Fancy.MyCheckbox', 'label'] ]);
The above shows how to define widgets as instances or as descriptions including dependencies. Classes can be defined with plugin notation, or fully namespaced class names.
- array $widgets
- Array of widgets to use.
When class does not implement WidgetInterface.
get( string $name )
Get a widget.
Will either fetch an already created widget, or create a new instance
if the widget has been defined. If the widget is undefined an instance of
_default widget will be returned. An exception will be thrown if
_default widget is undefined.
- string $name
- The widget name to get.
widget interface class.
when widget is undefined.