Skip to content

Commit

Permalink
Added InvoiceExtension for nette/di
Browse files Browse the repository at this point in the history
  • Loading branch information
AntikCz committed Mar 3, 2016
1 parent e45bccc commit 98c0a79
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,38 @@ $invoice->setTranslator(new MyTranslator());

or you can send pull-request with your translation to core component.

## Nette DI

```yaml
extensions:
invoice: WebChemistry\Invoice\DI\InvoiceExtension

invoice:
company:
name:
town:
address:
zip:
country:
## Optional
tin:
vaTin:
logo:
footer:
isTax:
```

```php

class Component {

public function __construct(WebChemistry\Invoice\Invoice $invoice) {
// ...
}
}

```

## Previews

First page:
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"nette/utils": "^2.3",
"intervention/image": "^2.3"
},
"require-dev": {
"nette/di": "^2.3"
},
"autoload": {
"classmap": ["src/"]
}
Expand Down
33 changes: 33 additions & 0 deletions src/DI/InvoiceExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace WebChemistry\Invoice\DI;

use Nette\DI\CompilerExtension;

class InvoiceExtension extends CompilerExtension {

/** @var array */
public $defaults = [
'company' => [],
];

public function loadConfiguration() {
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);

$cmp = $builder->addDefinition($this->prefix('company'))
->setClass('WebChemistry\Invoice\Data\Company');

foreach ($config['company'] as $name => $value) {
$cmp->addSetup($name, [$value]);
}
$cmp->addSetup('check()');

$builder->addDefinition($this->prefix('template'))
->setClass('WebChemistry\Invoice\Data\Template');

$builder->addDefinition($this->prefix('invoice'))
->setClass('WebChemistry\Invoice\Invoice', [$this->prefix('@company'), $this->prefix('@template')]);
}

}

0 comments on commit 98c0a79

Please sign in to comment.