diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 97f4df391..b59bf5d56 100644 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -81,4 +81,41 @@ class FileUtils return ExtensionType::UNKNOWN; } + + /** + * Make file path absolute + * + * @param string $origPath File path + * + * @return string + * + * @since 1.0.0 + */ + public static function absolute(string $origPath) : string + { + if(!file_exists($origPath)) { + $startsWithSlash = strpos($origPath, '/') === 0 ? '/' : ''; + + $path = []; + $parts = explode('/', $origPath); + + foreach($parts as $part) { + if (empty($part) || $part === '.') { + continue; + } + + if ($part !== '..') { + $path[] = $part; + } elseif (!empty($path)) { + array_pop($path); + } else { + throw new PathException($origPath); + } + } + + return $startsWithSlash . implode('/', $path); + } + + return realpath($origPath); + } } \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/Components/ACK.php b/Utils/EDI/AnsiX12/Component/ACK.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/ACK.php rename to Utils/EDI/AnsiX12/Component/ACK.php diff --git a/Utils/EDI/AnsiX12/Components/AMT.php b/Utils/EDI/AnsiX12/Component/AMT.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/AMT.php rename to Utils/EDI/AnsiX12/Component/AMT.php diff --git a/Utils/EDI/AnsiX12/Components/BAK.php b/Utils/EDI/AnsiX12/Component/BAK.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/BAK.php rename to Utils/EDI/AnsiX12/Component/BAK.php diff --git a/Utils/EDI/AnsiX12/Component/BEG.php b/Utils/EDI/AnsiX12/Component/BEG.php new file mode 100644 index 000000000..efbdc0101 --- /dev/null +++ b/Utils/EDI/AnsiX12/Component/BEG.php @@ -0,0 +1,30 @@ +invoiceDate = $invoiceDate; + } + + public function getInvoiceDate() : string + { + return $this->invoiceDate->format('Ymd'); + } + + public function setInvoiceNumber(string $invoice) /* : void */ + { + if(strlen($invoice) < 1 || strlen($invoice) > 22) { + throw new \Exception(); + } + + $this->invoice = $invoice; + } + + public function getInvoiceNumber() : string + { + return $this->invoice; + } + + public function setPurchaseDate(\DateTime $purchaseDate) /* : void */ + { + $this->purchaseDate = $purchaseDate; + } + + public function getPurchaseDate() : string + { + return $this->purchaseDate->format('Ymd'); + } + + public function setPurchaseNumber(string $purchase) /* : void */ + { + if(strlen($purchase) < 1 || strlen($purchase) > 22) { + throw new \Exception(); + } + + $this->purchase = $purchase; + } + + public function getPurchaseNumber() : string + { + return $this->purchase; + } + + public function setTransactionTypeCode(int $code) /* : void */ + { + if($code < 10 || $code > 99) { + throw new \Exception(); + } + + $this->transactionTypeCode = $code; + } + + public function getTransactionTypeCode() : string + { + return str_pad((string) $this->transactionTypeCode, 2, '0', STR_PAD_LEFT); + } +} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/Components/CAD.php b/Utils/EDI/AnsiX12/Component/CAD.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/CAD.php rename to Utils/EDI/AnsiX12/Component/CAD.php diff --git a/Utils/EDI/AnsiX12/Components/CTT.php b/Utils/EDI/AnsiX12/Component/CTT.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/CTT.php rename to Utils/EDI/AnsiX12/Component/CTT.php diff --git a/Utils/EDI/AnsiX12/Components/CUR.php b/Utils/EDI/AnsiX12/Component/CUR.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/CUR.php rename to Utils/EDI/AnsiX12/Component/CUR.php diff --git a/Utils/EDI/AnsiX12/Components/GE.php b/Utils/EDI/AnsiX12/Component/GE.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/GE.php rename to Utils/EDI/AnsiX12/Component/GE.php diff --git a/Utils/EDI/AnsiX12/Component/GS.php b/Utils/EDI/AnsiX12/Component/GS.php new file mode 100644 index 000000000..82b0ab789 --- /dev/null +++ b/Utils/EDI/AnsiX12/Component/GS.php @@ -0,0 +1,176 @@ +date = new \DateTime(); + } + + public function getFunctionalGroupHeader() : string + { + return $this->functionalGroupHeader; + } + + public function getFunctionalIdentifierCode() : string + { + return $this->functionalIdentifierCode; + } + + public function setFunctionalIdentifierCode(string $code) /* : void */ + { + if(!FunctionalIdentifierCode::isValidValue($code)) { + throw \Exception(); + } + + $this->functionalIdentifierCode = $code; + } + + public function getApplicationSenderCode() : string + { + return str_pad((string) $this->applicationSenderCode, 2, '0', STR_PAD_LEFT); + } + + public function setApplicationSenderCode(string $code) /* : void */ + { + if(strlen($code) < 2 || strlen($code) > 15) { + throw new \Exception(); + } + + $this->applicationSenderCode = $code; + } + + public function getApplicationReceiverCode() : string + { + return str_pad((string) $this->applicationReceiverCode, 2, '0', STR_PAD_LEFT); + } + + public function setApplicationReceiverCode(string $code) /* : void */ + { + if(strlen($code) < 2 || strlen($code) > 15) { + throw new \Exception(); + } + + $this->applicationReceiverCode = $code; + } + + public function setDate(\DateTime $date) /* : void */ + { + $this->date = $date; + } + + public function getDate() : string + { + return $this->date->format('d:m:y'); + } + + public function getTime() : string + { + return $this->date->format('d:m:y'); + } + + public function getGroupControlNumber() : int + { + return $this->groupControlNumber; + } + + public function setGroupControlNumber(int $number) /* : void */ + { + if($number < 0) { + throw new \Exception(); + } + + $this->groupControlNumber = $number; + } + + public function getResponsibleAgencyCode() : int + { + return $this->responsibleAgencyCode; + } + + public function setResponsibleAgencyCode(int $code) /* : void */ + { + if($code < 0 || $code > 99) { + throw new \Exception(); + } + + $this->responsibleAgencyCode = $code; + } + + public function getVersion() : string + { + return $this->version; + } + + public function setVersion(string $version) /* : void */ + { + $this->version = $version; + } + + public function serialize() + { + return $this->functionalGroupHeader . '*' + . $this->getFunctionalIdentifierCode() . '*' + . $this->getApplicationSenderCode() . '*' + . $this->getApplicationReceiverCode() . '*' + . $this->getDate() . '*' + . $this->getTime() . '*' + . $this->getGroupControlNumber() . '*' + . $this->getResponsibleAgencyCode() . '*' + . $this->getVersion() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; + } + + public function unserialize($raw) + { + $split = explode($raw); + + $this->setFunctionalGroupHeader(trim($split[0])); + $this->setFunctionalIdentifierCode(trim($split[1])); + $this->setApplicationSenderCode(trim($split[2])); + $this->setApplicationReceiverCode(trim($split[3])); + $this->setDate(new \DateTime(trim($split[4]) . '-' . trim($split[5]))); + $this->setGroupControlNumber(trim($split[6])); + $this->setResponsibleAgencyCode((int) trim($split[7])); + $this->setVersion(trim($split[8])); + } +} diff --git a/Utils/EDI/AnsiX12/Components/IEA.php b/Utils/EDI/AnsiX12/Component/IEA.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/IEA.php rename to Utils/EDI/AnsiX12/Component/IEA.php diff --git a/Utils/EDI/AnsiX12/Component/ISA.php b/Utils/EDI/AnsiX12/Component/ISA.php new file mode 100644 index 000000000..0c537d6b4 --- /dev/null +++ b/Utils/EDI/AnsiX12/Component/ISA.php @@ -0,0 +1,427 @@ +'; + + private $interchangeControlHeader = 'ISA'; + + /** + * Code to identify the type of information in the Authorization Information. + * + * Req: M + * Type: ID + * Min/Max: 2/2 + * Usage: Must + * + * 00 = No Authorization Information available + * + * @var int + * @since 1.0.0 + */ + private $authorizationInformationQualifier = 0; + + + /** + * Information used for additional identification or authorization of the interchange + * sender or the data in the interchange; the type of information is set by the Authorization + * Information Qualifier. + * + * Req: M + * Type: AN + * Min/Max: 10/10 + * Usage: Must + * + * @var string + * @since 1.0.0 + */ + private $authorizationInformation = ''; + + /** + * Code to identify the type of information in the Security Information. + * + * Req: M + * Type: ID + * Min/Max: 2/2 + * Usage: Must + * + * 00 = No Security Information available + * + * @var int + * @since 1.0.0 + */ + private $securityInformationQualifer = 0; + + /** + * This is used for identifying the security information about the interchange + * sender or the data in the interchange; the type of information is set by the Security + * Information Qualifier. + * + * Req: M + * Type: AN + * Min/Max: 10/10 + * Usage: Must + * + * @var string + * @since 1.0.0 + */ + private $securityInformation = ''; + + /** + * Qualifier to designate the system/method of code structure used to designate + * the sender or receiver ID element being qualifiedn. + * + * Req: M + * Type: ID + * Min/Max: 2/2 + * Usage: Must + * + * 00 = No Security Information available + * + * @var int + * @since 1.0.0 + */ + private $interchangeIdQualifier = 0; + + /** + * Interchange Sender + * + * Req: M + * Type: AN + * Min/Max: 15/15 + * Usage: Must + * + * @var string + * @since 1.0.0 + */ + private $interchangeSender = ''; + + /** + * DateTime of the interchange + * + * Req: M + * Type: DTM + * Usage: Must + * + * @var \DateTime + * @since 1.0.0 + */ + private $interchangeDateTime = null; + + /** + * Code to identify the agency responsible for the control standard used by the + * message that is enclosed by the interchange header and trailer. + * + * Req: M + * Type: ID + * Min/Max: 1/1 + * Usage: Must + * + * @var string + * @since 1.0.0 + */ + private $interchangeControlStandardId = ''; + + /** + * Code specifying the version number of the interchange control segments. + * + * Req: M + * Type: ID + * Min/Max: 5/5 + * Usage: Must + * + * @var int + * @since 1.0.0 + */ + private $interchangeControlVersionNumber = 401; + + /** + * A control number assigned by the interchange sender. + * + * Req: M + * Type: int + * Min/Max: 9/9 + * Usage: Must + * + * @var int + * @since 1.0.0 + */ + private $interchangeControlNumber = 0; + + /** + * Code sent by the sender to request an interchange acknowledgment. + * + * Req: M + * Type: bool + * Min/Max: 1/1 + * Usage: Must + * + * @var bool + * @since 1.0.0 + */ + private $acknowledgementRequested = false; + + /** + * Code to indicate whether data enclosed by this interchange envelope is test, + * production or information. + * + * Req: M + * Type: ID + * Min/Max: 1/1 + * Usage: Must + * + * @var int + * @since 1.0.0 + */ + private $usageIndicator = 'T'; + + public function setInterchangeControlHeader(string $header) /* : void */ + { + $this->interchangeControlHeader = $header; + } + + public function setAuthorizationInformationQualifier(int $qualifer) /* : void */ + { + if($qualifer > 99) { + throw new \Exception(); + } + + $this->authorizationInformationQualifier = $qualifier; + } + + public function getAuthorizationInformationQualifier() : string + { + return str_pad((string) $this->authorizationInformationQualifier, 2, '0', STR_PAD_LEFT); + } + + public function setAuthorizationInformation(string $information) /* : void */ + { + if(strlen($information) > 10) { + throw new \Exception(); + } + + $this->authorizationInformation = $information; + } + + public function getAuthorizationInformation() : string + { + return str_pad((string) $this->authorizationInformation, 10, ' ', STR_PAD_RIGHT); + } + + public function setSecurityInformationQualifer(int $qualifer) /* : void */ + { + if($qualifer > 99) { + throw new \Exception(); + } + + $this->securityInformationQualifer = $qualifier; + } + + public function getSecurityInformationQualifer() : string + { + return str_pad((string) $this->securityInformationQualifer, 2, '0', STR_PAD_LEFT); + } + + public function setSecurityInformation(string $information) /* : void */ + { + if(strlen($information) > 10) { + throw new \Exception(); + } + + $this->securityInformation = $information; + } + + public function getSecurityInformation() : string + { + return str_pad((string) $this->securityInformation, 10, ' ', STR_PAD_RIGHT); + } + + public function setInterchangeIdQualifier(int $qualifer) /* : void */ + { + if($qualifer > 99) { + throw new \Exception(); + } + + $this->interchangeIdQualifier = $qualifier; + } + + public function getInterchangeIdQualifier() : string + { + return str_pad((string) $this->interchangeIdQualifier, 2, '0', STR_PAD_LEFT); + } + + + public function setInterchangeSender(string $information) /* : void */ + { + if(strlen($information) > 15) { + throw new \Exception(); + } + + $this->interchangeSender = $information; + } + + public function getInterchangeSender() : string + { + return str_pad((string) $this->interchangeSender, 15, ' ', STR_PAD_RIGHT); + } + + public function setInterchangeReceiver(string $information) /* : void */ + { + if(strlen($information) > 15) { + throw new \Exception(); + } + + $this->interchangeReceiver = $information; + } + + public function getInterchangeReceiver() : string + { + return str_pad((string) $this->interchangeReceiver, 15, ' ', STR_PAD_RIGHT); + } + + public function setInterchangeDatetime(\DateTime $interchange) /* : void */ + { + $this->interchangeDateTime = $interchange; + } + + public function getInterchangeDate() : string + { + return $this->interchangeDateTime->format('d:m:y'); + } + + public function getInterchangeTime() : string + { + return $this->interchangeDateTime->format('H:i'); + } + + public function setInterchangeControlStandardId(string $id) /* : void */ + { + if(strlen($id) !== 1) { + throw new \Exception(); + } + + $this->interchangeControlStandardId = $id; + } + + public function getInterchangeControlStandardId() : string + { + return $this->interchangeControlStandardId; + } + + public function setInterchangeControlVersionNumber(int $version) /* : void */ + { + if($version > 99999) { + throw new \Exception(); + } + + $this->interchangeControlVersionNumber = $version; + } + + public function getInterchangeControlVersionNumber() : string + { + return str_pad((string) $this->interchangeControlVersionNumber, 5, '0', STR_PAD_LEFT); + } + + public function setInterchangeControlNumber(int $number) /* : void */ + { + if($number > 999999999) { + throw new \Exception(); + } + + $this->interchangeControlNumber = $number; + } + + public function getInterchangeControlNumber() : string + { + return str_pad((string) $this->interchangeControlNumber, 9, '0', STR_PAD_LEFT); + } + + public function setAcknowledgmentRequested(bool $ack) /* : void */ + { + $this->acknowledgmentRequested = $ack; + } + + public function getAcknowledgmentRequested() : string + { + return (string) $this->acknowledgmentRequested; + } + + public function setUsageUndicator(string $id) /* : void */ + { + if(strlen($id) !== 1) { + throw new \Exception(); + } + + $this->usageIndicator = $id; + } + + public function getUsageUndicator() : string + { + return $this->usageIndicator; + } + + public function serialize() + { + return $this->interchangeControlHeader . '*' + . $this->getAuthorizationInformationQualifier() . '*' + . $this->getAuthorizationInformation() . '*' + . $this->getSecurityInformationQualifer() . '*' + . $this->getSecurityInformation() . '*' + . $this->getInterchangeIdQualifier() . '*' + . $this->getInterchangeSender() . '*' + . $this->getInterchangeIdQualifier() . '*' + . $this->getInterchangeReceiver() . '*' + . $this->getInterchangeDate() . '*' + . $this->getInterchangeTime() . '*' + . $this->getInterchangeControlStandardId() . '*' + . $this->getInterchangeControlVersionNumber() . '*' + . $this->getInterchangeControlNumber() . '*' + . $this->getAcknowledgmentRequested() . '*' + . $this->getUsageUndicator() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; + } + + public function unserialize($raw) + { + $split = explode('*', $raw); + + $this->setInterchangeControlHeader(trim($split[0])); + $this->setAuthorizationInformationQualifier((int) trim($split[1])); + $this->setAuthorizationInformation(trim($split[2])); + $this->setSecurityInformationQualifer((int) trim($split[3])); + $this->setSecurityInformation(trim($split[4])); + $this->setInterchangeIdQualifier((int) trim($split[5])); + $this->setInterchangeSender(trim($split[6])); + $this->setInterchangeReceiver(trim($split[8])); + $this->setInterchangeDatetime(new \DateTime(trim($split[9]) . '-' . trim($split[10]))); + $this->setInterchangeControlStandardId(trim($split[11])); + $this->setInterchangeControlVersionNumber((int) trim($split[12])); + $this->setInterchangeControlNumber((int) trim($split[13])); + $this->setAcknowledgmentRequested((bool) $split[14]); + $this->setUsageUndicator($split[15]); + } +} diff --git a/Utils/EDI/AnsiX12/Components/IT1.php b/Utils/EDI/AnsiX12/Component/IT1.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/IT1.php rename to Utils/EDI/AnsiX12/Component/IT1.php diff --git a/Utils/EDI/AnsiX12/Components/ITD.php b/Utils/EDI/AnsiX12/Component/ITD.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/ITD.php rename to Utils/EDI/AnsiX12/Component/ITD.php diff --git a/Utils/EDI/AnsiX12/Components/MAN.php b/Utils/EDI/AnsiX12/Component/MAN.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/MAN.php rename to Utils/EDI/AnsiX12/Component/MAN.php diff --git a/Utils/EDI/AnsiX12/Components/N1.php b/Utils/EDI/AnsiX12/Component/N1.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/N1.php rename to Utils/EDI/AnsiX12/Component/N1.php diff --git a/Utils/EDI/AnsiX12/Components/N2.php b/Utils/EDI/AnsiX12/Component/N2.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/N2.php rename to Utils/EDI/AnsiX12/Component/N2.php diff --git a/Utils/EDI/AnsiX12/Components/N3.php b/Utils/EDI/AnsiX12/Component/N3.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/N3.php rename to Utils/EDI/AnsiX12/Component/N3.php diff --git a/Utils/EDI/AnsiX12/Components/N4.php b/Utils/EDI/AnsiX12/Component/N4.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/N4.php rename to Utils/EDI/AnsiX12/Component/N4.php diff --git a/Utils/EDI/AnsiX12/Components/PER.php b/Utils/EDI/AnsiX12/Component/PER.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/PER.php rename to Utils/EDI/AnsiX12/Component/PER.php diff --git a/Utils/EDI/AnsiX12/Components/PID.php b/Utils/EDI/AnsiX12/Component/PID.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/PID.php rename to Utils/EDI/AnsiX12/Component/PID.php diff --git a/Utils/EDI/AnsiX12/Components/PO1.php b/Utils/EDI/AnsiX12/Component/PO1.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/PO1.php rename to Utils/EDI/AnsiX12/Component/PO1.php diff --git a/Utils/EDI/AnsiX12/Components/REF.php b/Utils/EDI/AnsiX12/Component/REF.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/REF.php rename to Utils/EDI/AnsiX12/Component/REF.php diff --git a/Utils/EDI/AnsiX12/Components/SAC.php b/Utils/EDI/AnsiX12/Component/SAC.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/SAC.php rename to Utils/EDI/AnsiX12/Component/SAC.php diff --git a/Utils/EDI/AnsiX12/Components/SCH.php b/Utils/EDI/AnsiX12/Component/SCH.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/SCH.php rename to Utils/EDI/AnsiX12/Component/SCH.php diff --git a/Utils/EDI/AnsiX12/Components/SE.php b/Utils/EDI/AnsiX12/Component/SE.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/SE.php rename to Utils/EDI/AnsiX12/Component/SE.php diff --git a/Utils/EDI/AnsiX12/Component/ST.php b/Utils/EDI/AnsiX12/Component/ST.php new file mode 100644 index 000000000..a82ee7897 --- /dev/null +++ b/Utils/EDI/AnsiX12/Component/ST.php @@ -0,0 +1,82 @@ +transactionSetIdentifierCode = $idCode; + } + + public function setTransactionSetIdentifierCode(int $idCode) + { + if($idCode < 100 || $idCode > 999) { + throw new \Exception(); + } + + $this->transactionSetIdentifierCode = $idCode; + } + + public function getTransactionSetIdentifierCode() : int + { + return $this->transactionSetIdentifierCode; + } + + public function setTransactionSetControlNumber(string $controlNumber) + { + if(strlen($controlNumber) < 4 || strlen($controlNumber) > 9) { + throw new \Exception(); + } + + $this->transactionSetControlNumber = $controlNumber; + } + + public function getTransactionSetControlNumber() : string + { + return str_pad((string) $this->transactionSetControlNumber, 9, '0', STR_PAD_LEFT); + } + + public function serialize() + { + return self::IDENTIFIER . '*' + . $this->getTransactionSetIdentifierCode() . '*' + . $this->getTransactionSetControlNumber() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; + } + + public function unserialize($raw) + { + $split = explode('*', $raw); + + $this->setTransactionSetIdentifierCode((int) $split[1]); + $this->setTransactionSetControlNumber(substr($split[2], -1)); + } +} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/Components/TD5.php b/Utils/EDI/AnsiX12/Component/TD5.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/TD5.php rename to Utils/EDI/AnsiX12/Component/TD5.php diff --git a/Utils/EDI/AnsiX12/Components/TDS.php b/Utils/EDI/AnsiX12/Component/TDS.php similarity index 100% rename from Utils/EDI/AnsiX12/Components/TDS.php rename to Utils/EDI/AnsiX12/Component/TDS.php diff --git a/Utils/EDI/AnsiX12/Components/BEG.php b/Utils/EDI/AnsiX12/Components/BEG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Components/BIG.php b/Utils/EDI/AnsiX12/Components/BIG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Components/GS.php b/Utils/EDI/AnsiX12/Components/GS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Components/ISA.php b/Utils/EDI/AnsiX12/Components/ISA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Components/ST.php b/Utils/EDI/AnsiX12/Components/ST.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/FunctionalIdentifierCode.php b/Utils/EDI/AnsiX12/FunctionalIdentifierCode.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php index 475e15b0d..aa115c032 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php @@ -16,6 +16,7 @@ declare(strict_types=1); namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; use phpOMS\Utils\EDI\AnsiX12\EDIAbstract; +use phpOMS\Utils\EDI\AnsiX12\Component; /** * EDI 850 - Purchase order. @@ -28,11 +29,30 @@ use phpOMS\Utils\EDI\AnsiX12\EDIAbstract; */ class EDI850 extends EDIAbstract { + private $interchangeControlHeader = null; + + private $functionalGroupHeader = null; + + private $heading = null; + + private $detail = null; + + private $summary = null; + + private $functionalGroupTrailer = null; + + private $interchangeControlTrailer = null; + public function __construct() { - parent::__construct(); - $this->heading = new EDIT850Heading(); - $this->detail = new EDIT850Detail(); + $this->interchangeControlHeader = new ISA(); + $this->functionalGroupHeader = new GS(); + + $this->heading = new EDI850Heading(); + $this->detail = new EDI850Detail(); $this->summary = new EDI850Summary(); + + $this->functionalGroupTrailer = new GE(); + $this->interchangeControlTrailer = new IEA(); } } diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850BeginningSegment.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850BeginningSegment.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php index 48c52b9e1..2cdade6a8 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php @@ -15,6 +15,8 @@ declare(strict_types=1); namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; +use phpOMS\Utils\EDI\AnsiX12\Component; + /** * EDI 850 - Purchase order. * diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php index 6c5b39080..71b63bd8f 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php @@ -15,6 +15,8 @@ declare(strict_types=1); namespace phpOMS\Utils\EDI\AnsiX12\Purchase; +use phpOMS\Utils\EDI\AnsiX12\Component; + /** * EDI 850 - Purchase order. * @@ -46,6 +48,7 @@ class EDI850Heading public function __construct() { - $this->headingTransactionSetHeader = new TransactionSetHeader(); + $this->headingTransactionSetHeader = new ST(850); + $this->headingBeginningSegmentPO = new BEG(); } } diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php index 2816de3c7..9eb92e10f 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php @@ -15,6 +15,8 @@ declare(strict_types=1); namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; +use phpOMS\Utils\EDI\AnsiX12\Component; + /** * EDI 850 - Purchase order. * diff --git a/Utils/Encoding/Huffman/Dictionary.php b/Utils/Encoding/Huffman/Dictionary.php index ece8d031c..403c5a0dc 100644 --- a/Utils/Encoding/Huffman/Dictionary.php +++ b/Utils/Encoding/Huffman/Dictionary.php @@ -86,7 +86,6 @@ final class Dictionary } sort($count); - while (count($count) > 1) { $row1 = array_shift($count); $row2 = array_shift($count); @@ -101,14 +100,14 @@ final class Dictionary /** * Fill dictionary. * - * @param string $entry Source data to generate dictionary from + * @param array $entry Source data to generate dictionary from * @param string $value Dictionary value * * @return void * * @since 1.0.0 */ - private function fill(string $entry, string $value = '') /* : void */ + private function fill(array $entry, string $value = '') /* : void */ { if (!is_array($entry[0][1])) { $this->set($entry[0][1], $value . '0'); @@ -143,8 +142,8 @@ final class Dictionary throw new \Exception('Must be a character.'); } - if (!isset($this->dictionary[$entry])) { - throw new \Exception('Character does not exist'); + if (isset($this->dictionary[$entry])) { + throw new \Exception('Character already exists'); } if (strlen(str_replace('0', '', str_replace('1', '', $value))) !== 0) { diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index e06889b06..f99f13ffb 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -15,6 +15,9 @@ declare(strict_types=1); namespace phpOMS\Utils\IO\Zip; +use phpOMS\System\File\FileUtils; +use phpOMS\Utils\StringUtils; + /** * Zip class for handling zip files. * @@ -34,19 +37,19 @@ class Zip implements ArchiveInterface */ public static function pack($sources, string $destination, bool $overwrite = true) : bool { - $destination = str_replace('\\', '/', realpath($destination)); + $destination = FileUtils::absolute(str_replace('\\', '/', $destination)); if (!$overwrite && file_exists($destination)) { return false; } $zip = new \ZipArchive(); - if (!$zip->open($destination, $overwrite ? \ZipArchive::OVERWRITE : \ZipArchive::CREATE)) { + if (!$zip->open($destination, $overwrite ? \ZipArchive::CREATE | \ZipArchive::OVERWRITE : \ZipArchive::CREATE)) { return false; } /** @var array $sources */ - foreach ($sources as $source) { + foreach ($sources as $source => $relative) { $source = str_replace('\\', '/', realpath($source)); if (!file_exists($source)) { @@ -67,13 +70,13 @@ class Zip implements ArchiveInterface $file = realpath($file); if (is_dir($file)) { - $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); + $zip->addEmptyDir(str_replace($relative . '/', '', $file . '/')); } elseif (is_file($file)) { - $zip->addFile(str_replace($source . '/', '', $file), $file); + $zip->addFile(str_replace($relative . '/', '', $file), $file); } } } elseif (is_file($source)) { - $zip->addFile(basename($source), $source); + $zip->addFile($source, $relative); } } diff --git a/Utils/RnG/LinearCongruentialGenerator.php b/Utils/RnG/LinearCongruentialGenerator.php index ae777704d..074452972 100644 --- a/Utils/RnG/LinearCongruentialGenerator.php +++ b/Utils/RnG/LinearCongruentialGenerator.php @@ -26,6 +26,9 @@ namespace phpOMS\Utils\RnG; */ class LinearCongruentialGenerator { + private static $bsdSeed = 0; + private static $msvcrtSeed = 0; + /** * BSD random number * @@ -35,11 +38,13 @@ class LinearCongruentialGenerator * * @since 1.0.0 */ - public static function bsd(int $seed) + public static function bsd(int $seed = 0) { - return function () use (&$seed) { - return $seed = (1103515245 * $seed + 12345) % (1 << 31); - }; + if($seed !== 0) { + self::$bsdSeed = $seed; + } + + return self::$bsdSeed = (1103515245 * self::$bsdSeed + 12345) % (1 << 31); } /** @@ -51,10 +56,12 @@ class LinearCongruentialGenerator * * @since 1.0.0 */ - public static function msvcrt(int $seed) + public static function msvcrt(int $seed = 0) { - return function () use (&$seed) { - return ($seed = (214013 * $seed + 2531011) % (1 << 31)) >> 16; - }; + if($seed !== 0) { + self::$msvcrtSeed = $seed; + } + + return (self::$msvcrtSeed = (214013 * self::$msvcrtSeed + 2531011) % (1 << 31)) >> 16; } } diff --git a/Utils/StringCompare.php b/Utils/StringCompare.php index 810ea64f7..0cf24641d 100644 --- a/Utils/StringCompare.php +++ b/Utils/StringCompare.php @@ -48,6 +48,11 @@ class StringCompare $this->dictionary = $dictionary; } + public function add(string $word) /* : void */ + { + $this->dictionary[] = $word; + } + /** * Match word against dictionary. * @@ -66,6 +71,7 @@ class StringCompare $score = self::fuzzyMatch($word, $match); if($score < $bestScore) { + $bestScore = $score; $bestMatch = $word; } } diff --git a/Views/ViewLayout.php b/Views/ViewLayout.php deleted file mode 100644 index 8cd5411ce..000000000 --- a/Views/ViewLayout.php +++ /dev/null @@ -1,43 +0,0 @@ -