1. Go to this page and download the library: Download patinthehat/glacier library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
patinthehat / glacier example snippets
class MyEvent1 extends Event { }
event(new MyEvent1)
event(new MyEvent1, "my custom payload");
public static $autoRegister = false;
class MyEventListener1 extends EventListener
{
public static $events = [ 'my.event1', 'my.event2' ];
public function handle($event, $payload = null)
{
app()->output()->write('[event fired] '.$event->name . PHP_EOL);
return true;
}
public static $events = [ '*' ];
class MyCommand extends Command
{
public static $autoRegister = true;
public $name = 'mycmd';
public function execute()
{
$this->app->output()->writeln('my command!');
}
}
use Glacier\Console\Application;
use Glacier\Console\DefaultCommand;
use Glacier\Events\Event;
use Glacier\Events\EventListener;
use Glacier\Events\MultipleEventListener;
class MyEvent1 extends Event { }
class MyEvent2 extends Event { }
//automatically registered with the application
class MyEventListener1 extends EventListener
{
public static $events = [ 'my.event1', 'my.event2' ];
public function handle($event, $payload = null)
{
app()->output()->write('[event fired] '.$event->name.'; listener: '.__CLASS__ . '; payload = '. (isset($payload->name) ? $payload->name : '') . PHP_EOL);
return true;
}
}
//automatically registered with the application
class MyEventListener3 extends MultipleEventListener
{
public static $events = [ '*' ];
protected $ignoreMissingHandlers = true;
public function my_event1(Event $event, $payload = null)
{
echo '[1] hi from '.__CLASS__.': '.$event->name.PHP_EOL;
}
public function my_event2(Event $event, $payload = null)
{
echo '[2] hi from '.__CLASS__.': '.$event->name.PHP_EOL;
}
}
class DemoCommand extends DefaultCommand
{
public function initialize()
{
event(new MyEvent2);
}
public function execute()
{
event(new MyEvent1);
app()->output()->writeln('hello from '.$this->getName());
}
}
$app = new Application($argv, __DIR__, true, false, [DemoCommand::class], false, false);
$app->arguments()
->defineOption('t', 'test', true, 0)
->parse();
$app->run();
use Glacier\Console\Application;
use Glacier\Console\DefaultCommand;
class DemoCommand extends DefaultCommand
{
public $name = 'demo2';
public function initialize()
{
//
}
public function execute()
{
if (app()->arguments()->hasOption('goodbye')) {
app()->output()->writeln('goodbye from '.$this->getName());
} else {
app()->output()->writeln('hello from '.$this->getName());
}
}
}
$app = new Application($argv, __DIR__, true, true, [DemoCommand::class], false, false);
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.