Download the PHP package patinthehat/glacier without Composer
On this page you can find all versions of the php package patinthehat/glacier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download patinthehat/glacier
More information about patinthehat/glacier
Files in patinthehat/glacier
Package glacier
Short Description Lightweight console application framework for PHP
License MIT
Informations about the package glacier
Glacier
A lightweight framework for quickly putting together PHP CLI scripts and applications.
Install with composer
Events
Glacier allows you to write event-driven applications quite easily using Events
and EventListeners
.
Custom events extend the Event
class, and names are generated automatically. Event names are generated by inserting a period before every capital letter (except the first) and making everything lowercase. For example, "MyEvent123" would trigger the "my.event123" event.
An event can be defined as simply as:
Properties, etc. can be added as required.
To trigger an event, call event()
:
You may also send a payload along with the event by passing a second, optional parameter:
Event Listeners
Events are handled by event listeners, which are automatically registered by the application. No action needs to be taken other than defining an EventListener
or MultipleEventListener
class. To disable this behavior, set the property $autoRegister
to false:
An event listener that handles events 'my.event1' and 'my.event2' can be defined as such:
To listen for ALL events, the event name should be defined as '*':
Commands
Glacier allows support for multiple commands within the same application. To create a command, extend the Command
class:
By default, all commands are automatically registered. To disable this behavior, set the static property $autoRegister
to false:
If autoregistration is disabled, register it before calling $app->run()
:
Default Commands
- TBD
Command-Line Arguments
Glacier will accept all command-line flags by default. To accept a flag with a value, you must call the defineOption()
method on the arguments()
method. Once done defining options, you must call parse()
.
Once defined, even if the short flag is provided, its value can be accessed by calling setting($name)
, such as setting('test')
, even if -t 55
was passed on the command line.
To define command-line options, use the following format:
such as:
In full, to define a command-line option:
This must be done before a call to $app->run()
.
Any of these settings defined here could later be referenced, for example, as setting('count')
or setting('all')
.
If you simply wish to be able to handle flags with no values, you do not need to call defineOption()
. To access, simply reference app()->arguments()->hasOption('myflag')
:
Configuration Files
- TBD
A Basic Application
Execution:
php myapp.php -t 55
or
php myapp.php --test=123
A Simple Glacier Application
Execution:
php myapp.php
then
php myapp.php --goodbye