Download the PHP package knivey/cmdr without Composer
On this page you can find all versions of the php package knivey/cmdr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cmdr
Cmdr
knivey/cmdr
is command router designed for use on chatbots.
Requirements
- PHP >= 8.2
Features
- Arguments parsed/validated and easily accessed according to a syntax defined for command
- Uses function attributes to register functions for commands
- Can set up a wrapper function with
CallWrap
attribute (helpful for using something like\Amp\asyncCall
)
Installation
Documentation & Examples
Set up the command router object and find commands
Note that command names cannot contain a # or a space in them.
To load public methods from a class object use loadMethods($obj)
Argument Syntax Rules
<arg>
is a required arg<arg>...
required multiword arg, must be last in list[arg]
is an optional arg, all optionals must be at the end and no multiword arguments preceed them[arg]...
optional multiword arg, must be last in list- The arg name must not contain
[]<>
CallWrap
Argument validators (WIP)
You can specify some simple validations in the argument DSL.
Validators can also filter/normalize inputs, for example bool can take "yes" and set that as true.
Syntax
- Arguments can only have one validation applied to them.
- The Validate class provides some default validators and custom validators can be registsered.
- Validator args must not have spaces,
<arg: int min = 0>
would be an error. - Validator/filter args should not be named
val
, that'n conventionally used as the first function argument.Built in validators
uint, int, number
These all do what you would expect, check for types of numeric values.
They take two optional arguments min
and max
.
They will cast to the appropriate PHP type, for int or uint that is int
numeric could be int
or float
.
Example:
bool
Can take "yes", "on", "true", "no", "off", "false" and returns a PHP bool
options/choices
This one lets you limit the argument to a few choices. To use an optional you only need to put options in parentheses with a | to separate choices.
Example:
Custom validators and filters
You can set your own custom validators:
You can set filters, these are what normalize values for you.