Skip to content

Commit

Permalink
Extension: added version, name, catchExceptions, autoExit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 12, 2016
1 parent 1c2b672 commit dc06cc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ That's all. You don't have to be worried.

## Configuration

```yaml
console:
name: Acme Project
version: 1.0
catchExceptions: true / false
autoExit: true / false
url: www.acme.com
```

### URL address

There's no url in console mode (SAPI). But you can setup it by following line.

```yaml
console:
url: www.example.com
url: www.acme.com
```

## Example
Expand Down
23 changes: 22 additions & 1 deletion src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ final class ConsoleExtension extends CompilerExtension
/** @var array */
private $defaults = [
'url' => NULL,
'name' => NULL,
'version' => NULL,
'catchExceptions' => NULL,
'autoExit' => NULL,
];

/**
Expand All @@ -31,9 +35,26 @@ public function loadConfiguration()
if (PHP_SAPI !== 'cli') return;

$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);

$builder->addDefinition($this->prefix('application'))
$application = $builder->addDefinition($this->prefix('application'))
->setClass(Application::class);

if ($config['name'] !== NULL) {
$application->addSetup('setName', [$config['name']]);
}

if ($config['version'] !== NULL) {
$application->addSetup('setVersion', [$config['version']]);
}

if ($config['catchExceptions'] !== NULL) {
$application->addSetup('setCatchExceptions', [(bool) $config['catchExceptions']]);
}

if ($config['autoExit'] !== NULL) {
$application->addSetup('autoExit', [(bool) $config['autoExit']]);
}
}

/**
Expand Down

0 comments on commit dc06cc2

Please sign in to comment.