Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nowisesys/uup-application
Run monitored command action for CLI command line and HTTP requests.
https://github.com/nowisesys/uup-application
Last synced: 28 days ago
JSON representation
Run monitored command action for CLI command line and HTTP requests.
- Host: GitHub
- URL: https://github.com/nowisesys/uup-application
- Owner: nowisesys
- License: apache-2.0
- Created: 2022-01-07T10:52:18.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T14:32:55.000Z (almost 3 years ago)
- Last Synced: 2024-05-05T04:01:52.401Z (6 months ago)
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UUP-APPLICATION
==========================================Run the same command action both for CLI command line and HTTP requests with monitoring.
### ACTIONS:
The action class handles business logic and the runner executes and monitor the action.
#### Example
```php
execute();```
### LIFETIME:
The action class derives from `ApplicationAction` and implements the lifetime methods `usage()`, `setup()`,
`execute()` and `cleanup()`. At least the setup method should be implemented, the other are optional.```php
class HelloWorldAction extends ApplicationAction
{
public function setup(): void
{
if ($this->options->isMissing('my-name')) {
$this->options->setOption('my-name', "Anders");
}
}public function execute(): void
{
if ($this->options->hasOption('my-name')) {
printf("Hello world, %s!\n", $this->options->getString('my-name'));
}
}
}
```### OPTIONS:
Command options are passed from CLI command options or HTTP request depending on execution context. The runner takes
are of handling help or quiet options. The standard options `help`, `version` and `quiet` are transparent handled along
with their short option equivalents.### MONITOR:
The runner execute the action class and provides error monitoring. By default, runner will terminate action when a
throwable get caught. The error behavior can be overridden by action class.### INLINE:
For simple tasks, use an anonymous (java-style) class with implementations of wanted methods:
```php
execute();
```See [example](example) directory for code examples.
### INFORMATION:
Provide `help` and `version` information by overriding base class methods in your action class.
#### HELP
Override the `usage()` method. Call parent method to output standard options.
```php
class HelloWorldAction extends ApplicationAction
{
public function usage(): void
{
printf("Sample greeter action class.\n");
printf("\n");
printf("Options:\n");
printf(" my-name: Set caller name.\n");
printf("\n");parent::usage();
}...
}
```#### VERSION
Similar to usage, but override the `version()` instead. This method gives full control of version output.
```php
class HelloWorldAction extends ApplicationAction
{
public function version(): void
{
printf("hello-world %s\n", $this->getVersion());
}public function getVersion(): string
{
return "1.2.2";
}...
}
```If default version format is OK, then overriding the `getVersion()` method should be sufficient.
#### ZERO MAINTENANCE:
**Hint:** Consider reading version string from your package composer.json file instead of using a hard coded string
that requires manual update!