-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mads Møller
committed
Mar 21, 2019
1 parent
e6a87ff
commit 114b474
Showing
34 changed files
with
3,778 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml export-ignore | ||
/tests export-ignore | ||
/.editorconfig export-ignore | ||
/phpunit.gitlab.xml export-ignore | ||
/gitlab-test-mysql.sh export-ignore | ||
/.gitlab-ci.yml export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.idea/ | ||
codeCoverage/ | ||
vendor/ | ||
composer.lock | ||
.php_cs.cache | ||
_ide_helper.php | ||
.phpstorm.meta.php | ||
coverage | ||
coverage.xml | ||
phpunit.local.xml | ||
composer.lock | ||
/tests/_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="EdiFact-Generator"> | ||
<directory>./tests/GeneratorTest</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
<?php | ||
|
||
namespace EDI\Generator; | ||
|
||
/** | ||
* Class Base | ||
* | ||
* @package EDI\Generator | ||
*/ | ||
class Base { | ||
|
||
/** @var array */ | ||
protected $messageContent = []; | ||
|
||
/** @var array */ | ||
protected $composed; | ||
|
||
/** @var string */ | ||
protected $sender; | ||
|
||
/** @var string */ | ||
protected $receiver; | ||
|
||
/** @var string */ | ||
// protected $managingOrganisation = '89'; | ||
|
||
/** | ||
* @param $keyName | ||
*/ | ||
public function addKeyToCompose($keyName) | ||
{ | ||
$this->composeKeys[] = $keyName; | ||
} | ||
|
||
/** | ||
* compose message by keys givven in an ordered array | ||
* | ||
* @param array $keys | ||
* | ||
* @return array | ||
* @throws EdifactException | ||
*/ | ||
public function composeByKeys($keys = null) | ||
{ | ||
if ($keys === null) { | ||
$keys = $this->composeKeys; | ||
} | ||
foreach ($keys as $key) { | ||
if (property_exists($this, $key)) { | ||
if ($this->{$key} !== null) { | ||
$value = $this->{$key}; | ||
if ($value) { | ||
$this->messageContent[] = $value; | ||
} else { | ||
throw new EdifactException("key " . $key . " returns no array structure"); | ||
} | ||
} | ||
} else { | ||
throw new EdifactException( | ||
'key: ' . $key . ' not found for composeByKeys in ' . get_class($this) . '->' . | ||
debug_backtrace()[1]['function'] | ||
); | ||
} | ||
} | ||
|
||
return $this->messageContent; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getComposed() { | ||
return $this->composed; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSender() { | ||
return $this->sender; | ||
} | ||
|
||
/** | ||
* @param string $sender | ||
* | ||
* @return $this | ||
*/ | ||
public function setSender($sender) { | ||
$this->sender = $sender; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getReceiver() { | ||
return $this->receiver; | ||
} | ||
|
||
/** | ||
* @param string $receiver | ||
* | ||
* @return $this | ||
*/ | ||
public function setReceiver($receiver) { | ||
$this->receiver = $receiver; | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param string, $functionCode | ||
* @param $identifier | ||
* | ||
* @return array|bool | ||
*/ | ||
protected function addRFFSegment($functionCode, $identifier) { | ||
if (empty($identifier)) { | ||
return false; | ||
} | ||
|
||
return [ | ||
'RFF', | ||
[ | ||
$functionCode, | ||
self::maxChars($identifier, 35), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param $dateString | ||
* @param $type | ||
* @param int $formatQualifier | ||
* | ||
* @see https://www.stylusstudio.com/edifact/D94A/2379.htm | ||
* @return array | ||
* @throws EdifactException | ||
*/ | ||
protected function addDTMSegment($dateString, $type, $formatQualifier = EdifactDate::DATE) { | ||
$data = []; | ||
$data[] = (string) $type; | ||
if (!empty($dateString)) { | ||
$data[] = EdifactDate::get($dateString , $formatQualifier); | ||
$data[] = (string)$formatQualifier; | ||
} | ||
|
||
return ['DTM', $data]; | ||
} | ||
|
||
/** | ||
* @param $documentNumber | ||
* @param $type | ||
* | ||
* @return array | ||
*/ | ||
public static function addBGMSegment($documentNumber, $type) { | ||
return [ | ||
'BGM', | ||
[ | ||
$type, | ||
'', | ||
'89', | ||
], | ||
$documentNumber, | ||
]; | ||
} | ||
|
||
/** | ||
* Crop String to max char length | ||
* | ||
* @param string $string | ||
* @param int $length | ||
* | ||
* @return string | ||
*/ | ||
protected static function maxChars($string, $length = 35) { | ||
if (empty($string)) { | ||
return ''; | ||
} | ||
|
||
return mb_substr($string, 0, $length); | ||
} | ||
|
||
/** | ||
* | ||
* @param $value | ||
* @param $array | ||
* @param null $errorMessage | ||
* | ||
* @throws EdifactException | ||
*/ | ||
protected function isAllowed($value, $array, $errorMessage = null) { | ||
if ($errorMessage === null) { | ||
$errorMessage = 'value: ' . $value . ' is not in allowed values: ' . | ||
' [' . implode(', ', $array) . '] in ' . get_class($this) . '->' . | ||
debug_backtrace()[1]['function']; | ||
} | ||
if (!in_array($value , $array , true)) { | ||
throw new EdifactException($errorMessage); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @param $qualifier | ||
* @param $value | ||
* | ||
* @return array | ||
*/ | ||
public static function addMOASegment($qualifier, $value) { | ||
return [ | ||
'MOA', | ||
[ | ||
'', | ||
(string) $qualifier, | ||
EdiFactNumber::convert($value), | ||
], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.