Skip to content

Commit c30ef98

Browse files
Merge pull request #18 from utopia-php/feat-dependency-injection
2 parents 05cd936 + e05e9ea commit c30ef98

12 files changed

Lines changed: 357 additions & 237 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
/vendor/
3-
/.idea/
3+
/.idea/
4+
.phpunit.result.cache

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ before_script: composer install --ignore-platform-reqs
1212

1313
script:
1414
- vendor/bin/phpunit --configuration phpunit.xml < tests/input.txt
15-
- vendor/bin/psalm --show-info=true
15+
- vendor/bin/phpcs -p

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

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"email": "eldad@appwrite.io"
1111
}
1212
],
13+
"scripts": {
14+
"test": "vendor/bin/phpunit --configuration phpunit.xml < tests/input.txt",
15+
"lint": "vendor/bin/phpcs",
16+
"format": "vendor/bin/phpcbf"
17+
},
1318
"autoload": {
1419
"psr-4": {"Utopia\\CLI\\": "src/CLI"}
1520
},
@@ -19,7 +24,7 @@
1924
},
2025
"require-dev": {
2126
"phpunit/phpunit": "^9.3",
22-
"vimeo/psalm": "4.0.1"
27+
"squizlabs/php_codesniffer": "^3.6"
2328
},
2429
"minimum-stability": "dev"
2530
}

phpcs.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Appwrite Standard" namespace="Appwrite">
3+
<rule ref="PSR12"/>
4+
<file>./src</file>
5+
<file>./tests</file>
6+
<ini name="memory_limit" value="4096M"/>
7+
<!-- Exclude SDK's for performance reasons -->
8+
<!-- Ignore max line width -->
9+
<rule ref="Generic.Files.LineLength">
10+
<exclude-pattern>*</exclude-pattern>
11+
</rule>
12+
<!-- Allow Side Effects on root level of files -->
13+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
14+
<exclude-pattern>*</exclude-pattern>
15+
</rule>
16+
</ruleset>

0 commit comments

Comments
 (0)