Download the PHP package dmvdbrugge/dynamic-components without Composer
On this page you can find all versions of the php package dmvdbrugge/dynamic-components. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dmvdbrugge/dynamic-components
More information about dmvdbrugge/dynamic-components
Files in dmvdbrugge/dynamic-components
Package dynamic-components
Short Description Dynamic Components for the PHP UI extension
License MIT
Informations about the package dynamic-components
Dynamic Components
Dynamic Components for the PHP UI extension: use callbacks instead of hardcoded actions. Features advanced versions of the basic controls provided by the extension.
Usage / Examples
The most basic example is a button that changes its text when clicked:
This in contrast to having to create a hardcoded or anonymous class:
When we take the first example a bit further, say we now want 3 buttons:
Whereas in the extends
form you either need to duplicate the anonymous class multiple times (duplicating logic), or
create an actual class (which gives you some additional options, but also more hassle).
Each callback will receive the component that the action triggers for as last parameter. Last mostly means only (and
thus also first), but is relevant for Area
's actions, as they receive multiple params already.
See also the examples, which feature several Controls used in different ways and coding styles. Every
example is a fully working program and can be run directly with php, given of course the extension is enabled. See also
csv2qif's
FileSelect for a more advanced
version of the filepicker. (Or any of its other UiComponents
. It's kicked off in src/Command/Ui.php
but that's the
boring part.)
API
All components extend a class, usually the one provided by the extension. Inherited methods are unlisted but obviously still available. All component descriptions in this section are in the same format:
Clickable FQN (is link to its API docs)
Extra information, if any.
Controls
Button
UI\Controls\Button
Check
UI\Controls\Check
ColorButton
UI\Controls\ColorButton
Combo
UI\Controls\Combo
EditableCombo
UI\Controls\EditableCombo
Entry
UI\Controls\Entry
MultilineEntry
UI\Controls\MultilineEntry
Radio
UI\Controls\Radio
Slider
UI\Controls\Slider
Because UI\Controls\Slider
accepts $min > $max
and then flips them, so does DynamicComponents\Controls\Slider
.
However for clarity's sake you should pass them in the correct way, as the getters return the actual min and max.
Spin
UI\Controls\Spin
Because UI\Controls\Spin
accepts $min > $max
and then flips them, so does DynamicComponents\Controls\Spin
.
However for clarity's sake you should pass them in the correct way, as the getters return the actual min and max.
Advanced Controls
Combo
DynamicComponents\Controls\Combo
Radio
DynamicComponents\Controls\Radio
Other
Area
UI\Area
Executor
UI\Executor
Menu
UI\Menu
Menu
has no actions itself, but is used for creating MenuItem
s. While DynamicComponents\MenuItem
s can be used
with a UI\Menu
, using a DynamicComponents\Menu
has the following advantages: it adds itself as parent, it sets the
MenuItem
's name, and it has DynamicComponents\MenuItem
as default in append()
. It's fully backwards compatible
though, so you can still create UI\MenuItem
s with it.
To facilitate both stricter typing and supporting PhpStorm's Advanced Metadata, add()
has been added as correctly
typed shortcut, together with addAs()
which has arguments flipped compared to append()
for type detection (which
only works on the first param).
MenuItem
UI\MenuItem
Name and Parent are only available when created by a DynamicComponents\Menu
. Theoretically, name could be set
manually, but there is no guarantee that it's actually correct.
Window
UI\Window
The default action on a UI\Window
without onClosing
is to destroy()
itself and call UI\quit()
. To provide the
same functionality in a flexible way DynamicComponents\Window
does this as well, but you can prevent it by returning
false
from the callback.
Installation
Dynamic Components is just a single composer call away:
Background
csv2qif was a happy little commandline tool, until I stumbled upon the PHP UI extension (source). Coming from a web-background, where callbacks are flowing freely, the idea of hardcoding every button, dropdown, and radio was not a pleasant one. Thus the dynamic button was born, quickly followed by the advanced controls combo and radio.
Realizing this had nothing to do with the tool itself, the idea sparked to move them to a library of their own, providing a reason to let their actionable control-friends (check, entry, etc.) join the party. So here we are.
License
MIT License
Copyright (c) 2018-2019 Dave van der Brugge