Skip to content

Commit e05e9ea

Browse files
committed
update readme with hooks
1 parent f756e9b commit e05e9ea

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,45 @@ And than, run from command line:
4343
php script.php command-name --email=me@example.com
4444
```
4545

46+
### Hooks
47+
48+
There are three types of hooks, init hooks, shutdown hooks and error hooks. Init hooks are executed before the task is executed. Shutdown hook is executed after task is executed before application shuts down. Finally error hooks are executed whenever there's an error in the application lifecycle. You can provide multiple hooks for each stage.
49+
50+
```php
51+
require_once __DIR__ . '/../../vendor/autoload.php';
52+
53+
use Utopia\App;
54+
use Utopia\Request;
55+
use Utopia\Response;
56+
57+
CLI::setResource('res1', function() {
58+
return 'resource 1';
59+
})
60+
61+
CLI::init()
62+
inject('res1')
63+
->action(function($res1) {
64+
Console::info($res1);
65+
});
66+
67+
CLI::error()
68+
->inject('error')
69+
->action(function($error) {
70+
Console::error('Error occurred ' . $error);
71+
});
72+
73+
$cli = new CLI();
74+
75+
$cli
76+
->task('command-name')
77+
->param('email', null, new Wildcard())
78+
->action(function ($email) {
79+
Console::success($email);
80+
});
81+
82+
$cli->run();
83+
```
84+
4685
### Log Messages
4786

4887
```php

0 commit comments

Comments
 (0)