Skip to content

Commit

Permalink
Generator version implementation, cherry-picked from #5 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanwilfer authored Dec 19, 2023
1 parent ad37ad8 commit 17e40d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ And it will generate the following output (in PC8/CP437 encoding):
#FLAGGA 0
#FORMAT PC8
#SIETYP 4
#PROGRAM "SIE-PHP exporter"
#PROGRAM "SIE-PHP exporter" 1.0
#GEN 20150921
#FNAMN "My company"
#KONTO 1511 Kundfordringar
Expand Down
16 changes: 11 additions & 5 deletions src/SIE/Dumper/SIEDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
class SIEDumper
{
const DEFAULT_GENERATOR_NAME = 'SIE-PHP exporter';
const DEFAULT_GENERATOR_VERSION = '1.0';

/**
* Delimiter used for newline.
* @var string
Expand Down Expand Up @@ -123,7 +126,8 @@ public function __construct()
{
// default options
$this->options = [
'generator' => 'SIE-PHP exporter',
'generator' => self::DEFAULT_GENERATOR_NAME,
'generator_version' => self::DEFAULT_GENERATOR_VERSION,
'generated_date' => date('Ymd'),
'generated_sign' => null,
];
Expand All @@ -132,11 +136,13 @@ public function __construct()
/**
* Set generator (custom "PROGRAM" name).
*
* @param $generator
* @param string $generatorName
* @param string $generatorVersion
*/
public function setGenerator($generator)
public function setGenerator($generatorName, $generatorVersion = self::DEFAULT_GENERATOR_VERSION)
{
$this->options['generator'] = $generator;
$this->options['generator'] = $generatorName;
$this->options['generator_version'] = $generatorVersion;
}

/**
Expand All @@ -150,7 +156,7 @@ public function dump(Data\Company $sie)
$data = $this->getLine('FLAGGA', ['0']);
$data .= $this->getLine('FORMAT', ['PC8']);
$data .= $this->getLine('SIETYP', ['4']);
$data .= $this->getLine('PROGRAM', [$this->options['generator']]);
$data .= $this->getLine('PROGRAM', [$this->options['generator'], $this->options['generator_version']]);
$data .= $this->getLine('GEN', [$this->options['generated_date'], $this->options['generated_sign']]);
$data .= $this->getLine('FNAMN', [$sie->getCompanyName()]);
// optional
Expand Down

0 comments on commit 17e40d9

Please sign in to comment.