Skip to content

Commit

Permalink
Merge pull request #18 from utopia-php/feat-dependency-injection
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar authored Oct 9, 2022
2 parents 05cd936 + e05e9ea commit c30ef98
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 237 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
/vendor/
/.idea/
/.idea/
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ before_script: composer install --ignore-platform-reqs

script:
- vendor/bin/phpunit --configuration phpunit.xml < tests/input.txt
- vendor/bin/psalm --show-info=true
- vendor/bin/phpcs -p
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
},
Expand All @@ -19,7 +24,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "4.0.1"
"squizlabs/php_codesniffer": "^3.6"
},
"minimum-stability": "dev"
}
16 changes: 16 additions & 0 deletions phpcs.xml
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>
Loading

0 comments on commit c30ef98

Please sign in to comment.