-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from utopia-php/feat-dependency-injection
- Loading branch information
Showing
12 changed files
with
357 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
composer.lock | ||
/vendor/ | ||
/.idea/ | ||
/.idea/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,45 @@ And than, run from command line: | |
php script.php command-name [email protected] | ||
``` | ||
|
||
### Hooks | ||
|
||
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. | ||
|
||
```php | ||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use Utopia\App; | ||
use Utopia\Request; | ||
use Utopia\Response; | ||
|
||
CLI::setResource('res1', function() { | ||
return 'resource 1'; | ||
}) | ||
|
||
CLI::init() | ||
inject('res1') | ||
->action(function($res1) { | ||
Console::info($res1); | ||
}); | ||
|
||
CLI::error() | ||
->inject('error') | ||
->action(function($error) { | ||
Console::error('Error occurred ' . $error); | ||
}); | ||
|
||
$cli = new CLI(); | ||
|
||
$cli | ||
->task('command-name') | ||
->param('email', null, new Wildcard()) | ||
->action(function ($email) { | ||
Console::success($email); | ||
}); | ||
|
||
$cli->run(); | ||
``` | ||
|
||
### Log Messages | ||
|
||
```php | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,11 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"scripts": { | ||
"test": "vendor/bin/phpunit --configuration phpunit.xml < tests/input.txt", | ||
"lint": "vendor/bin/phpcs", | ||
"format": "vendor/bin/phpcbf" | ||
}, | ||
"autoload": { | ||
"psr-4": {"Utopia\\CLI\\": "src/CLI"} | ||
}, | ||
|
@@ -19,7 +24,7 @@ | |
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.3", | ||
"vimeo/psalm": "4.0.1" | ||
"squizlabs/php_codesniffer": "^3.6" | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Appwrite Standard" namespace="Appwrite"> | ||
<rule ref="PSR12"/> | ||
<file>./src</file> | ||
<file>./tests</file> | ||
<ini name="memory_limit" value="4096M"/> | ||
<!-- Exclude SDK's for performance reasons --> | ||
<!-- Ignore max line width --> | ||
<rule ref="Generic.Files.LineLength"> | ||
<exclude-pattern>*</exclude-pattern> | ||
</rule> | ||
<!-- Allow Side Effects on root level of files --> | ||
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols"> | ||
<exclude-pattern>*</exclude-pattern> | ||
</rule> | ||
</ruleset> |
Oops, something went wrong.