repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean13.php | CINean13.draw | public function draw($im) {
$this->drawBars($im);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
if ($this->isDefaultEanLabelEnabled()) {
$dimension = $this->labelCenter1->getDimension();
$this->drawExtendedBars($im, $dimension[1] - 2);
}
} | php | public function draw($im) {
$this->drawBars($im);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
if ($this->isDefaultEanLabelEnabled()) {
$dimension = $this->labelCenter1->getDimension();
$this->drawExtendedBars($im, $dimension[1] - 2);
}
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"$",
"this",
"->",
"drawBars",
"(",
"$",
"im",
")",
";",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isDefaultEanLabelEnabled",
"(",
")",
")",
"{",
"$",
"dimension",
"=",
"$",
"this",
"->",
"labelCenter1",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"drawExtendedBars",
"(",
"$",
"im",
",",
"$",
"dimension",
"[",
"1",
"]",
"-",
"2",
")",
";",
"}",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean13.php#L83-L91 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean13.php | CINean13.addDefaultLabel | protected function addDefaultLabel() {
if ($this->isDefaultEanLabelEnabled()) {
$this->processChecksum();
$label = $this->getLabel();
$font = $this->font;
$this->labelLeft = new CINLabel(substr($label, 0, 1), $font, CINLabel::POSITION_LEFT, CINLabel::ALIGN_BOTTOM);
$this->labelLeft->setSpacing(4 * $this->scale);
$this->labelCenter1 = new CINLabel(substr($label, 1, 6), $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelCenter1Dimension = $this->labelCenter1->getDimension();
$this->labelCenter1->setOffset(($this->scale * 44 - $labelCenter1Dimension[0]) / 2 + $this->scale * 2);
$this->labelCenter2 = new CINLabel(substr($label, 7, 5) . $this->keys[$this->checksumValue], $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$this->labelCenter2->setOffset(($this->scale * 44 - $labelCenter1Dimension[0]) / 2 + $this->scale * 48);
if ($this->alignLabel) {
$labelDimension = $this->labelCenter1->getDimension();
$this->labelLeft->setOffset($labelDimension[1]);
} else {
$labelDimension = $this->labelLeft->getDimension();
$this->labelLeft->setOffset($labelDimension[1] / 2);
}
$this->addLabel($this->labelLeft);
$this->addLabel($this->labelCenter1);
$this->addLabel($this->labelCenter2);
}
} | php | protected function addDefaultLabel() {
if ($this->isDefaultEanLabelEnabled()) {
$this->processChecksum();
$label = $this->getLabel();
$font = $this->font;
$this->labelLeft = new CINLabel(substr($label, 0, 1), $font, CINLabel::POSITION_LEFT, CINLabel::ALIGN_BOTTOM);
$this->labelLeft->setSpacing(4 * $this->scale);
$this->labelCenter1 = new CINLabel(substr($label, 1, 6), $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$labelCenter1Dimension = $this->labelCenter1->getDimension();
$this->labelCenter1->setOffset(($this->scale * 44 - $labelCenter1Dimension[0]) / 2 + $this->scale * 2);
$this->labelCenter2 = new CINLabel(substr($label, 7, 5) . $this->keys[$this->checksumValue], $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT);
$this->labelCenter2->setOffset(($this->scale * 44 - $labelCenter1Dimension[0]) / 2 + $this->scale * 48);
if ($this->alignLabel) {
$labelDimension = $this->labelCenter1->getDimension();
$this->labelLeft->setOffset($labelDimension[1]);
} else {
$labelDimension = $this->labelLeft->getDimension();
$this->labelLeft->setOffset($labelDimension[1] / 2);
}
$this->addLabel($this->labelLeft);
$this->addLabel($this->labelCenter1);
$this->addLabel($this->labelCenter2);
}
} | [
"protected",
"function",
"addDefaultLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDefaultEanLabelEnabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"processChecksum",
"(",
")",
";",
"$",
"label",
"=",
"$",
"this",
"->",
"getLabel",
"(",
")",
";",
"$",
"font",
"=",
"$",
"this",
"->",
"font",
";",
"$",
"this",
"->",
"labelLeft",
"=",
"new",
"CINLabel",
"(",
"substr",
"(",
"$",
"label",
",",
"0",
",",
"1",
")",
",",
"$",
"font",
",",
"CINLabel",
"::",
"POSITION_LEFT",
",",
"CINLabel",
"::",
"ALIGN_BOTTOM",
")",
";",
"$",
"this",
"->",
"labelLeft",
"->",
"setSpacing",
"(",
"4",
"*",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"this",
"->",
"labelCenter1",
"=",
"new",
"CINLabel",
"(",
"substr",
"(",
"$",
"label",
",",
"1",
",",
"6",
")",
",",
"$",
"font",
",",
"CINLabel",
"::",
"POSITION_BOTTOM",
",",
"CINLabel",
"::",
"ALIGN_LEFT",
")",
";",
"$",
"labelCenter1Dimension",
"=",
"$",
"this",
"->",
"labelCenter1",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"labelCenter1",
"->",
"setOffset",
"(",
"(",
"$",
"this",
"->",
"scale",
"*",
"44",
"-",
"$",
"labelCenter1Dimension",
"[",
"0",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"scale",
"*",
"2",
")",
";",
"$",
"this",
"->",
"labelCenter2",
"=",
"new",
"CINLabel",
"(",
"substr",
"(",
"$",
"label",
",",
"7",
",",
"5",
")",
".",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
",",
"$",
"font",
",",
"CINLabel",
"::",
"POSITION_BOTTOM",
",",
"CINLabel",
"::",
"ALIGN_LEFT",
")",
";",
"$",
"this",
"->",
"labelCenter2",
"->",
"setOffset",
"(",
"(",
"$",
"this",
"->",
"scale",
"*",
"44",
"-",
"$",
"labelCenter1Dimension",
"[",
"0",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"scale",
"*",
"48",
")",
";",
"if",
"(",
"$",
"this",
"->",
"alignLabel",
")",
"{",
"$",
"labelDimension",
"=",
"$",
"this",
"->",
"labelCenter1",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"labelLeft",
"->",
"setOffset",
"(",
"$",
"labelDimension",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"labelDimension",
"=",
"$",
"this",
"->",
"labelLeft",
"->",
"getDimension",
"(",
")",
";",
"$",
"this",
"->",
"labelLeft",
"->",
"setOffset",
"(",
"$",
"labelDimension",
"[",
"1",
"]",
"/",
"2",
")",
";",
"}",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"labelLeft",
")",
";",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"labelCenter1",
")",
";",
"$",
"this",
"->",
"addLabel",
"(",
"$",
"this",
"->",
"labelCenter2",
")",
";",
"}",
"}"
] | Adds the default label. | [
"Adds",
"the",
"default",
"label",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean13.php#L114-L142 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean13.php | CINean13.validate | protected function validate() {
$c = strlen($this->text);
if ($c === 0) {
throw new CINParseException('ean13', 'No data has been entered.');
}
$this->checkCharsAllowed();
$this->checkCorrectLength();
parent::validate();
} | php | protected function validate() {
$c = strlen($this->text);
if ($c === 0) {
throw new CINParseException('ean13', 'No data has been entered.');
}
$this->checkCharsAllowed();
$this->checkCorrectLength();
parent::validate();
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"if",
"(",
"$",
"c",
"===",
"0",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'ean13'",
",",
"'No data has been entered.'",
")",
";",
"}",
"$",
"this",
"->",
"checkCharsAllowed",
"(",
")",
";",
"$",
"this",
"->",
"checkCorrectLength",
"(",
")",
";",
"parent",
"::",
"validate",
"(",
")",
";",
"}"
] | Validates the input. | [
"Validates",
"the",
"input",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean13.php#L158-L168 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean13.php | CINean13.checkCorrectLength | protected function checkCorrectLength() {
// If we have 13 chars, just flush the last one without throwing anything
$c = strlen($this->text);
if ($c === 13) {
$this->text = substr($this->text, 0, 12);
} elseif ($c !== 12) {
throw new CINParseException('ean13', 'Must contain 12 digits, the 13th digit is automatically added.');
}
} | php | protected function checkCorrectLength() {
// If we have 13 chars, just flush the last one without throwing anything
$c = strlen($this->text);
if ($c === 13) {
$this->text = substr($this->text, 0, 12);
} elseif ($c !== 12) {
throw new CINParseException('ean13', 'Must contain 12 digits, the 13th digit is automatically added.');
}
} | [
"protected",
"function",
"checkCorrectLength",
"(",
")",
"{",
"// If we have 13 chars, just flush the last one without throwing anything\r",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"if",
"(",
"$",
"c",
"===",
"13",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"substr",
"(",
"$",
"this",
"->",
"text",
",",
"0",
",",
"12",
")",
";",
"}",
"elseif",
"(",
"$",
"c",
"!==",
"12",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'ean13'",
",",
"'Must contain 12 digits, the 13th digit is automatically added.'",
")",
";",
"}",
"}"
] | Check correct length. | [
"Check",
"correct",
"length",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean13.php#L186-L194 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINean13.php | CINean13.drawBars | protected function drawBars($im) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw Second Code
$this->drawChar($im, $this->findCode($temp_text[1]), false);
// Draw Manufacturer Code
for ($i = 0; $i < 5; $i++) {
$this->drawChar($im, self::inverse($this->findCode($temp_text[$i + 2]), $this->codeParity[(int)$temp_text[0]][$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Product Code
for ($i = 7; $i < 13; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
} | php | protected function drawBars($im) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw Second Code
$this->drawChar($im, $this->findCode($temp_text[1]), false);
// Draw Manufacturer Code
for ($i = 0; $i < 5; $i++) {
$this->drawChar($im, self::inverse($this->findCode($temp_text[$i + 2]), $this->codeParity[(int)$temp_text[0]][$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Product Code
for ($i = 7; $i < 13; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
} | [
"protected",
"function",
"drawBars",
"(",
"$",
"im",
")",
"{",
"// Checksum\r",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"$",
"temp_text",
"=",
"$",
"this",
"->",
"text",
".",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
";",
"// Starting Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'000'",
",",
"true",
")",
";",
"// Draw Second Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"1",
"]",
")",
",",
"false",
")",
";",
"// Draw Manufacturer Code\r",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"5",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"self",
"::",
"inverse",
"(",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"$",
"i",
"+",
"2",
"]",
")",
",",
"$",
"this",
"->",
"codeParity",
"[",
"(",
"int",
")",
"$",
"temp_text",
"[",
"0",
"]",
"]",
"[",
"$",
"i",
"]",
")",
",",
"false",
")",
";",
"}",
"// Draw Center Guard Bar\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'00000'",
",",
"false",
")",
";",
"// Draw Product Code\r",
"for",
"(",
"$",
"i",
"=",
"7",
";",
"$",
"i",
"<",
"13",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"$",
"i",
"]",
")",
",",
"true",
")",
";",
"}",
"// Draw Right Guard Bar\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'000'",
",",
"true",
")",
";",
"}"
] | Draws the bars
@param resource $im | [
"Draws",
"the",
"bars"
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINean13.php#L248-L274 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode11.php | CINcode11.draw | public function draw($im) {
// Starting Code
$this->drawChar($im, '001100', true);
// Chars
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
// Checksum
$this->calculateChecksum();
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending Code
$this->drawChar($im, '00110', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | php | public function draw($im) {
// Starting Code
$this->drawChar($im, '001100', true);
// Chars
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
// Checksum
$this->calculateChecksum();
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending Code
$this->drawChar($im, '00110', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"// Starting Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'001100'",
",",
"true",
")",
";",
"// Chars\r",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
")",
",",
"true",
")",
";",
"}",
"// Checksum\r",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"checksumValue",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"code",
"[",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"i",
"]",
"]",
",",
"true",
")",
";",
"}",
"// Ending Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'00110'",
",",
"true",
")",
";",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode11.php#L44-L64 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode11.php | CINcode11.getDimension | public function getDimension($w, $h) {
$startlength = 8;
$textlength = 0;
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$textlength += $this->getIndexLength($this->findIndex($this->text[$i]));
}
$checksumlength = 0;
$this->calculateChecksum();
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$checksumlength += $this->getIndexLength($this->checksumValue[$i]);
}
$endlength = 7;
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | php | public function getDimension($w, $h) {
$startlength = 8;
$textlength = 0;
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$textlength += $this->getIndexLength($this->findIndex($this->text[$i]));
}
$checksumlength = 0;
$this->calculateChecksum();
$c = count($this->checksumValue);
for ($i = 0; $i < $c; $i++) {
$checksumlength += $this->getIndexLength($this->checksumValue[$i]);
}
$endlength = 7;
$w += $startlength + $textlength + $checksumlength + $endlength;
$h += $this->thickness;
return parent::getDimension($w, $h);
} | [
"public",
"function",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
"{",
"$",
"startlength",
"=",
"8",
";",
"$",
"textlength",
"=",
"0",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"this",
"->",
"text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"textlength",
"+=",
"$",
"this",
"->",
"getIndexLength",
"(",
"$",
"this",
"->",
"findIndex",
"(",
"$",
"this",
"->",
"text",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"$",
"checksumlength",
"=",
"0",
";",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"checksumValue",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksumlength",
"+=",
"$",
"this",
"->",
"getIndexLength",
"(",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"endlength",
"=",
"7",
";",
"$",
"w",
"+=",
"$",
"startlength",
"+",
"$",
"textlength",
"+",
"$",
"checksumlength",
"+",
"$",
"endlength",
";",
"$",
"h",
"+=",
"$",
"this",
"->",
"thickness",
";",
"return",
"parent",
"::",
"getDimension",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Returns the maximal size of a barcode.
@param int $w
@param int $h
@return int[] | [
"Returns",
"the",
"maximal",
"size",
"of",
"a",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode11.php#L73-L95 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINcode11.php | CINcode11.calculateChecksum | protected function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 11 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 10, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 9, the sequence wraps around back to 1.
$sequence_multiplier = array(10, 9);
$temp_text = $this->text;
$this->checksumValue = array();
for ($z = 0; $z < 2; $z++) {
$c = strlen($temp_text);
// We don't display the K CheckSum if the original text had a length less than 10
if ($c <= 10 && $z === 1) {
break;
}
$checksum = 0;
for ($i = $c, $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if ($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $this->findIndex($temp_text[$j]) * $multiplier;
}
$this->checksumValue[$z] = $checksum % 11;
$temp_text .= $this->keys[$this->checksumValue[$z]];
}
} | php | protected function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 11 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 10, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 9, the sequence wraps around back to 1.
$sequence_multiplier = array(10, 9);
$temp_text = $this->text;
$this->checksumValue = array();
for ($z = 0; $z < 2; $z++) {
$c = strlen($temp_text);
// We don't display the K CheckSum if the original text had a length less than 10
if ($c <= 10 && $z === 1) {
break;
}
$checksum = 0;
for ($i = $c, $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if ($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $this->findIndex($temp_text[$j]) * $multiplier;
}
$this->checksumValue[$z] = $checksum % 11;
$temp_text .= $this->keys[$this->checksumValue[$z]];
}
} | [
"protected",
"function",
"calculateChecksum",
"(",
")",
"{",
"// Checksum\r",
"// First CheckSUM \"C\"\r",
"// The \"C\" checksum character is the modulo 11 remainder of the sum of the weighted\r",
"// value of the data characters. The weighting value starts at \"1\" for the right-most\r",
"// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.\r",
"// After 10, the sequence wraps around back to 1.\r",
"// Second CheckSUM \"K\"\r",
"// Same as CheckSUM \"C\" but we count the CheckSum \"C\" at the end\r",
"// After 9, the sequence wraps around back to 1.\r",
"$",
"sequence_multiplier",
"=",
"array",
"(",
"10",
",",
"9",
")",
";",
"$",
"temp_text",
"=",
"$",
"this",
"->",
"text",
";",
"$",
"this",
"->",
"checksumValue",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"z",
"=",
"0",
";",
"$",
"z",
"<",
"2",
";",
"$",
"z",
"++",
")",
"{",
"$",
"c",
"=",
"strlen",
"(",
"$",
"temp_text",
")",
";",
"// We don't display the K CheckSum if the original text had a length less than 10\r",
"if",
"(",
"$",
"c",
"<=",
"10",
"&&",
"$",
"z",
"===",
"1",
")",
"{",
"break",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"c",
",",
"$",
"j",
"=",
"0",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
",",
"$",
"j",
"++",
")",
"{",
"$",
"multiplier",
"=",
"$",
"i",
"%",
"$",
"sequence_multiplier",
"[",
"$",
"z",
"]",
";",
"if",
"(",
"$",
"multiplier",
"===",
"0",
")",
"{",
"$",
"multiplier",
"=",
"$",
"sequence_multiplier",
"[",
"$",
"z",
"]",
";",
"}",
"$",
"checksum",
"+=",
"$",
"this",
"->",
"findIndex",
"(",
"$",
"temp_text",
"[",
"$",
"j",
"]",
")",
"*",
"$",
"multiplier",
";",
"}",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"z",
"]",
"=",
"$",
"checksum",
"%",
"11",
";",
"$",
"temp_text",
".=",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"[",
"$",
"z",
"]",
"]",
";",
"}",
"}"
] | Overloaded method to calculate checksum. | [
"Overloaded",
"method",
"to",
"calculate",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode11.php#L119-L154 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINmsi.php | CINmsi.setChecksum | public function setChecksum($checksum) {
$checksum = intval($checksum);
if ($checksum < 0 && $checksum > 2) {
throw new CINArgumentException('The checksum must be between 0 and 2 included.', 'checksum');
}
$this->checksum = $checksum;
} | php | public function setChecksum($checksum) {
$checksum = intval($checksum);
if ($checksum < 0 && $checksum > 2) {
throw new CINArgumentException('The checksum must be between 0 and 2 included.', 'checksum');
}
$this->checksum = $checksum;
} | [
"public",
"function",
"setChecksum",
"(",
"$",
"checksum",
")",
"{",
"$",
"checksum",
"=",
"intval",
"(",
"$",
"checksum",
")",
";",
"if",
"(",
"$",
"checksum",
"<",
"0",
"&&",
"$",
"checksum",
">",
"2",
")",
"{",
"throw",
"new",
"CINArgumentException",
"(",
"'The checksum must be between 0 and 2 included.'",
",",
"'checksum'",
")",
";",
"}",
"$",
"this",
"->",
"checksum",
"=",
"$",
"checksum",
";",
"}"
] | Sets how many checksums we display. 0 to 2.
@param int $checksum | [
"Sets",
"how",
"many",
"checksums",
"we",
"display",
".",
"0",
"to",
"2",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINmsi.php#L48-L55 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINmsi.php | CINmsi.calculateChecksum | protected function calculateChecksum() {
// Forming a new number
// If the original number is even, we take all even position
// If the original number is odd, we take all odd position
// 123456 = 246
// 12345 = 135
// Multiply by 2
// Add up all the digit in the result (270 : 2+7+0)
// Add up other digit not used.
// 10 - (? Modulo 10). If result = 10, change to 0
$last_text = $this->text;
$this->checksumValue = array();
for ($i = 0; $i < $this->checksum; $i++) {
$new_text = '';
$new_number = 0;
$c = strlen($last_text);
if ($c % 2 === 0) { // Even
$starting = 1;
} else {
$starting = 0;
}
for ($j = $starting; $j < $c; $j += 2) {
$new_text .= $last_text[$j];
}
$new_text = strval(intval($new_text) * 2);
$c2 = strlen($new_text);
for ($j = 0; $j < $c2; $j++) {
$new_number += intval($new_text[$j]);
}
for ($j = ($starting === 0) ? 1 : 0; $j < $c; $j += 2) {
$new_number += intval($last_text[$j]);
}
$new_number = (10 - $new_number % 10) % 10;
$this->checksumValue[] = $new_number;
$last_text .= $new_number;
}
} | php | protected function calculateChecksum() {
// Forming a new number
// If the original number is even, we take all even position
// If the original number is odd, we take all odd position
// 123456 = 246
// 12345 = 135
// Multiply by 2
// Add up all the digit in the result (270 : 2+7+0)
// Add up other digit not used.
// 10 - (? Modulo 10). If result = 10, change to 0
$last_text = $this->text;
$this->checksumValue = array();
for ($i = 0; $i < $this->checksum; $i++) {
$new_text = '';
$new_number = 0;
$c = strlen($last_text);
if ($c % 2 === 0) { // Even
$starting = 1;
} else {
$starting = 0;
}
for ($j = $starting; $j < $c; $j += 2) {
$new_text .= $last_text[$j];
}
$new_text = strval(intval($new_text) * 2);
$c2 = strlen($new_text);
for ($j = 0; $j < $c2; $j++) {
$new_number += intval($new_text[$j]);
}
for ($j = ($starting === 0) ? 1 : 0; $j < $c; $j += 2) {
$new_number += intval($last_text[$j]);
}
$new_number = (10 - $new_number % 10) % 10;
$this->checksumValue[] = $new_number;
$last_text .= $new_number;
}
} | [
"protected",
"function",
"calculateChecksum",
"(",
")",
"{",
"// Forming a new number\r",
"// If the original number is even, we take all even position\r",
"// If the original number is odd, we take all odd position\r",
"// 123456 = 246\r",
"// 12345 = 135\r",
"// Multiply by 2\r",
"// Add up all the digit in the result (270 : 2+7+0)\r",
"// Add up other digit not used.\r",
"// 10 - (? Modulo 10). If result = 10, change to 0\r",
"$",
"last_text",
"=",
"$",
"this",
"->",
"text",
";",
"$",
"this",
"->",
"checksumValue",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"checksum",
";",
"$",
"i",
"++",
")",
"{",
"$",
"new_text",
"=",
"''",
";",
"$",
"new_number",
"=",
"0",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"last_text",
")",
";",
"if",
"(",
"$",
"c",
"%",
"2",
"===",
"0",
")",
"{",
"// Even\r",
"$",
"starting",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"starting",
"=",
"0",
";",
"}",
"for",
"(",
"$",
"j",
"=",
"$",
"starting",
";",
"$",
"j",
"<",
"$",
"c",
";",
"$",
"j",
"+=",
"2",
")",
"{",
"$",
"new_text",
".=",
"$",
"last_text",
"[",
"$",
"j",
"]",
";",
"}",
"$",
"new_text",
"=",
"strval",
"(",
"intval",
"(",
"$",
"new_text",
")",
"*",
"2",
")",
";",
"$",
"c2",
"=",
"strlen",
"(",
"$",
"new_text",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"c2",
";",
"$",
"j",
"++",
")",
"{",
"$",
"new_number",
"+=",
"intval",
"(",
"$",
"new_text",
"[",
"$",
"j",
"]",
")",
";",
"}",
"for",
"(",
"$",
"j",
"=",
"(",
"$",
"starting",
"===",
"0",
")",
"?",
"1",
":",
"0",
";",
"$",
"j",
"<",
"$",
"c",
";",
"$",
"j",
"+=",
"2",
")",
"{",
"$",
"new_number",
"+=",
"intval",
"(",
"$",
"last_text",
"[",
"$",
"j",
"]",
")",
";",
"}",
"$",
"new_number",
"=",
"(",
"10",
"-",
"$",
"new_number",
"%",
"10",
")",
"%",
"10",
";",
"$",
"this",
"->",
"checksumValue",
"[",
"]",
"=",
"$",
"new_number",
";",
"$",
"last_text",
".=",
"$",
"new_number",
";",
"}",
"}"
] | Overloaded method to calculate checksum. | [
"Overloaded",
"method",
"to",
"calculate",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINmsi.php#L123-L163 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.parse | public function parse($text) {
$parsedText = $this->parseGs1128($text);
if($this->customLabelText!==false and CINBarcode1D::AUTO_LABEL!=$this->customLabelText){
parent::setLabel($this->customLabelText);
}
parent::parse($parsedText);
} | php | public function parse($text) {
$parsedText = $this->parseGs1128($text);
if($this->customLabelText!==false and CINBarcode1D::AUTO_LABEL!=$this->customLabelText){
parent::setLabel($this->customLabelText);
}
parent::parse($parsedText);
} | [
"public",
"function",
"parse",
"(",
"$",
"text",
")",
"{",
"$",
"parsedText",
"=",
"$",
"this",
"->",
"parseGs1128",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"this",
"->",
"customLabelText",
"!==",
"false",
"and",
"CINBarcode1D",
"::",
"AUTO_LABEL",
"!=",
"$",
"this",
"->",
"customLabelText",
")",
"{",
"parent",
"::",
"setLabel",
"(",
"$",
"this",
"->",
"customLabelText",
")",
";",
"}",
"parent",
"::",
"parse",
"(",
"$",
"parsedText",
")",
";",
"}"
] | Parses Text.
@param string $text | [
"Parses",
"Text",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L249-L255 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.formatGs1128 | private function formatGs1128() {
$formatedText = '~F1';
$formatedLabel = '';
$c = count($this->identifiersId);
for ($i = 0; $i < $c; $i++) {
if ($i > 0) {
$formatedLabel .= ' ';
}
if ($this->identifiersId[$i] !== null) {
$formatedLabel .= '(' . $this->identifiersId[$i] . ')';
}
$formatedText .= $this->identifiersId[$i];
$formatedLabel .= $this->identifiersContent[$i];
$formatedText .= $this->identifiersContent[$i];
if (isset($this->identifiersAi[$this->identifiersId[$i]])) {
$ai_data = $this->identifiersAi[$this->identifiersId[$i]];
} elseif (isset($this->identifiersId[$i][3])) {
$identifierWithVar = substr($this->identifiersId[$i], 0, -1) . 'y';
$ai_data = isset($this->identifiersAi[$identifierWithVar]) ? $this->identifiersAi[$identifierWithVar] : null;
} else {
$ai_data = null;
}
/* We'll check if we need to add a ~F1 (<GS>) char */
/* If we use the legacy mode, we always add a ~F1 (<GS>) char between AIs */
if ($ai_data !== null) {
if ((strlen($this->identifiersContent[$i]) < $ai_data[self::MAXLENGTH] && ($i + 1) !== $c) || (!$this->strictMode && ($i + 1) !== $c)) {
$formatedText .= '~F1';
}
} elseif ($this->allowsUnknownIdentifier && $this->identifiersId[$i] === null && ($i + 1) !== $c) {
/* If this id is unknown, we add a ~F1 (<GS>) char */
$formatedText .= '~F1';
}
}
if ($this->noLengthLimit === false && (strlen(str_replace('~F1', chr(29), $formatedText)) - 1) > self::MAX_GS1128_CHARS) {
throw new CINParseException('gs1128', 'The barcode can\'t contain more than ' . self::MAX_GS1128_CHARS . ' characters.');
}
$this->label = $formatedLabel;
return $formatedText;
} | php | private function formatGs1128() {
$formatedText = '~F1';
$formatedLabel = '';
$c = count($this->identifiersId);
for ($i = 0; $i < $c; $i++) {
if ($i > 0) {
$formatedLabel .= ' ';
}
if ($this->identifiersId[$i] !== null) {
$formatedLabel .= '(' . $this->identifiersId[$i] . ')';
}
$formatedText .= $this->identifiersId[$i];
$formatedLabel .= $this->identifiersContent[$i];
$formatedText .= $this->identifiersContent[$i];
if (isset($this->identifiersAi[$this->identifiersId[$i]])) {
$ai_data = $this->identifiersAi[$this->identifiersId[$i]];
} elseif (isset($this->identifiersId[$i][3])) {
$identifierWithVar = substr($this->identifiersId[$i], 0, -1) . 'y';
$ai_data = isset($this->identifiersAi[$identifierWithVar]) ? $this->identifiersAi[$identifierWithVar] : null;
} else {
$ai_data = null;
}
/* We'll check if we need to add a ~F1 (<GS>) char */
/* If we use the legacy mode, we always add a ~F1 (<GS>) char between AIs */
if ($ai_data !== null) {
if ((strlen($this->identifiersContent[$i]) < $ai_data[self::MAXLENGTH] && ($i + 1) !== $c) || (!$this->strictMode && ($i + 1) !== $c)) {
$formatedText .= '~F1';
}
} elseif ($this->allowsUnknownIdentifier && $this->identifiersId[$i] === null && ($i + 1) !== $c) {
/* If this id is unknown, we add a ~F1 (<GS>) char */
$formatedText .= '~F1';
}
}
if ($this->noLengthLimit === false && (strlen(str_replace('~F1', chr(29), $formatedText)) - 1) > self::MAX_GS1128_CHARS) {
throw new CINParseException('gs1128', 'The barcode can\'t contain more than ' . self::MAX_GS1128_CHARS . ' characters.');
}
$this->label = $formatedLabel;
return $formatedText;
} | [
"private",
"function",
"formatGs1128",
"(",
")",
"{",
"$",
"formatedText",
"=",
"'~F1'",
";",
"$",
"formatedLabel",
"=",
"''",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"this",
"->",
"identifiersId",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"formatedLabel",
".=",
"' '",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
"!==",
"null",
")",
"{",
"$",
"formatedLabel",
".=",
"'('",
".",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
".",
"')'",
";",
"}",
"$",
"formatedText",
".=",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
";",
"$",
"formatedLabel",
".=",
"$",
"this",
"->",
"identifiersContent",
"[",
"$",
"i",
"]",
";",
"$",
"formatedText",
".=",
"$",
"this",
"->",
"identifiersContent",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"ai_data",
"=",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
"[",
"3",
"]",
")",
")",
"{",
"$",
"identifierWithVar",
"=",
"substr",
"(",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
",",
"0",
",",
"-",
"1",
")",
".",
"'y'",
";",
"$",
"ai_data",
"=",
"isset",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"identifierWithVar",
"]",
")",
"?",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"identifierWithVar",
"]",
":",
"null",
";",
"}",
"else",
"{",
"$",
"ai_data",
"=",
"null",
";",
"}",
"/* We'll check if we need to add a ~F1 (<GS>) char */",
"/* If we use the legacy mode, we always add a ~F1 (<GS>) char between AIs */",
"if",
"(",
"$",
"ai_data",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"strlen",
"(",
"$",
"this",
"->",
"identifiersContent",
"[",
"$",
"i",
"]",
")",
"<",
"$",
"ai_data",
"[",
"self",
"::",
"MAXLENGTH",
"]",
"&&",
"(",
"$",
"i",
"+",
"1",
")",
"!==",
"$",
"c",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"strictMode",
"&&",
"(",
"$",
"i",
"+",
"1",
")",
"!==",
"$",
"c",
")",
")",
"{",
"$",
"formatedText",
".=",
"'~F1'",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"allowsUnknownIdentifier",
"&&",
"$",
"this",
"->",
"identifiersId",
"[",
"$",
"i",
"]",
"===",
"null",
"&&",
"(",
"$",
"i",
"+",
"1",
")",
"!==",
"$",
"c",
")",
"{",
"/* If this id is unknown, we add a ~F1 (<GS>) char */",
"$",
"formatedText",
".=",
"'~F1'",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"noLengthLimit",
"===",
"false",
"&&",
"(",
"strlen",
"(",
"str_replace",
"(",
"'~F1'",
",",
"chr",
"(",
"29",
")",
",",
"$",
"formatedText",
")",
")",
"-",
"1",
")",
">",
"self",
"::",
"MAX_GS1128_CHARS",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The barcode can\\'t contain more than '",
".",
"self",
"::",
"MAX_GS1128_CHARS",
".",
"' characters.'",
")",
";",
"}",
"$",
"this",
"->",
"label",
"=",
"$",
"formatedLabel",
";",
"return",
"$",
"formatedText",
";",
"}"
] | Formats data for gs1-128.
@return string | [
"Formats",
"data",
"for",
"gs1",
"-",
"128",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L262-L308 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.parseGs1128 | private function parseGs1128($text) {
/* We format correctly what the user gives */
if (is_array($text)) {
$formatArray = array();
foreach ($text as $content) {
if (is_array($content)) { /* double array */
if (count($content) === 2) {
if (is_array($content[self::ID]) || is_array($content[self::CONTENT])) {
throw new CINParseException('gs1128', 'Double arrays can\'t contain arrays.');
} else {
$formatArray[] = '(' . $content[self::ID] . ')' . $content[self::CONTENT];
}
} else {
throw new CINParseException('gs1128', 'Double arrays must contain 2 values.');
}
} else { /* simple array */
$formatArray[] = $content;
}
}
unset($text);
$text = $formatArray;
} else { /* string */
$text = array($text);
}
$textCount = count($text);
for ($cmpt = 0; $cmpt < $textCount; $cmpt++) {
/* We parse the content of the array */
if (!$this->parseContent($text[$cmpt])) {
return;
}
}
return $this->formatGs1128();
} | php | private function parseGs1128($text) {
/* We format correctly what the user gives */
if (is_array($text)) {
$formatArray = array();
foreach ($text as $content) {
if (is_array($content)) { /* double array */
if (count($content) === 2) {
if (is_array($content[self::ID]) || is_array($content[self::CONTENT])) {
throw new CINParseException('gs1128', 'Double arrays can\'t contain arrays.');
} else {
$formatArray[] = '(' . $content[self::ID] . ')' . $content[self::CONTENT];
}
} else {
throw new CINParseException('gs1128', 'Double arrays must contain 2 values.');
}
} else { /* simple array */
$formatArray[] = $content;
}
}
unset($text);
$text = $formatArray;
} else { /* string */
$text = array($text);
}
$textCount = count($text);
for ($cmpt = 0; $cmpt < $textCount; $cmpt++) {
/* We parse the content of the array */
if (!$this->parseContent($text[$cmpt])) {
return;
}
}
return $this->formatGs1128();
} | [
"private",
"function",
"parseGs1128",
"(",
"$",
"text",
")",
"{",
"/* We format correctly what the user gives */",
"if",
"(",
"is_array",
"(",
"$",
"text",
")",
")",
"{",
"$",
"formatArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"text",
"as",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"/* double array */",
"if",
"(",
"count",
"(",
"$",
"content",
")",
"===",
"2",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
"[",
"self",
"::",
"ID",
"]",
")",
"||",
"is_array",
"(",
"$",
"content",
"[",
"self",
"::",
"CONTENT",
"]",
")",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'Double arrays can\\'t contain arrays.'",
")",
";",
"}",
"else",
"{",
"$",
"formatArray",
"[",
"]",
"=",
"'('",
".",
"$",
"content",
"[",
"self",
"::",
"ID",
"]",
".",
"')'",
".",
"$",
"content",
"[",
"self",
"::",
"CONTENT",
"]",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'Double arrays must contain 2 values.'",
")",
";",
"}",
"}",
"else",
"{",
"/* simple array */",
"$",
"formatArray",
"[",
"]",
"=",
"$",
"content",
";",
"}",
"}",
"unset",
"(",
"$",
"text",
")",
";",
"$",
"text",
"=",
"$",
"formatArray",
";",
"}",
"else",
"{",
"/* string */",
"$",
"text",
"=",
"array",
"(",
"$",
"text",
")",
";",
"}",
"$",
"textCount",
"=",
"count",
"(",
"$",
"text",
")",
";",
"for",
"(",
"$",
"cmpt",
"=",
"0",
";",
"$",
"cmpt",
"<",
"$",
"textCount",
";",
"$",
"cmpt",
"++",
")",
"{",
"/* We parse the content of the array */",
"if",
"(",
"!",
"$",
"this",
"->",
"parseContent",
"(",
"$",
"text",
"[",
"$",
"cmpt",
"]",
")",
")",
"{",
"return",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"formatGs1128",
"(",
")",
";",
"}"
] | Parses the text to gs1-128.
@param mixed $text
@return mixed | [
"Parses",
"the",
"text",
"to",
"gs1",
"-",
"128",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L316-L351 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.parseContent | private function parseContent($text) {
/* $yAlreadySet has 3 states: */
/* null: There is no variable in the ID; true: the variable is already set; false: the variable is not set yet; */
$content = null;
$yAlreadySet = null;
$realNameId = null;
$separatorsFound = 0;
$checksumAdded = 0;
$decimalPointRemoved = 0;
$toParse = str_replace('~F1', chr(29), $text);
$nbCharToParse = strlen($toParse);
$nbCharId = 0;
$isFormated = $toParse[0] === '(' ? true : false;
$maxCharId = $isFormated ? self::MAX_ID_FORMATED : self::MAX_ID_NOT_FORMATED;
$id = strtolower(substr($toParse, 0, min($maxCharId, $nbCharToParse)));
$id = $isFormated ? $this->findIdFormated($id, $yAlreadySet, $realNameId) : $this->findIdNotFormated($id, $yAlreadySet, $realNameId);
if ($id === false) {
if ($this->allowsUnknownIdentifier === false) {
return false;
}
$id = null;
$nbCharId = 0;
$content = $toParse;
} else {
$nbCharId = strlen($id) + ($isFormated ? 2 : 0);
$n = min($this->identifiersAi[$realNameId][self::MAXLENGTH], $nbCharToParse);
$content = substr($toParse, $nbCharId, $n);
}
if ($id !== null) {
/* If we have an AI with an "y" var, we check if there is a decimal point in the next *MAXLENGTH* characters */
/* if there is one, we take an extra character */
if ($yAlreadySet !== null) {
if (strpos($content, '.') !== false || strpos($content, ',') !== false) {
$n++;
if ($n <= $nbCharToParse) {
/* We take an extra char */
$content = substr($toParse, $nbCharId, $n);
}
}
}
}
/* We check for separator */
$separator = strpos($content, chr(29));
if ($separator !== false) {
$content = substr($content, 0, $separator);
$separatorsFound++;
}
if ($id !== null) {
/* We check the conformity */
if (!$this->checkConformity($content, $id, $realNameId)) {
return false;
}
/* We check the checksum */
if (!$this->checkChecksum($content, $id, $realNameId, $checksumAdded)) {
return false;
}
/* We check the vars */
if (!$this->checkVars($content, $id, $yAlreadySet, $decimalPointRemoved)) {
return false;
}
}
$this->identifiersId[] = $id;
$this->identifiersContent[] = $content;
$nbCharLastContent = (((strlen($content) + $nbCharId) - $checksumAdded) + $decimalPointRemoved) + $separatorsFound;
if ($nbCharToParse - $nbCharLastContent > 0) {
/* If there is more than one content in this array, we parse again */
$otherContent = substr($toParse, $nbCharLastContent, $nbCharToParse);
$nbCharOtherContent = strlen($otherContent);
if ($otherContent[0] === chr(29)) {
$otherContent = substr($otherContent, 1);
$nbCharOtherContent--;
}
if ($nbCharOtherContent > 0) {
$text = $otherContent;
return $this->parseContent($text);
}
}
return true;
} | php | private function parseContent($text) {
/* $yAlreadySet has 3 states: */
/* null: There is no variable in the ID; true: the variable is already set; false: the variable is not set yet; */
$content = null;
$yAlreadySet = null;
$realNameId = null;
$separatorsFound = 0;
$checksumAdded = 0;
$decimalPointRemoved = 0;
$toParse = str_replace('~F1', chr(29), $text);
$nbCharToParse = strlen($toParse);
$nbCharId = 0;
$isFormated = $toParse[0] === '(' ? true : false;
$maxCharId = $isFormated ? self::MAX_ID_FORMATED : self::MAX_ID_NOT_FORMATED;
$id = strtolower(substr($toParse, 0, min($maxCharId, $nbCharToParse)));
$id = $isFormated ? $this->findIdFormated($id, $yAlreadySet, $realNameId) : $this->findIdNotFormated($id, $yAlreadySet, $realNameId);
if ($id === false) {
if ($this->allowsUnknownIdentifier === false) {
return false;
}
$id = null;
$nbCharId = 0;
$content = $toParse;
} else {
$nbCharId = strlen($id) + ($isFormated ? 2 : 0);
$n = min($this->identifiersAi[$realNameId][self::MAXLENGTH], $nbCharToParse);
$content = substr($toParse, $nbCharId, $n);
}
if ($id !== null) {
/* If we have an AI with an "y" var, we check if there is a decimal point in the next *MAXLENGTH* characters */
/* if there is one, we take an extra character */
if ($yAlreadySet !== null) {
if (strpos($content, '.') !== false || strpos($content, ',') !== false) {
$n++;
if ($n <= $nbCharToParse) {
/* We take an extra char */
$content = substr($toParse, $nbCharId, $n);
}
}
}
}
/* We check for separator */
$separator = strpos($content, chr(29));
if ($separator !== false) {
$content = substr($content, 0, $separator);
$separatorsFound++;
}
if ($id !== null) {
/* We check the conformity */
if (!$this->checkConformity($content, $id, $realNameId)) {
return false;
}
/* We check the checksum */
if (!$this->checkChecksum($content, $id, $realNameId, $checksumAdded)) {
return false;
}
/* We check the vars */
if (!$this->checkVars($content, $id, $yAlreadySet, $decimalPointRemoved)) {
return false;
}
}
$this->identifiersId[] = $id;
$this->identifiersContent[] = $content;
$nbCharLastContent = (((strlen($content) + $nbCharId) - $checksumAdded) + $decimalPointRemoved) + $separatorsFound;
if ($nbCharToParse - $nbCharLastContent > 0) {
/* If there is more than one content in this array, we parse again */
$otherContent = substr($toParse, $nbCharLastContent, $nbCharToParse);
$nbCharOtherContent = strlen($otherContent);
if ($otherContent[0] === chr(29)) {
$otherContent = substr($otherContent, 1);
$nbCharOtherContent--;
}
if ($nbCharOtherContent > 0) {
$text = $otherContent;
return $this->parseContent($text);
}
}
return true;
} | [
"private",
"function",
"parseContent",
"(",
"$",
"text",
")",
"{",
"/* $yAlreadySet has 3 states: */",
"/* null: There is no variable in the ID; true: the variable is already set; false: the variable is not set yet; */",
"$",
"content",
"=",
"null",
";",
"$",
"yAlreadySet",
"=",
"null",
";",
"$",
"realNameId",
"=",
"null",
";",
"$",
"separatorsFound",
"=",
"0",
";",
"$",
"checksumAdded",
"=",
"0",
";",
"$",
"decimalPointRemoved",
"=",
"0",
";",
"$",
"toParse",
"=",
"str_replace",
"(",
"'~F1'",
",",
"chr",
"(",
"29",
")",
",",
"$",
"text",
")",
";",
"$",
"nbCharToParse",
"=",
"strlen",
"(",
"$",
"toParse",
")",
";",
"$",
"nbCharId",
"=",
"0",
";",
"$",
"isFormated",
"=",
"$",
"toParse",
"[",
"0",
"]",
"===",
"'('",
"?",
"true",
":",
"false",
";",
"$",
"maxCharId",
"=",
"$",
"isFormated",
"?",
"self",
"::",
"MAX_ID_FORMATED",
":",
"self",
"::",
"MAX_ID_NOT_FORMATED",
";",
"$",
"id",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"toParse",
",",
"0",
",",
"min",
"(",
"$",
"maxCharId",
",",
"$",
"nbCharToParse",
")",
")",
")",
";",
"$",
"id",
"=",
"$",
"isFormated",
"?",
"$",
"this",
"->",
"findIdFormated",
"(",
"$",
"id",
",",
"$",
"yAlreadySet",
",",
"$",
"realNameId",
")",
":",
"$",
"this",
"->",
"findIdNotFormated",
"(",
"$",
"id",
",",
"$",
"yAlreadySet",
",",
"$",
"realNameId",
")",
";",
"if",
"(",
"$",
"id",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"allowsUnknownIdentifier",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"id",
"=",
"null",
";",
"$",
"nbCharId",
"=",
"0",
";",
"$",
"content",
"=",
"$",
"toParse",
";",
"}",
"else",
"{",
"$",
"nbCharId",
"=",
"strlen",
"(",
"$",
"id",
")",
"+",
"(",
"$",
"isFormated",
"?",
"2",
":",
"0",
")",
";",
"$",
"n",
"=",
"min",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"MAXLENGTH",
"]",
",",
"$",
"nbCharToParse",
")",
";",
"$",
"content",
"=",
"substr",
"(",
"$",
"toParse",
",",
"$",
"nbCharId",
",",
"$",
"n",
")",
";",
"}",
"if",
"(",
"$",
"id",
"!==",
"null",
")",
"{",
"/* If we have an AI with an \"y\" var, we check if there is a decimal point in the next *MAXLENGTH* characters */",
"/* if there is one, we take an extra character */",
"if",
"(",
"$",
"yAlreadySet",
"!==",
"null",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"content",
",",
"'.'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"content",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"n",
"++",
";",
"if",
"(",
"$",
"n",
"<=",
"$",
"nbCharToParse",
")",
"{",
"/* We take an extra char */",
"$",
"content",
"=",
"substr",
"(",
"$",
"toParse",
",",
"$",
"nbCharId",
",",
"$",
"n",
")",
";",
"}",
"}",
"}",
"}",
"/* We check for separator */",
"$",
"separator",
"=",
"strpos",
"(",
"$",
"content",
",",
"chr",
"(",
"29",
")",
")",
";",
"if",
"(",
"$",
"separator",
"!==",
"false",
")",
"{",
"$",
"content",
"=",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"$",
"separator",
")",
";",
"$",
"separatorsFound",
"++",
";",
"}",
"if",
"(",
"$",
"id",
"!==",
"null",
")",
"{",
"/* We check the conformity */",
"if",
"(",
"!",
"$",
"this",
"->",
"checkConformity",
"(",
"$",
"content",
",",
"$",
"id",
",",
"$",
"realNameId",
")",
")",
"{",
"return",
"false",
";",
"}",
"/* We check the checksum */",
"if",
"(",
"!",
"$",
"this",
"->",
"checkChecksum",
"(",
"$",
"content",
",",
"$",
"id",
",",
"$",
"realNameId",
",",
"$",
"checksumAdded",
")",
")",
"{",
"return",
"false",
";",
"}",
"/* We check the vars */",
"if",
"(",
"!",
"$",
"this",
"->",
"checkVars",
"(",
"$",
"content",
",",
"$",
"id",
",",
"$",
"yAlreadySet",
",",
"$",
"decimalPointRemoved",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"identifiersId",
"[",
"]",
"=",
"$",
"id",
";",
"$",
"this",
"->",
"identifiersContent",
"[",
"]",
"=",
"$",
"content",
";",
"$",
"nbCharLastContent",
"=",
"(",
"(",
"(",
"strlen",
"(",
"$",
"content",
")",
"+",
"$",
"nbCharId",
")",
"-",
"$",
"checksumAdded",
")",
"+",
"$",
"decimalPointRemoved",
")",
"+",
"$",
"separatorsFound",
";",
"if",
"(",
"$",
"nbCharToParse",
"-",
"$",
"nbCharLastContent",
">",
"0",
")",
"{",
"/* If there is more than one content in this array, we parse again */",
"$",
"otherContent",
"=",
"substr",
"(",
"$",
"toParse",
",",
"$",
"nbCharLastContent",
",",
"$",
"nbCharToParse",
")",
";",
"$",
"nbCharOtherContent",
"=",
"strlen",
"(",
"$",
"otherContent",
")",
";",
"if",
"(",
"$",
"otherContent",
"[",
"0",
"]",
"===",
"chr",
"(",
"29",
")",
")",
"{",
"$",
"otherContent",
"=",
"substr",
"(",
"$",
"otherContent",
",",
"1",
")",
";",
"$",
"nbCharOtherContent",
"--",
";",
"}",
"if",
"(",
"$",
"nbCharOtherContent",
">",
"0",
")",
"{",
"$",
"text",
"=",
"$",
"otherContent",
";",
"return",
"$",
"this",
"->",
"parseContent",
"(",
"$",
"text",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Splits the id and the content for each application identifiers (AIs).
@param string $text
@param int $cmpt
@return bool | [
"Splits",
"the",
"id",
"and",
"the",
"content",
"for",
"each",
"application",
"identifiers",
"(",
"AIs",
")",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L360-L450 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.idExists | private function idExists($id, &$yAlreadySet, &$realNameId) {
$yFound = isset($id[3]) && $id[3] === 'y';
$idVarAdded = substr($id, 0, -1) . 'y';
if (isset($this->identifiersAi[$id])) {
if ($yFound) {
$yAlreadySet = false;
}
$realNameId = $id;
return true;
} elseif (!$yFound && isset($this->identifiersAi[$idVarAdded])) {
/* if the id don't exist, we try to find this id with "y" at the last char */
$yAlreadySet = true;
$realNameId = $idVarAdded;
return true;
}
return false;
} | php | private function idExists($id, &$yAlreadySet, &$realNameId) {
$yFound = isset($id[3]) && $id[3] === 'y';
$idVarAdded = substr($id, 0, -1) . 'y';
if (isset($this->identifiersAi[$id])) {
if ($yFound) {
$yAlreadySet = false;
}
$realNameId = $id;
return true;
} elseif (!$yFound && isset($this->identifiersAi[$idVarAdded])) {
/* if the id don't exist, we try to find this id with "y" at the last char */
$yAlreadySet = true;
$realNameId = $idVarAdded;
return true;
}
return false;
} | [
"private",
"function",
"idExists",
"(",
"$",
"id",
",",
"&",
"$",
"yAlreadySet",
",",
"&",
"$",
"realNameId",
")",
"{",
"$",
"yFound",
"=",
"isset",
"(",
"$",
"id",
"[",
"3",
"]",
")",
"&&",
"$",
"id",
"[",
"3",
"]",
"===",
"'y'",
";",
"$",
"idVarAdded",
"=",
"substr",
"(",
"$",
"id",
",",
"0",
",",
"-",
"1",
")",
".",
"'y'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"id",
"]",
")",
")",
"{",
"if",
"(",
"$",
"yFound",
")",
"{",
"$",
"yAlreadySet",
"=",
"false",
";",
"}",
"$",
"realNameId",
"=",
"$",
"id",
";",
"return",
"true",
";",
"}",
"elseif",
"(",
"!",
"$",
"yFound",
"&&",
"isset",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"idVarAdded",
"]",
")",
")",
"{",
"/* if the id don't exist, we try to find this id with \"y\" at the last char */",
"$",
"yAlreadySet",
"=",
"true",
";",
"$",
"realNameId",
"=",
"$",
"idVarAdded",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if an id exists.
@param string $id
@param bool $yAlreadySet
@param string $realNameId
@return bool | [
"Checks",
"if",
"an",
"id",
"exists",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L460-L479 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.findIdFormated | private function findIdFormated($id, &$yAlreadySet, &$realNameId) {
$pos = strpos($id, ')');
if ($pos === false) {
throw new CINParseException('gs1128', 'Identifiers must have no more than 4 characters.');
} else {
if ($pos < 3) {
throw new CINParseException('gs1128', 'Identifiers must have at least 2 characters.');
}
$id = substr($id, 1, $pos - 1);
if ($this->idExists($id, $yAlreadySet, $realNameId)) {
return $id;
}
if ($this->allowsUnknownIdentifier === false) {
throw new CINParseException('gs1128', 'The identifier ' . $id . ' doesn\'t exist.');
}
return false;
}
} | php | private function findIdFormated($id, &$yAlreadySet, &$realNameId) {
$pos = strpos($id, ')');
if ($pos === false) {
throw new CINParseException('gs1128', 'Identifiers must have no more than 4 characters.');
} else {
if ($pos < 3) {
throw new CINParseException('gs1128', 'Identifiers must have at least 2 characters.');
}
$id = substr($id, 1, $pos - 1);
if ($this->idExists($id, $yAlreadySet, $realNameId)) {
return $id;
}
if ($this->allowsUnknownIdentifier === false) {
throw new CINParseException('gs1128', 'The identifier ' . $id . ' doesn\'t exist.');
}
return false;
}
} | [
"private",
"function",
"findIdFormated",
"(",
"$",
"id",
",",
"&",
"$",
"yAlreadySet",
",",
"&",
"$",
"realNameId",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"id",
",",
"')'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'Identifiers must have no more than 4 characters.'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"pos",
"<",
"3",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'Identifiers must have at least 2 characters.'",
")",
";",
"}",
"$",
"id",
"=",
"substr",
"(",
"$",
"id",
",",
"1",
",",
"$",
"pos",
"-",
"1",
")",
";",
"if",
"(",
"$",
"this",
"->",
"idExists",
"(",
"$",
"id",
",",
"$",
"yAlreadySet",
",",
"$",
"realNameId",
")",
")",
"{",
"return",
"$",
"id",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"allowsUnknownIdentifier",
"===",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The identifier '",
".",
"$",
"id",
".",
"' doesn\\'t exist.'",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] | Finds ID with formated content.
@param string $id
@param bool $yAlreadySet
@param string $realNameId
@return mixed | [
"Finds",
"ID",
"with",
"formated",
"content",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L489-L509 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.findIdNotFormated | private function findIdNotFormated($id, &$yAlreadySet, &$realNameId) {
$tofind = $id;
while (strlen($tofind) >= 2) {
if ($this->idExists($tofind, $yAlreadySet, $realNameId)) {
return $tofind;
} else {
$tofind = substr($tofind, 0, -1);
}
}
if ($this->allowsUnknownIdentifier === false) {
throw new CINParseException('gs1128', 'Error in formatting, can\'t find an identifier.');
}
return false;
} | php | private function findIdNotFormated($id, &$yAlreadySet, &$realNameId) {
$tofind = $id;
while (strlen($tofind) >= 2) {
if ($this->idExists($tofind, $yAlreadySet, $realNameId)) {
return $tofind;
} else {
$tofind = substr($tofind, 0, -1);
}
}
if ($this->allowsUnknownIdentifier === false) {
throw new CINParseException('gs1128', 'Error in formatting, can\'t find an identifier.');
}
return false;
} | [
"private",
"function",
"findIdNotFormated",
"(",
"$",
"id",
",",
"&",
"$",
"yAlreadySet",
",",
"&",
"$",
"realNameId",
")",
"{",
"$",
"tofind",
"=",
"$",
"id",
";",
"while",
"(",
"strlen",
"(",
"$",
"tofind",
")",
">=",
"2",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"idExists",
"(",
"$",
"tofind",
",",
"$",
"yAlreadySet",
",",
"$",
"realNameId",
")",
")",
"{",
"return",
"$",
"tofind",
";",
"}",
"else",
"{",
"$",
"tofind",
"=",
"substr",
"(",
"$",
"tofind",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"allowsUnknownIdentifier",
"===",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'Error in formatting, can\\'t find an identifier.'",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Finds ID with non-formated content.
@param string $id
@param bool $yAlreadySet
@param string $realNameId
@return mixed | [
"Finds",
"ID",
"with",
"non",
"-",
"formated",
"content",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L519-L535 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.checkConformity | private function checkConformity(&$content, $id, $realNameId) {
switch ($this->identifiersAi[$realNameId][self::KIND_OF_DATA]) {
case self::NUMERIC:
$content = str_replace(',', '.', $content);
if (!preg_match("/^[0-9.]+$/", $content)) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must be numerical.');
}
break;
case self::DATE_YYMMDD:
$valid_date = true;
if (preg_match("/^[0-9]{6}$/", $content)) {
$year = substr($content, 0, 2);
$month = substr($content, 2, 2);
$day = substr($content, 4, 2);
/* day can be 00 if we only need month and year */
if (intval($month) < 1 || intval($month) > 12 || intval($day) < 0 || intval($day) > 31) {
$valid_date = false;
}
} else {
$valid_date = false;
}
if (!$valid_date) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must be in YYMMDD format.');
}
break;
}
// We check the length of the content
$nbCharContent = strlen($content);
$checksumChar = 0;
$minlengthContent = $this->identifiersAi[$realNameId][self::MINLENGTH];
$maxlengthContent = $this->identifiersAi[$realNameId][self::MAXLENGTH];
if ($this->identifiersAi[$realNameId][self::CHECKSUM]) {
$checksumChar++;
}
if ($nbCharContent < ($minlengthContent - $checksumChar)) {
if ($minlengthContent === $maxlengthContent) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must contain ' . $minlengthContent . ' character(s).');
} else {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must contain between ' . $minlengthContent . ' and ' . $maxlengthContent . ' character(s).');
}
}
return true;
} | php | private function checkConformity(&$content, $id, $realNameId) {
switch ($this->identifiersAi[$realNameId][self::KIND_OF_DATA]) {
case self::NUMERIC:
$content = str_replace(',', '.', $content);
if (!preg_match("/^[0-9.]+$/", $content)) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must be numerical.');
}
break;
case self::DATE_YYMMDD:
$valid_date = true;
if (preg_match("/^[0-9]{6}$/", $content)) {
$year = substr($content, 0, 2);
$month = substr($content, 2, 2);
$day = substr($content, 4, 2);
/* day can be 00 if we only need month and year */
if (intval($month) < 1 || intval($month) > 12 || intval($day) < 0 || intval($day) > 31) {
$valid_date = false;
}
} else {
$valid_date = false;
}
if (!$valid_date) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must be in YYMMDD format.');
}
break;
}
// We check the length of the content
$nbCharContent = strlen($content);
$checksumChar = 0;
$minlengthContent = $this->identifiersAi[$realNameId][self::MINLENGTH];
$maxlengthContent = $this->identifiersAi[$realNameId][self::MAXLENGTH];
if ($this->identifiersAi[$realNameId][self::CHECKSUM]) {
$checksumChar++;
}
if ($nbCharContent < ($minlengthContent - $checksumChar)) {
if ($minlengthContent === $maxlengthContent) {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must contain ' . $minlengthContent . ' character(s).');
} else {
throw new CINParseException('gs1128', 'The value of "' . $id . '" must contain between ' . $minlengthContent . ' and ' . $maxlengthContent . ' character(s).');
}
}
return true;
} | [
"private",
"function",
"checkConformity",
"(",
"&",
"$",
"content",
",",
"$",
"id",
",",
"$",
"realNameId",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"KIND_OF_DATA",
"]",
")",
"{",
"case",
"self",
"::",
"NUMERIC",
":",
"$",
"content",
"=",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"content",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^[0-9.]+$/\"",
",",
"$",
"content",
")",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The value of \"'",
".",
"$",
"id",
".",
"'\" must be numerical.'",
")",
";",
"}",
"break",
";",
"case",
"self",
"::",
"DATE_YYMMDD",
":",
"$",
"valid_date",
"=",
"true",
";",
"if",
"(",
"preg_match",
"(",
"\"/^[0-9]{6}$/\"",
",",
"$",
"content",
")",
")",
"{",
"$",
"year",
"=",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"2",
")",
";",
"$",
"month",
"=",
"substr",
"(",
"$",
"content",
",",
"2",
",",
"2",
")",
";",
"$",
"day",
"=",
"substr",
"(",
"$",
"content",
",",
"4",
",",
"2",
")",
";",
"/* day can be 00 if we only need month and year */",
"if",
"(",
"intval",
"(",
"$",
"month",
")",
"<",
"1",
"||",
"intval",
"(",
"$",
"month",
")",
">",
"12",
"||",
"intval",
"(",
"$",
"day",
")",
"<",
"0",
"||",
"intval",
"(",
"$",
"day",
")",
">",
"31",
")",
"{",
"$",
"valid_date",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"valid_date",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"valid_date",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The value of \"'",
".",
"$",
"id",
".",
"'\" must be in YYMMDD format.'",
")",
";",
"}",
"break",
";",
"}",
"// We check the length of the content\r",
"$",
"nbCharContent",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"$",
"checksumChar",
"=",
"0",
";",
"$",
"minlengthContent",
"=",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"MINLENGTH",
"]",
";",
"$",
"maxlengthContent",
"=",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"MAXLENGTH",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"CHECKSUM",
"]",
")",
"{",
"$",
"checksumChar",
"++",
";",
"}",
"if",
"(",
"$",
"nbCharContent",
"<",
"(",
"$",
"minlengthContent",
"-",
"$",
"checksumChar",
")",
")",
"{",
"if",
"(",
"$",
"minlengthContent",
"===",
"$",
"maxlengthContent",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The value of \"'",
".",
"$",
"id",
".",
"'\" must contain '",
".",
"$",
"minlengthContent",
".",
"' character(s).'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The value of \"'",
".",
"$",
"id",
".",
"'\" must contain between '",
".",
"$",
"minlengthContent",
".",
"' and '",
".",
"$",
"maxlengthContent",
".",
"' character(s).'",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks confirmity of the content.
@param string $content
@param string $id
@param string $realNameId
@return bool | [
"Checks",
"confirmity",
"of",
"the",
"content",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L545-L595 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.checkChecksum | private function checkChecksum(&$content, $id, $realNameId, &$checksumAdded) {
if ($this->identifiersAi[$realNameId][self::CHECKSUM]) {
$nbCharContent = strlen($content);
$minlengthContent = $this->identifiersAi[$realNameId][self::MINLENGTH];
if ($nbCharContent === ($minlengthContent - 1)) {
/* we need to calculate the checksum */
$content .= self::getAiContentChecksum($content);
$checksumAdded++;
} elseif ($nbCharContent === $minlengthContent) {
/* we need to check the checksum */
$checksum = self::getAiContentChecksum(substr($content, 0, -1));
if (intval($content[$nbCharContent - 1]) !== $checksum) {
throw new CINParseException('gs1128', 'The checksum of "(' . $id . ') ' . $content . '" must be: ' . $checksum);
}
}
}
return true;
} | php | private function checkChecksum(&$content, $id, $realNameId, &$checksumAdded) {
if ($this->identifiersAi[$realNameId][self::CHECKSUM]) {
$nbCharContent = strlen($content);
$minlengthContent = $this->identifiersAi[$realNameId][self::MINLENGTH];
if ($nbCharContent === ($minlengthContent - 1)) {
/* we need to calculate the checksum */
$content .= self::getAiContentChecksum($content);
$checksumAdded++;
} elseif ($nbCharContent === $minlengthContent) {
/* we need to check the checksum */
$checksum = self::getAiContentChecksum(substr($content, 0, -1));
if (intval($content[$nbCharContent - 1]) !== $checksum) {
throw new CINParseException('gs1128', 'The checksum of "(' . $id . ') ' . $content . '" must be: ' . $checksum);
}
}
}
return true;
} | [
"private",
"function",
"checkChecksum",
"(",
"&",
"$",
"content",
",",
"$",
"id",
",",
"$",
"realNameId",
",",
"&",
"$",
"checksumAdded",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"CHECKSUM",
"]",
")",
"{",
"$",
"nbCharContent",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"$",
"minlengthContent",
"=",
"$",
"this",
"->",
"identifiersAi",
"[",
"$",
"realNameId",
"]",
"[",
"self",
"::",
"MINLENGTH",
"]",
";",
"if",
"(",
"$",
"nbCharContent",
"===",
"(",
"$",
"minlengthContent",
"-",
"1",
")",
")",
"{",
"/* we need to calculate the checksum */",
"$",
"content",
".=",
"self",
"::",
"getAiContentChecksum",
"(",
"$",
"content",
")",
";",
"$",
"checksumAdded",
"++",
";",
"}",
"elseif",
"(",
"$",
"nbCharContent",
"===",
"$",
"minlengthContent",
")",
"{",
"/* we need to check the checksum */",
"$",
"checksum",
"=",
"self",
"::",
"getAiContentChecksum",
"(",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"intval",
"(",
"$",
"content",
"[",
"$",
"nbCharContent",
"-",
"1",
"]",
")",
"!==",
"$",
"checksum",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'The checksum of \"('",
".",
"$",
"id",
".",
"') '",
".",
"$",
"content",
".",
"'\" must be: '",
".",
"$",
"checksum",
")",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Verifies the checksum.
@param string $content
@param string $id
@param int $realNameId
@param int $checksumAdded
@return bool | [
"Verifies",
"the",
"checksum",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L606-L624 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.checkVars | private function checkVars(&$content, &$id, $yAlreadySet, &$decimalPointRemoved) {
$nbCharContent = strlen($content);
/* We check for "y" var in AI */
if ($yAlreadySet) {
/* We'll check if we have a decimal point */
if (strpos($content, '.') !== false) {
throw new CINParseException('gs1128', 'If you do not use any "y" variable, you have to insert a whole number.');
}
} elseif ($yAlreadySet !== null) {
/* We need to replace the "y" var with the position of the decimal point */
$pos = strpos($content, '.');
if ($pos === false) {
$pos = $nbCharContent - 1;
}
$id = str_replace('y', $nbCharContent - ($pos + 1), strtolower($id));
$content = str_replace('.', '', $content);
$decimalPointRemoved++;
}
return true;
} | php | private function checkVars(&$content, &$id, $yAlreadySet, &$decimalPointRemoved) {
$nbCharContent = strlen($content);
/* We check for "y" var in AI */
if ($yAlreadySet) {
/* We'll check if we have a decimal point */
if (strpos($content, '.') !== false) {
throw new CINParseException('gs1128', 'If you do not use any "y" variable, you have to insert a whole number.');
}
} elseif ($yAlreadySet !== null) {
/* We need to replace the "y" var with the position of the decimal point */
$pos = strpos($content, '.');
if ($pos === false) {
$pos = $nbCharContent - 1;
}
$id = str_replace('y', $nbCharContent - ($pos + 1), strtolower($id));
$content = str_replace('.', '', $content);
$decimalPointRemoved++;
}
return true;
} | [
"private",
"function",
"checkVars",
"(",
"&",
"$",
"content",
",",
"&",
"$",
"id",
",",
"$",
"yAlreadySet",
",",
"&",
"$",
"decimalPointRemoved",
")",
"{",
"$",
"nbCharContent",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"/* We check for \"y\" var in AI */",
"if",
"(",
"$",
"yAlreadySet",
")",
"{",
"/* We'll check if we have a decimal point */",
"if",
"(",
"strpos",
"(",
"$",
"content",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"CINParseException",
"(",
"'gs1128'",
",",
"'If you do not use any \"y\" variable, you have to insert a whole number.'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"yAlreadySet",
"!==",
"null",
")",
"{",
"/* We need to replace the \"y\" var with the position of the decimal point */",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"content",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"pos",
"=",
"$",
"nbCharContent",
"-",
"1",
";",
"}",
"$",
"id",
"=",
"str_replace",
"(",
"'y'",
",",
"$",
"nbCharContent",
"-",
"(",
"$",
"pos",
"+",
"1",
")",
",",
"strtolower",
"(",
"$",
"id",
")",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"content",
")",
";",
"$",
"decimalPointRemoved",
"++",
";",
"}",
"return",
"true",
";",
"}"
] | Checks vars "y".
@param string $content
@param string $id
@param bool $yAlreadySet
@param int $decimalPointRemoved
@return bool | [
"Checks",
"vars",
"y",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L635-L656 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINgs1128.php | CINgs1128.calculateChecksumMod10 | private static function calculateChecksumMod10($content) {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$checksumValue = 0;
$c = strlen($content);
for ($i = $c; $i > 0; $i--) {
if ($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
$checksumValue += ($content[$i - 1] * $multiplier);
}
return (10 - $checksumValue % 10) % 10;
} | php | private static function calculateChecksumMod10($content) {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$checksumValue = 0;
$c = strlen($content);
for ($i = $c; $i > 0; $i--) {
if ($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
$checksumValue += ($content[$i - 1] * $multiplier);
}
return (10 - $checksumValue % 10) % 10;
} | [
"private",
"static",
"function",
"calculateChecksumMod10",
"(",
"$",
"content",
")",
"{",
"// Calculating Checksum\r",
"// Consider the right-most digit of the message to be in an \"odd\" position,\r",
"// and assign odd/even to each character moving from right to left\r",
"// Odd Position = 3, Even Position = 1\r",
"// Multiply it by the number\r",
"// Add all of that and do 10-(?mod10)\r",
"$",
"odd",
"=",
"true",
";",
"$",
"checksumValue",
"=",
"0",
";",
"$",
"c",
"=",
"strlen",
"(",
"$",
"content",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"c",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"$",
"odd",
"===",
"true",
")",
"{",
"$",
"multiplier",
"=",
"3",
";",
"$",
"odd",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"multiplier",
"=",
"1",
";",
"$",
"odd",
"=",
"true",
";",
"}",
"$",
"checksumValue",
"+=",
"(",
"$",
"content",
"[",
"$",
"i",
"-",
"1",
"]",
"*",
"$",
"multiplier",
")",
";",
"}",
"return",
"(",
"10",
"-",
"$",
"checksumValue",
"%",
"10",
")",
"%",
"10",
";",
"}"
] | Checksum Mod10.
@param int $content
@return int | [
"Checksum",
"Mod10",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINgs1128.php#L664-L688 |
codeitnowin/barcode-generator | CodeItNow/BarcodeBundle/Generator/CINs25.php | CINs25.draw | public function draw($im) {
$temp_text = $this->text;
// Checksum
if ($this->checksum === true) {
$this->calculateChecksum();
$temp_text .= $this->keys[$this->checksumValue];
}
// Starting Code
$this->drawChar($im, '101000', true);
// Chars
$c = strlen($temp_text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Ending Code
$this->drawChar($im, '10001', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | php | public function draw($im) {
$temp_text = $this->text;
// Checksum
if ($this->checksum === true) {
$this->calculateChecksum();
$temp_text .= $this->keys[$this->checksumValue];
}
// Starting Code
$this->drawChar($im, '101000', true);
// Chars
$c = strlen($temp_text);
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Ending Code
$this->drawChar($im, '10001', true);
$this->drawText($im, 0, 0, $this->positionX, $this->thickness);
} | [
"public",
"function",
"draw",
"(",
"$",
"im",
")",
"{",
"$",
"temp_text",
"=",
"$",
"this",
"->",
"text",
";",
"// Checksum\r",
"if",
"(",
"$",
"this",
"->",
"checksum",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"calculateChecksum",
"(",
")",
";",
"$",
"temp_text",
".=",
"$",
"this",
"->",
"keys",
"[",
"$",
"this",
"->",
"checksumValue",
"]",
";",
"}",
"// Starting Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'101000'",
",",
"true",
")",
";",
"// Chars\r",
"$",
"c",
"=",
"strlen",
"(",
"$",
"temp_text",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"findCode",
"(",
"$",
"temp_text",
"[",
"$",
"i",
"]",
")",
",",
"true",
")",
";",
"}",
"// Ending Code\r",
"$",
"this",
"->",
"drawChar",
"(",
"$",
"im",
",",
"'10001'",
",",
"true",
")",
";",
"$",
"this",
"->",
"drawText",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"positionX",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"}"
] | Draws the barcode.
@param resource $im | [
"Draws",
"the",
"barcode",
"."
] | train | https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINs25.php#L58-L79 |
adhocore/php-jwt | src/ValidatesJWT.php | ValidatesJWT.validateConfig | protected function validateConfig($key, $algo, $maxAge, $leeway)
{
if (empty($key)) {
throw new JWTException('Signing key cannot be empty', static::ERROR_KEY_EMPTY);
}
if (!isset($this->algos[$algo])) {
throw new JWTException('Unsupported algo ' . $algo, static::ERROR_ALGO_UNSUPPORTED);
}
if ($maxAge < 1) {
throw new JWTException('Invalid maxAge: Should be greater than 0', static::ERROR_INVALID_MAXAGE);
}
if ($leeway < 0 || $leeway > 120) {
throw new JWTException('Invalid leeway: Should be between 0-120', static::ERROR_INVALID_LEEWAY);
}
} | php | protected function validateConfig($key, $algo, $maxAge, $leeway)
{
if (empty($key)) {
throw new JWTException('Signing key cannot be empty', static::ERROR_KEY_EMPTY);
}
if (!isset($this->algos[$algo])) {
throw new JWTException('Unsupported algo ' . $algo, static::ERROR_ALGO_UNSUPPORTED);
}
if ($maxAge < 1) {
throw new JWTException('Invalid maxAge: Should be greater than 0', static::ERROR_INVALID_MAXAGE);
}
if ($leeway < 0 || $leeway > 120) {
throw new JWTException('Invalid leeway: Should be between 0-120', static::ERROR_INVALID_LEEWAY);
}
} | [
"protected",
"function",
"validateConfig",
"(",
"$",
"key",
",",
"$",
"algo",
",",
"$",
"maxAge",
",",
"$",
"leeway",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Signing key cannot be empty'",
",",
"static",
"::",
"ERROR_KEY_EMPTY",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"algo",
"]",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Unsupported algo '",
".",
"$",
"algo",
",",
"static",
"::",
"ERROR_ALGO_UNSUPPORTED",
")",
";",
"}",
"if",
"(",
"$",
"maxAge",
"<",
"1",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid maxAge: Should be greater than 0'",
",",
"static",
"::",
"ERROR_INVALID_MAXAGE",
")",
";",
"}",
"if",
"(",
"$",
"leeway",
"<",
"0",
"||",
"$",
"leeway",
">",
"120",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid leeway: Should be between 0-120'",
",",
"static",
"::",
"ERROR_INVALID_LEEWAY",
")",
";",
"}",
"}"
] | Throw up if input parameters invalid.
@codeCoverageIgnore | [
"Throw",
"up",
"if",
"input",
"parameters",
"invalid",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/ValidatesJWT.php#L29-L46 |
adhocore/php-jwt | src/ValidatesJWT.php | ValidatesJWT.validateHeader | protected function validateHeader(array $header)
{
if (empty($header['alg'])) {
throw new JWTException('Invalid token: Missing header algo', static::ERROR_ALGO_MISSING);
}
if (empty($this->algos[$header['alg']])) {
throw new JWTException('Invalid token: Unsupported header algo', static::ERROR_ALGO_UNSUPPORTED);
}
$this->validateKid($header);
} | php | protected function validateHeader(array $header)
{
if (empty($header['alg'])) {
throw new JWTException('Invalid token: Missing header algo', static::ERROR_ALGO_MISSING);
}
if (empty($this->algos[$header['alg']])) {
throw new JWTException('Invalid token: Unsupported header algo', static::ERROR_ALGO_UNSUPPORTED);
}
$this->validateKid($header);
} | [
"protected",
"function",
"validateHeader",
"(",
"array",
"$",
"header",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"header",
"[",
"'alg'",
"]",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: Missing header algo'",
",",
"static",
"::",
"ERROR_ALGO_MISSING",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"header",
"[",
"'alg'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: Unsupported header algo'",
",",
"static",
"::",
"ERROR_ALGO_UNSUPPORTED",
")",
";",
"}",
"$",
"this",
"->",
"validateKid",
"(",
"$",
"header",
")",
";",
"}"
] | Throw up if header invalid. | [
"Throw",
"up",
"if",
"header",
"invalid",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/ValidatesJWT.php#L51-L61 |
adhocore/php-jwt | src/ValidatesJWT.php | ValidatesJWT.validateKid | protected function validateKid(array $header)
{
if (!isset($header['kid'])) {
return;
}
if (empty($this->keys[$header['kid']])) {
throw new JWTException('Invalid token: Unknown key ID', static::ERROR_KID_UNKNOWN);
}
$this->key = $this->keys[$header['kid']];
} | php | protected function validateKid(array $header)
{
if (!isset($header['kid'])) {
return;
}
if (empty($this->keys[$header['kid']])) {
throw new JWTException('Invalid token: Unknown key ID', static::ERROR_KID_UNKNOWN);
}
$this->key = $this->keys[$header['kid']];
} | [
"protected",
"function",
"validateKid",
"(",
"array",
"$",
"header",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"header",
"[",
"'kid'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"header",
"[",
"'kid'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: Unknown key ID'",
",",
"static",
"::",
"ERROR_KID_UNKNOWN",
")",
";",
"}",
"$",
"this",
"->",
"key",
"=",
"$",
"this",
"->",
"keys",
"[",
"$",
"header",
"[",
"'kid'",
"]",
"]",
";",
"}"
] | Throw up if kid exists and invalid. | [
"Throw",
"up",
"if",
"kid",
"exists",
"and",
"invalid",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/ValidatesJWT.php#L66-L76 |
adhocore/php-jwt | src/ValidatesJWT.php | ValidatesJWT.validateTimestamps | protected function validateTimestamps(array $payload)
{
$timestamp = $this->timestamp ?: \time();
$checks = [
['exp', $this->leeway /* */ , static::ERROR_TOKEN_EXPIRED, 'Expired'],
['iat', $this->maxAge - $this->leeway, static::ERROR_TOKEN_EXPIRED, 'Expired'],
['nbf', $this->maxAge - $this->leeway, static::ERROR_TOKEN_NOT_NOW, 'Not now'],
];
foreach ($checks as list($key, $offset, $code, $error)) {
if (isset($payload[$key])) {
$offset += $payload[$key];
$fail = $key === 'nbf' ? $timestamp <= $offset : $timestamp >= $offset;
if ($fail) {
throw new JWTException('Invalid token: ' . $error, $code);
}
}
}
} | php | protected function validateTimestamps(array $payload)
{
$timestamp = $this->timestamp ?: \time();
$checks = [
['exp', $this->leeway /* */ , static::ERROR_TOKEN_EXPIRED, 'Expired'],
['iat', $this->maxAge - $this->leeway, static::ERROR_TOKEN_EXPIRED, 'Expired'],
['nbf', $this->maxAge - $this->leeway, static::ERROR_TOKEN_NOT_NOW, 'Not now'],
];
foreach ($checks as list($key, $offset, $code, $error)) {
if (isset($payload[$key])) {
$offset += $payload[$key];
$fail = $key === 'nbf' ? $timestamp <= $offset : $timestamp >= $offset;
if ($fail) {
throw new JWTException('Invalid token: ' . $error, $code);
}
}
}
} | [
"protected",
"function",
"validateTimestamps",
"(",
"array",
"$",
"payload",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"timestamp",
"?",
":",
"\\",
"time",
"(",
")",
";",
"$",
"checks",
"=",
"[",
"[",
"'exp'",
",",
"$",
"this",
"->",
"leeway",
"/* */",
",",
"static",
"::",
"ERROR_TOKEN_EXPIRED",
",",
"'Expired'",
"]",
",",
"[",
"'iat'",
",",
"$",
"this",
"->",
"maxAge",
"-",
"$",
"this",
"->",
"leeway",
",",
"static",
"::",
"ERROR_TOKEN_EXPIRED",
",",
"'Expired'",
"]",
",",
"[",
"'nbf'",
",",
"$",
"this",
"->",
"maxAge",
"-",
"$",
"this",
"->",
"leeway",
",",
"static",
"::",
"ERROR_TOKEN_NOT_NOW",
",",
"'Not now'",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"checks",
"as",
"list",
"(",
"$",
"key",
",",
"$",
"offset",
",",
"$",
"code",
",",
"$",
"error",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"payload",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"offset",
"+=",
"$",
"payload",
"[",
"$",
"key",
"]",
";",
"$",
"fail",
"=",
"$",
"key",
"===",
"'nbf'",
"?",
"$",
"timestamp",
"<=",
"$",
"offset",
":",
"$",
"timestamp",
">=",
"$",
"offset",
";",
"if",
"(",
"$",
"fail",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: '",
".",
"$",
"error",
",",
"$",
"code",
")",
";",
"}",
"}",
"}",
"}"
] | Throw up if timestamp claims like iat, exp, nbf are invalid. | [
"Throw",
"up",
"if",
"timestamp",
"claims",
"like",
"iat",
"exp",
"nbf",
"are",
"invalid",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/ValidatesJWT.php#L81-L100 |
adhocore/php-jwt | src/ValidatesJWT.php | ValidatesJWT.validateKey | protected function validateKey()
{
if (\is_string($key = $this->key)) {
if (\substr($key, 0, 7) !== 'file://') {
$key = 'file://' . $key;
}
$this->key = \openssl_get_privatekey($key, $this->passphrase ?: '');
}
if (!\is_resource($this->key)) {
throw new JWTException('Invalid key: Should be resource of private key', static::ERROR_KEY_INVALID);
}
} | php | protected function validateKey()
{
if (\is_string($key = $this->key)) {
if (\substr($key, 0, 7) !== 'file://') {
$key = 'file://' . $key;
}
$this->key = \openssl_get_privatekey($key, $this->passphrase ?: '');
}
if (!\is_resource($this->key)) {
throw new JWTException('Invalid key: Should be resource of private key', static::ERROR_KEY_INVALID);
}
} | [
"protected",
"function",
"validateKey",
"(",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
")",
")",
"{",
"if",
"(",
"\\",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"7",
")",
"!==",
"'file://'",
")",
"{",
"$",
"key",
"=",
"'file://'",
".",
"$",
"key",
";",
"}",
"$",
"this",
"->",
"key",
"=",
"\\",
"openssl_get_privatekey",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"passphrase",
"?",
":",
"''",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_resource",
"(",
"$",
"this",
"->",
"key",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid key: Should be resource of private key'",
",",
"static",
"::",
"ERROR_KEY_INVALID",
")",
";",
"}",
"}"
] | Throw up if key is not resource or file path to private key. | [
"Throw",
"up",
"if",
"key",
"is",
"not",
"resource",
"or",
"file",
"path",
"to",
"private",
"key",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/ValidatesJWT.php#L105-L118 |
adhocore/php-jwt | src/JWT.php | JWT.encode | public function encode(array $payload, array $header = [])
{
$header = ['typ' => 'JWT', 'alg' => $this->algo] + $header;
$this->validateKid($header);
if (!isset($payload['iat']) && !isset($payload['exp'])) {
$payload['exp'] = ($this->timestamp ?: \time()) + $this->maxAge;
}
$header = $this->urlSafeEncode($header);
$payload = $this->urlSafeEncode($payload);
$signature = $this->urlSafeEncode($this->sign($header . '.' . $payload));
return $header . '.' . $payload . '.' . $signature;
} | php | public function encode(array $payload, array $header = [])
{
$header = ['typ' => 'JWT', 'alg' => $this->algo] + $header;
$this->validateKid($header);
if (!isset($payload['iat']) && !isset($payload['exp'])) {
$payload['exp'] = ($this->timestamp ?: \time()) + $this->maxAge;
}
$header = $this->urlSafeEncode($header);
$payload = $this->urlSafeEncode($payload);
$signature = $this->urlSafeEncode($this->sign($header . '.' . $payload));
return $header . '.' . $payload . '.' . $signature;
} | [
"public",
"function",
"encode",
"(",
"array",
"$",
"payload",
",",
"array",
"$",
"header",
"=",
"[",
"]",
")",
"{",
"$",
"header",
"=",
"[",
"'typ'",
"=>",
"'JWT'",
",",
"'alg'",
"=>",
"$",
"this",
"->",
"algo",
"]",
"+",
"$",
"header",
";",
"$",
"this",
"->",
"validateKid",
"(",
"$",
"header",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"payload",
"[",
"'iat'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"payload",
"[",
"'exp'",
"]",
")",
")",
"{",
"$",
"payload",
"[",
"'exp'",
"]",
"=",
"(",
"$",
"this",
"->",
"timestamp",
"?",
":",
"\\",
"time",
"(",
")",
")",
"+",
"$",
"this",
"->",
"maxAge",
";",
"}",
"$",
"header",
"=",
"$",
"this",
"->",
"urlSafeEncode",
"(",
"$",
"header",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"urlSafeEncode",
"(",
"$",
"payload",
")",
";",
"$",
"signature",
"=",
"$",
"this",
"->",
"urlSafeEncode",
"(",
"$",
"this",
"->",
"sign",
"(",
"$",
"header",
".",
"'.'",
".",
"$",
"payload",
")",
")",
";",
"return",
"$",
"header",
".",
"'.'",
".",
"$",
"payload",
".",
"'.'",
".",
"$",
"signature",
";",
"}"
] | Encode payload as JWT token.
@param array $payload
@param array $header Extra header (if any) to append.
@return string URL safe JWT token. | [
"Encode",
"payload",
"as",
"JWT",
"token",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L118-L133 |
adhocore/php-jwt | src/JWT.php | JWT.decode | public function decode($token)
{
if (\substr_count($token, '.') < 2) {
throw new JWTException('Invalid token: Incomplete segments', static::ERROR_TOKEN_INVALID);
}
$token = \explode('.', $token, 3);
$this->validateHeader((array) $this->urlSafeDecode($token[0]));
// Validate signature.
if (!$this->verify($token[0] . '.' . $token[1], $token[2])) {
throw new JWTException('Invalid token: Signature failed', static::ERROR_SIGNATURE_FAILED);
}
$payload = (array) $this->urlSafeDecode($token[1]);
$this->validateTimestamps($payload);
return $payload;
} | php | public function decode($token)
{
if (\substr_count($token, '.') < 2) {
throw new JWTException('Invalid token: Incomplete segments', static::ERROR_TOKEN_INVALID);
}
$token = \explode('.', $token, 3);
$this->validateHeader((array) $this->urlSafeDecode($token[0]));
// Validate signature.
if (!$this->verify($token[0] . '.' . $token[1], $token[2])) {
throw new JWTException('Invalid token: Signature failed', static::ERROR_SIGNATURE_FAILED);
}
$payload = (array) $this->urlSafeDecode($token[1]);
$this->validateTimestamps($payload);
return $payload;
} | [
"public",
"function",
"decode",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"\\",
"substr_count",
"(",
"$",
"token",
",",
"'.'",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: Incomplete segments'",
",",
"static",
"::",
"ERROR_TOKEN_INVALID",
")",
";",
"}",
"$",
"token",
"=",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"token",
",",
"3",
")",
";",
"$",
"this",
"->",
"validateHeader",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"urlSafeDecode",
"(",
"$",
"token",
"[",
"0",
"]",
")",
")",
";",
"// Validate signature.",
"if",
"(",
"!",
"$",
"this",
"->",
"verify",
"(",
"$",
"token",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"token",
"[",
"1",
"]",
",",
"$",
"token",
"[",
"2",
"]",
")",
")",
"{",
"throw",
"new",
"JWTException",
"(",
"'Invalid token: Signature failed'",
",",
"static",
"::",
"ERROR_SIGNATURE_FAILED",
")",
";",
"}",
"$",
"payload",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"urlSafeDecode",
"(",
"$",
"token",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"validateTimestamps",
"(",
"$",
"payload",
")",
";",
"return",
"$",
"payload",
";",
"}"
] | Decode JWT token and return original payload.
@param string $token
@return array | [
"Decode",
"JWT",
"token",
"and",
"return",
"original",
"payload",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L142-L161 |
adhocore/php-jwt | src/JWT.php | JWT.sign | protected function sign($input)
{
// HMAC SHA.
if (\substr($this->algo, 0, 2) === 'HS') {
return \hash_hmac($this->algos[$this->algo], $input, $this->key, true);
}
$this->validateKey();
\openssl_sign($input, $signature, $this->key, $this->algos[$this->algo]);
return $signature;
} | php | protected function sign($input)
{
// HMAC SHA.
if (\substr($this->algo, 0, 2) === 'HS') {
return \hash_hmac($this->algos[$this->algo], $input, $this->key, true);
}
$this->validateKey();
\openssl_sign($input, $signature, $this->key, $this->algos[$this->algo]);
return $signature;
} | [
"protected",
"function",
"sign",
"(",
"$",
"input",
")",
"{",
"// HMAC SHA.",
"if",
"(",
"\\",
"substr",
"(",
"$",
"this",
"->",
"algo",
",",
"0",
",",
"2",
")",
"===",
"'HS'",
")",
"{",
"return",
"\\",
"hash_hmac",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"this",
"->",
"algo",
"]",
",",
"$",
"input",
",",
"$",
"this",
"->",
"key",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"validateKey",
"(",
")",
";",
"\\",
"openssl_sign",
"(",
"$",
"input",
",",
"$",
"signature",
",",
"$",
"this",
"->",
"key",
",",
"$",
"this",
"->",
"algos",
"[",
"$",
"this",
"->",
"algo",
"]",
")",
";",
"return",
"$",
"signature",
";",
"}"
] | Sign the input with configured key and return the signature.
@param string $input
@return string | [
"Sign",
"the",
"input",
"with",
"configured",
"key",
"and",
"return",
"the",
"signature",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L182-L194 |
adhocore/php-jwt | src/JWT.php | JWT.verify | protected function verify($input, $signature)
{
$algo = $this->algos[$this->algo];
// HMAC SHA.
if (\substr($this->algo, 0, 2) === 'HS') {
return \hash_equals($this->urlSafeEncode(\hash_hmac($algo, $input, $this->key, true)), $signature);
}
$this->validateKey();
$pubKey = \openssl_pkey_get_details($this->key)['key'];
return \openssl_verify($input, $this->urlSafeDecode($signature, false), $pubKey, $algo) === 1;
} | php | protected function verify($input, $signature)
{
$algo = $this->algos[$this->algo];
// HMAC SHA.
if (\substr($this->algo, 0, 2) === 'HS') {
return \hash_equals($this->urlSafeEncode(\hash_hmac($algo, $input, $this->key, true)), $signature);
}
$this->validateKey();
$pubKey = \openssl_pkey_get_details($this->key)['key'];
return \openssl_verify($input, $this->urlSafeDecode($signature, false), $pubKey, $algo) === 1;
} | [
"protected",
"function",
"verify",
"(",
"$",
"input",
",",
"$",
"signature",
")",
"{",
"$",
"algo",
"=",
"$",
"this",
"->",
"algos",
"[",
"$",
"this",
"->",
"algo",
"]",
";",
"// HMAC SHA.",
"if",
"(",
"\\",
"substr",
"(",
"$",
"this",
"->",
"algo",
",",
"0",
",",
"2",
")",
"===",
"'HS'",
")",
"{",
"return",
"\\",
"hash_equals",
"(",
"$",
"this",
"->",
"urlSafeEncode",
"(",
"\\",
"hash_hmac",
"(",
"$",
"algo",
",",
"$",
"input",
",",
"$",
"this",
"->",
"key",
",",
"true",
")",
")",
",",
"$",
"signature",
")",
";",
"}",
"$",
"this",
"->",
"validateKey",
"(",
")",
";",
"$",
"pubKey",
"=",
"\\",
"openssl_pkey_get_details",
"(",
"$",
"this",
"->",
"key",
")",
"[",
"'key'",
"]",
";",
"return",
"\\",
"openssl_verify",
"(",
"$",
"input",
",",
"$",
"this",
"->",
"urlSafeDecode",
"(",
"$",
"signature",
",",
"false",
")",
",",
"$",
"pubKey",
",",
"$",
"algo",
")",
"===",
"1",
";",
"}"
] | Verify the signature of given input.
@param string $input
@param string $signature
@throws JWTException When key is invalid.
@return bool | [
"Verify",
"the",
"signature",
"of",
"given",
"input",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L206-L220 |
adhocore/php-jwt | src/JWT.php | JWT.urlSafeEncode | protected function urlSafeEncode($data)
{
if (\is_array($data)) {
$data = \json_encode($data, \JSON_UNESCAPED_SLASHES);
$this->validateLastJson();
}
return \rtrim(\strtr(\base64_encode($data), '+/', '-_'), '=');
} | php | protected function urlSafeEncode($data)
{
if (\is_array($data)) {
$data = \json_encode($data, \JSON_UNESCAPED_SLASHES);
$this->validateLastJson();
}
return \rtrim(\strtr(\base64_encode($data), '+/', '-_'), '=');
} | [
"protected",
"function",
"urlSafeEncode",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"\\",
"json_encode",
"(",
"$",
"data",
",",
"\\",
"JSON_UNESCAPED_SLASHES",
")",
";",
"$",
"this",
"->",
"validateLastJson",
"(",
")",
";",
"}",
"return",
"\\",
"rtrim",
"(",
"\\",
"strtr",
"(",
"\\",
"base64_encode",
"(",
"$",
"data",
")",
",",
"'+/'",
",",
"'-_'",
")",
",",
"'='",
")",
";",
"}"
] | URL safe base64 encode.
First serialized the payload as json if it is an array.
@param array|string $data
@throws JWTException When JSON encode fails.
@return string | [
"URL",
"safe",
"base64",
"encode",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L233-L241 |
adhocore/php-jwt | src/JWT.php | JWT.urlSafeDecode | protected function urlSafeDecode($data, $asJson = true)
{
if (!$asJson) {
return \base64_decode(\strtr($data, '-_', '+/'));
}
$data = \json_decode(\base64_decode(\strtr($data, '-_', '+/')));
$this->validateLastJson();
return $data;
} | php | protected function urlSafeDecode($data, $asJson = true)
{
if (!$asJson) {
return \base64_decode(\strtr($data, '-_', '+/'));
}
$data = \json_decode(\base64_decode(\strtr($data, '-_', '+/')));
$this->validateLastJson();
return $data;
} | [
"protected",
"function",
"urlSafeDecode",
"(",
"$",
"data",
",",
"$",
"asJson",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"asJson",
")",
"{",
"return",
"\\",
"base64_decode",
"(",
"\\",
"strtr",
"(",
"$",
"data",
",",
"'-_'",
",",
"'+/'",
")",
")",
";",
"}",
"$",
"data",
"=",
"\\",
"json_decode",
"(",
"\\",
"base64_decode",
"(",
"\\",
"strtr",
"(",
"$",
"data",
",",
"'-_'",
",",
"'+/'",
")",
")",
")",
";",
"$",
"this",
"->",
"validateLastJson",
"(",
")",
";",
"return",
"$",
"data",
";",
"}"
] | URL safe base64 decode.
@param array|string $data
@param bool $asJson Whether to parse as JSON (defaults to true).
@throws JWTException When JSON encode fails.
@return array|\stdClass|string | [
"URL",
"safe",
"base64",
"decode",
"."
] | train | https://github.com/adhocore/php-jwt/blob/7bbb90d089ac5ef73b4282fc33c7de23403ae6c8/src/JWT.php#L253-L263 |
php-edifact/edifact | src/EDI/Reader.php | Reader.load | public function load(string $url): bool
{
$this->parsedfile = (new Parser($url))->get();
return $this->preValidate();
} | php | public function load(string $url): bool
{
$this->parsedfile = (new Parser($url))->get();
return $this->preValidate();
} | [
"public",
"function",
"load",
"(",
"string",
"$",
"url",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"parsedfile",
"=",
"(",
"new",
"Parser",
"(",
"$",
"url",
")",
")",
"->",
"get",
"(",
")",
";",
"return",
"$",
"this",
"->",
"preValidate",
"(",
")",
";",
"}"
] | @param string $url url to edi file, path to edi file or EDI message
@return bool | [
"@param",
"string",
"$url",
"url",
"to",
"edi",
"file",
"path",
"to",
"edi",
"file",
"or",
"EDI",
"message"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L65-L70 |
php-edifact/edifact | src/EDI/Reader.php | Reader.preValidate | public function preValidate(): bool
{
$this->errors = [];
if (!\is_array($this->parsedfile)) {
$this->errors[] = 'Incorrect format parsed file';
return false;
}
$r = $this->readUNHmessageNumber();
if (!$r && isset($this->errors[0]) && $this->errors[0] == 'Segment "UNH" is ambiguous') {
$this->errors = [];
$this->errors[] = 'File has multiple messages';
return false;
}
return true;
} | php | public function preValidate(): bool
{
$this->errors = [];
if (!\is_array($this->parsedfile)) {
$this->errors[] = 'Incorrect format parsed file';
return false;
}
$r = $this->readUNHmessageNumber();
if (!$r && isset($this->errors[0]) && $this->errors[0] == 'Segment "UNH" is ambiguous') {
$this->errors = [];
$this->errors[] = 'File has multiple messages';
return false;
}
return true;
} | [
"public",
"function",
"preValidate",
"(",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"parsedfile",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Incorrect format parsed file'",
";",
"return",
"false",
";",
"}",
"$",
"r",
"=",
"$",
"this",
"->",
"readUNHmessageNumber",
"(",
")",
";",
"if",
"(",
"!",
"$",
"r",
"&&",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"0",
"]",
")",
"&&",
"$",
"this",
"->",
"errors",
"[",
"0",
"]",
"==",
"'Segment \"UNH\" is ambiguous'",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'File has multiple messages'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Do initial validation
@return bool | [
"Do",
"initial",
"validation"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L89-L108 |
php-edifact/edifact | src/EDI/Reader.php | Reader.splitMultiMessage | public static function splitMultiMessage(string $ediMessage): array
{
// init
$splicedMessages = [];
$message = [];
$unb = false;
foreach (self::unwrap($ediMessage) as $segment) {
if (\strpos($segment, 'UNB') === 0) {
$unb = $segment;
continue;
}
if (\strpos($segment, 'UNH') === 0) {
if ($unb) {
$message[] = $unb;
}
$message[] = $segment;
continue;
}
if (\strpos($segment, 'UNT') === 0) {
$message[] = $segment;
$splicedMessages[] = $message;
$message = [];
continue;
}
if ($message) {
$message[] = $segment;
}
}
if (\strpos($segment, 'UNZ') === 0) {
$segment = \preg_replace('#UNZ\+\d+\+#', 'UNZ+1+', $segment);
foreach ($splicedMessages as $k => $message) {
$splicedMessages[$k][] = $segment;
}
}
foreach ($splicedMessages as $k => &$message) {
$message = \implode(PHP_EOL, $splicedMessages[$k]);
}
return $splicedMessages;
} | php | public static function splitMultiMessage(string $ediMessage): array
{
// init
$splicedMessages = [];
$message = [];
$unb = false;
foreach (self::unwrap($ediMessage) as $segment) {
if (\strpos($segment, 'UNB') === 0) {
$unb = $segment;
continue;
}
if (\strpos($segment, 'UNH') === 0) {
if ($unb) {
$message[] = $unb;
}
$message[] = $segment;
continue;
}
if (\strpos($segment, 'UNT') === 0) {
$message[] = $segment;
$splicedMessages[] = $message;
$message = [];
continue;
}
if ($message) {
$message[] = $segment;
}
}
if (\strpos($segment, 'UNZ') === 0) {
$segment = \preg_replace('#UNZ\+\d+\+#', 'UNZ+1+', $segment);
foreach ($splicedMessages as $k => $message) {
$splicedMessages[$k][] = $segment;
}
}
foreach ($splicedMessages as $k => &$message) {
$message = \implode(PHP_EOL, $splicedMessages[$k]);
}
return $splicedMessages;
} | [
"public",
"static",
"function",
"splitMultiMessage",
"(",
"string",
"$",
"ediMessage",
")",
":",
"array",
"{",
"// init",
"$",
"splicedMessages",
"=",
"[",
"]",
";",
"$",
"message",
"=",
"[",
"]",
";",
"$",
"unb",
"=",
"false",
";",
"foreach",
"(",
"self",
"::",
"unwrap",
"(",
"$",
"ediMessage",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"segment",
",",
"'UNB'",
")",
"===",
"0",
")",
"{",
"$",
"unb",
"=",
"$",
"segment",
";",
"continue",
";",
"}",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"segment",
",",
"'UNH'",
")",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"unb",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"$",
"unb",
";",
"}",
"$",
"message",
"[",
"]",
"=",
"$",
"segment",
";",
"continue",
";",
"}",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"segment",
",",
"'UNT'",
")",
"===",
"0",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"$",
"segment",
";",
"$",
"splicedMessages",
"[",
"]",
"=",
"$",
"message",
";",
"$",
"message",
"=",
"[",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"message",
")",
"{",
"$",
"message",
"[",
"]",
"=",
"$",
"segment",
";",
"}",
"}",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"segment",
",",
"'UNZ'",
")",
"===",
"0",
")",
"{",
"$",
"segment",
"=",
"\\",
"preg_replace",
"(",
"'#UNZ\\+\\d+\\+#'",
",",
"'UNZ+1+'",
",",
"$",
"segment",
")",
";",
"foreach",
"(",
"$",
"splicedMessages",
"as",
"$",
"k",
"=>",
"$",
"message",
")",
"{",
"$",
"splicedMessages",
"[",
"$",
"k",
"]",
"[",
"]",
"=",
"$",
"segment",
";",
"}",
"}",
"foreach",
"(",
"$",
"splicedMessages",
"as",
"$",
"k",
"=>",
"&",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"\\",
"implode",
"(",
"PHP_EOL",
",",
"$",
"splicedMessages",
"[",
"$",
"k",
"]",
")",
";",
"}",
"return",
"$",
"splicedMessages",
";",
"}"
] | Split multi messages to separate messages
@param string $ediMessage
@return array | [
"Split",
"multi",
"messages",
"to",
"separate",
"messages"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L117-L163 |
php-edifact/edifact | src/EDI/Reader.php | Reader.unwrap | private static function unwrap($string)
{
foreach (\preg_split("/(?<!\?)'/", $string) as &$line) {
$line = \preg_replace('#[\x00\r\n]#', '', $line);
$temp = $line . "'";
if ($temp != "'") {
yield $temp;
}
}
} | php | private static function unwrap($string)
{
foreach (\preg_split("/(?<!\?)'/", $string) as &$line) {
$line = \preg_replace('#[\x00\r\n]#', '', $line);
$temp = $line . "'";
if ($temp != "'") {
yield $temp;
}
}
} | [
"private",
"static",
"function",
"unwrap",
"(",
"$",
"string",
")",
"{",
"foreach",
"(",
"\\",
"preg_split",
"(",
"\"/(?<!\\?)'/\"",
",",
"$",
"string",
")",
"as",
"&",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"\\",
"preg_replace",
"(",
"'#[\\x00\\r\\n]#'",
",",
"''",
",",
"$",
"line",
")",
";",
"$",
"temp",
"=",
"$",
"line",
".",
"\"'\"",
";",
"if",
"(",
"$",
"temp",
"!=",
"\"'\"",
")",
"{",
"yield",
"$",
"temp",
";",
"}",
"}",
"}"
] | unwrap string splitting rows on terminator (if not escaped)
@param string $string
@return \Generator | [
"unwrap",
"string",
"splitting",
"rows",
"on",
"terminator",
"(",
"if",
"not",
"escaped",
")"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L172-L181 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readEdiDataValueReq | public function readEdiDataValueReq($filter, int $l1, $l2 = false): string
{
return $this->readEdiDataValue($filter, $l1, $l2, true);
} | php | public function readEdiDataValueReq($filter, int $l1, $l2 = false): string
{
return $this->readEdiDataValue($filter, $l1, $l2, true);
} | [
"public",
"function",
"readEdiDataValueReq",
"(",
"$",
"filter",
",",
"int",
"$",
"l1",
",",
"$",
"l2",
"=",
"false",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"$",
"filter",
",",
"$",
"l1",
",",
"$",
"l2",
",",
"true",
")",
";",
"}"
] | read required value. if no found, registered error
@param string|array $filter segment filter by segment name and values
@param int $l1
@param int|false $l2
@return string | [
"read",
"required",
"value",
".",
"if",
"no",
"found",
"registered",
"error"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L192-L195 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readEdiDataValue | public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = false)
{
// interpret filter parameters
if (\is_array($filter)) {
$segment_name = $filter[0];
$filter_elements = $filter[1];
} else {
$segment_name = $filter;
$filter_elements = false;
}
$segment = false;
$segment_count = 0;
// search segment, who conform to filter
foreach ($this->parsedfile as $edi_row) {
if ($edi_row[0] == $segment_name) {
if ($filter_elements) {
$filter_ok = false;
foreach ($filter_elements as $el_id => $el_value) {
$f_el_list = \explode('.', (string)$el_id);
if (\count($f_el_list) === 1) {
if (
isset($edi_row[$el_id])
&&
$edi_row[$el_id] == $el_value
) {
$filter_ok = true;
break;
}
} else if (
isset($edi_row[$f_el_list[0]])
&&
(
(
isset($edi_row[$f_el_list[0]][$f_el_list[1]])
&&
\is_array($edi_row[$f_el_list[0]])
&&
$edi_row[$f_el_list[0]][$f_el_list[1]] == $el_value
)
||
(
isset($edi_row[$f_el_list[0]])
&&
\is_string($edi_row[$f_el_list[0]])
&&
$edi_row[$f_el_list[0]] == $el_value
)
)
) {
$filter_ok = true;
break;
}
}
if ($filter_ok === false) {
continue;
}
}
$segment = $edi_row;
$segment_count++;
}
}
// no found segment
if (!$segment) {
if ($required) {
$this->errors[] = 'Segment "' . $segment_name . '" no exist';
}
return null;
}
// found more one segment - error
if ($segment_count > 1) {
$this->errors[] = 'Segment "' . $segment_name . '" is ambiguous';
return null;
}
// validate elements
if (!isset($segment[$l1])) {
if ($required) {
$this->errors[] = 'Segment value "' . $segment_name . '[' . $l1 . ']" no exist';
}
return null;
}
// requested first level element
if ($l2 === false) {
return $segment[$l1];
}
// requested second level element, but not exist
if (!\is_array($segment[$l1]) || !isset($segment[$l1][$l2])) {
if ($required) {
$this->errors[] = 'Segment value "' . $segment_name . '[' . $l1 . '][' . $l2 . ']" no exist';
}
return null;
}
// second level element
return $segment[$l1][$l2];
} | php | public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = false)
{
// interpret filter parameters
if (\is_array($filter)) {
$segment_name = $filter[0];
$filter_elements = $filter[1];
} else {
$segment_name = $filter;
$filter_elements = false;
}
$segment = false;
$segment_count = 0;
// search segment, who conform to filter
foreach ($this->parsedfile as $edi_row) {
if ($edi_row[0] == $segment_name) {
if ($filter_elements) {
$filter_ok = false;
foreach ($filter_elements as $el_id => $el_value) {
$f_el_list = \explode('.', (string)$el_id);
if (\count($f_el_list) === 1) {
if (
isset($edi_row[$el_id])
&&
$edi_row[$el_id] == $el_value
) {
$filter_ok = true;
break;
}
} else if (
isset($edi_row[$f_el_list[0]])
&&
(
(
isset($edi_row[$f_el_list[0]][$f_el_list[1]])
&&
\is_array($edi_row[$f_el_list[0]])
&&
$edi_row[$f_el_list[0]][$f_el_list[1]] == $el_value
)
||
(
isset($edi_row[$f_el_list[0]])
&&
\is_string($edi_row[$f_el_list[0]])
&&
$edi_row[$f_el_list[0]] == $el_value
)
)
) {
$filter_ok = true;
break;
}
}
if ($filter_ok === false) {
continue;
}
}
$segment = $edi_row;
$segment_count++;
}
}
// no found segment
if (!$segment) {
if ($required) {
$this->errors[] = 'Segment "' . $segment_name . '" no exist';
}
return null;
}
// found more one segment - error
if ($segment_count > 1) {
$this->errors[] = 'Segment "' . $segment_name . '" is ambiguous';
return null;
}
// validate elements
if (!isset($segment[$l1])) {
if ($required) {
$this->errors[] = 'Segment value "' . $segment_name . '[' . $l1 . ']" no exist';
}
return null;
}
// requested first level element
if ($l2 === false) {
return $segment[$l1];
}
// requested second level element, but not exist
if (!\is_array($segment[$l1]) || !isset($segment[$l1][$l2])) {
if ($required) {
$this->errors[] = 'Segment value "' . $segment_name . '[' . $l1 . '][' . $l2 . ']" no exist';
}
return null;
}
// second level element
return $segment[$l1][$l2];
} | [
"public",
"function",
"readEdiDataValue",
"(",
"$",
"filter",
",",
"int",
"$",
"l1",
",",
"$",
"l2",
"=",
"false",
",",
"bool",
"$",
"required",
"=",
"false",
")",
"{",
"// interpret filter parameters",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"segment_name",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"$",
"filter_elements",
"=",
"$",
"filter",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"segment_name",
"=",
"$",
"filter",
";",
"$",
"filter_elements",
"=",
"false",
";",
"}",
"$",
"segment",
"=",
"false",
";",
"$",
"segment_count",
"=",
"0",
";",
"// search segment, who conform to filter",
"foreach",
"(",
"$",
"this",
"->",
"parsedfile",
"as",
"$",
"edi_row",
")",
"{",
"if",
"(",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"segment_name",
")",
"{",
"if",
"(",
"$",
"filter_elements",
")",
"{",
"$",
"filter_ok",
"=",
"false",
";",
"foreach",
"(",
"$",
"filter_elements",
"as",
"$",
"el_id",
"=>",
"$",
"el_value",
")",
"{",
"$",
"f_el_list",
"=",
"\\",
"explode",
"(",
"'.'",
",",
"(",
"string",
")",
"$",
"el_id",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"f_el_list",
")",
"===",
"1",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"edi_row",
"[",
"$",
"el_id",
"]",
")",
"&&",
"$",
"edi_row",
"[",
"$",
"el_id",
"]",
"==",
"$",
"el_value",
")",
"{",
"$",
"filter_ok",
"=",
"true",
";",
"break",
";",
"}",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
")",
"&&",
"(",
"(",
"isset",
"(",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
"[",
"$",
"f_el_list",
"[",
"1",
"]",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
")",
"&&",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
"[",
"$",
"f_el_list",
"[",
"1",
"]",
"]",
"==",
"$",
"el_value",
")",
"||",
"(",
"isset",
"(",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
")",
"&&",
"\\",
"is_string",
"(",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
")",
"&&",
"$",
"edi_row",
"[",
"$",
"f_el_list",
"[",
"0",
"]",
"]",
"==",
"$",
"el_value",
")",
")",
")",
"{",
"$",
"filter_ok",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"filter_ok",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"segment",
"=",
"$",
"edi_row",
";",
"$",
"segment_count",
"++",
";",
"}",
"}",
"// no found segment",
"if",
"(",
"!",
"$",
"segment",
")",
"{",
"if",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Segment \"'",
".",
"$",
"segment_name",
".",
"'\" no exist'",
";",
"}",
"return",
"null",
";",
"}",
"// found more one segment - error",
"if",
"(",
"$",
"segment_count",
">",
"1",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Segment \"'",
".",
"$",
"segment_name",
".",
"'\" is ambiguous'",
";",
"return",
"null",
";",
"}",
"// validate elements",
"if",
"(",
"!",
"isset",
"(",
"$",
"segment",
"[",
"$",
"l1",
"]",
")",
")",
"{",
"if",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Segment value \"'",
".",
"$",
"segment_name",
".",
"'['",
".",
"$",
"l1",
".",
"']\" no exist'",
";",
"}",
"return",
"null",
";",
"}",
"// requested first level element",
"if",
"(",
"$",
"l2",
"===",
"false",
")",
"{",
"return",
"$",
"segment",
"[",
"$",
"l1",
"]",
";",
"}",
"// requested second level element, but not exist",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"segment",
"[",
"$",
"l1",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"segment",
"[",
"$",
"l1",
"]",
"[",
"$",
"l2",
"]",
")",
")",
"{",
"if",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Segment value \"'",
".",
"$",
"segment_name",
".",
"'['",
".",
"$",
"l1",
".",
"']['",
".",
"$",
"l2",
".",
"']\" no exist'",
";",
"}",
"return",
"null",
";",
"}",
"// second level element",
"return",
"$",
"segment",
"[",
"$",
"l1",
"]",
"[",
"$",
"l2",
"]",
";",
"}"
] | read data value from parsed EDI data
@param array|string $filter 'AGR' - segment code
or ['AGR',['1'=>'BB']], where AGR segment code and first element equal 'BB'
or ['AGR',['1.0'=>'BB']], where AGR segment code and first element zero subelement
equal 'BB'
@param int $l1 first level item number (start by 1)
@param int|false $l2 second level item number (start by 0)
@param bool $required if required, but no exist, register error
@return null|string | [
"read",
"data",
"value",
"from",
"parsed",
"EDI",
"data"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L210-L317 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readEdiSegmentDTM | public function readEdiSegmentDTM($PeriodQualifier)
{
$date = $this->readEdiDataValue(['DTM', ['1.0' => $PeriodQualifier]], 1, 1);
$format = $this->readEdiDataValue(['DTM', ['1.0' => $PeriodQualifier]], 1, 2);
if (empty($date)) {
return $date;
}
switch ($format) {
case 203: //CCYYMMDDHHMM
return \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $date);
case 102: //CCYYMMDD
return \preg_replace('/(\d{4})(\d{2})(\d{2})/', '$1-$2-$3', $date);
default:
return $date;
}
} | php | public function readEdiSegmentDTM($PeriodQualifier)
{
$date = $this->readEdiDataValue(['DTM', ['1.0' => $PeriodQualifier]], 1, 1);
$format = $this->readEdiDataValue(['DTM', ['1.0' => $PeriodQualifier]], 1, 2);
if (empty($date)) {
return $date;
}
switch ($format) {
case 203: //CCYYMMDDHHMM
return \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $date);
case 102: //CCYYMMDD
return \preg_replace('/(\d{4})(\d{2})(\d{2})/', '$1-$2-$3', $date);
default:
return $date;
}
} | [
"public",
"function",
"readEdiSegmentDTM",
"(",
"$",
"PeriodQualifier",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"[",
"'DTM'",
",",
"[",
"'1.0'",
"=>",
"$",
"PeriodQualifier",
"]",
"]",
",",
"1",
",",
"1",
")",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"[",
"'DTM'",
",",
"[",
"'1.0'",
"=>",
"$",
"PeriodQualifier",
"]",
"]",
",",
"1",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"date",
")",
")",
"{",
"return",
"$",
"date",
";",
"}",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"203",
":",
"//CCYYMMDDHHMM",
"return",
"\\",
"preg_replace",
"(",
"'#(\\d\\d\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)#'",
",",
"'$1-$2-$3 $4:$5:00'",
",",
"$",
"date",
")",
";",
"case",
"102",
":",
"//CCYYMMDD",
"return",
"\\",
"preg_replace",
"(",
"'/(\\d{4})(\\d{2})(\\d{2})/'",
",",
"'$1-$2-$3'",
",",
"$",
"date",
")",
";",
"default",
":",
"return",
"$",
"date",
";",
"}",
"}"
] | read date from DTM segment period qualifier - codelist 2005
@param int $PeriodQualifier period qualifier (codelist/2005)
@return string YYYY-MM-DD HH:MM:SS | [
"read",
"date",
"from",
"DTM",
"segment",
"period",
"qualifier",
"-",
"codelist",
"2005"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L326-L344 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readUNBDateTimeOfPreparation | public function readUNBDateTimeOfPreparation()
{
// separate date (YYMMDD) and time (HHMM)
$date = $this->readEdiDataValue('UNB', 4, 0);
if (!empty($date)) {
$time = $this->readEdiDataValue('UNB', 4, 1);
$datetime = \preg_replace('#(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '20$1-$2-$3 $4:$5:00', $date . $time);
return $datetime;
}
// common YYYYMMDDHHMM
$datetime = $this->readEdiDataValue('UNB', 4);
$datetime = \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $datetime);
return $datetime;
} | php | public function readUNBDateTimeOfPreparation()
{
// separate date (YYMMDD) and time (HHMM)
$date = $this->readEdiDataValue('UNB', 4, 0);
if (!empty($date)) {
$time = $this->readEdiDataValue('UNB', 4, 1);
$datetime = \preg_replace('#(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '20$1-$2-$3 $4:$5:00', $date . $time);
return $datetime;
}
// common YYYYMMDDHHMM
$datetime = $this->readEdiDataValue('UNB', 4);
$datetime = \preg_replace('#(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)#', '$1-$2-$3 $4:$5:00', $datetime);
return $datetime;
} | [
"public",
"function",
"readUNBDateTimeOfPreparation",
"(",
")",
"{",
"// separate date (YYMMDD) and time (HHMM)",
"$",
"date",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"'UNB'",
",",
"4",
",",
"0",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"date",
")",
")",
"{",
"$",
"time",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"'UNB'",
",",
"4",
",",
"1",
")",
";",
"$",
"datetime",
"=",
"\\",
"preg_replace",
"(",
"'#(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)#'",
",",
"'20$1-$2-$3 $4:$5:00'",
",",
"$",
"date",
".",
"$",
"time",
")",
";",
"return",
"$",
"datetime",
";",
"}",
"// common YYYYMMDDHHMM",
"$",
"datetime",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"'UNB'",
",",
"4",
")",
";",
"$",
"datetime",
"=",
"\\",
"preg_replace",
"(",
"'#(\\d\\d\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)#'",
",",
"'$1-$2-$3 $4:$5:00'",
",",
"$",
"datetime",
")",
";",
"return",
"$",
"datetime",
";",
"}"
] | get message preparation time
@return null|string | [
"get",
"message",
"preparation",
"time"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L367-L383 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readTDTtransportIdentification | public function readTDTtransportIdentification($transportStageQualifier): string
{
$transportIdentification = $this->readEdiDataValue(['TDT', ['1' => $transportStageQualifier]], 8, 0);
if (!empty($transportIdentification)) {
return $transportIdentification;
}
return $this->readEdiDataValue(['TDT', ['1' => $transportStageQualifier]], 8);
} | php | public function readTDTtransportIdentification($transportStageQualifier): string
{
$transportIdentification = $this->readEdiDataValue(['TDT', ['1' => $transportStageQualifier]], 8, 0);
if (!empty($transportIdentification)) {
return $transportIdentification;
}
return $this->readEdiDataValue(['TDT', ['1' => $transportStageQualifier]], 8);
} | [
"public",
"function",
"readTDTtransportIdentification",
"(",
"$",
"transportStageQualifier",
")",
":",
"string",
"{",
"$",
"transportIdentification",
"=",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"[",
"'TDT'",
",",
"[",
"'1'",
"=>",
"$",
"transportStageQualifier",
"]",
"]",
",",
"8",
",",
"0",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"transportIdentification",
")",
")",
"{",
"return",
"$",
"transportIdentification",
";",
"}",
"return",
"$",
"this",
"->",
"readEdiDataValue",
"(",
"[",
"'TDT'",
",",
"[",
"'1'",
"=>",
"$",
"transportStageQualifier",
"]",
"]",
",",
"8",
")",
";",
"}"
] | read transport identification number
@param mixed $transportStageQualifier
@return null|string | [
"read",
"transport",
"identification",
"number"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L392-L400 |
php-edifact/edifact | src/EDI/Reader.php | Reader.readGroups | public function readGroups(string $before, string $start, string $end, string $after)
{
// init
$groups = [];
$group = [];
$position = 'before_search';
foreach ($this->parsedfile as $edi_row) {
// search before group segment
if ($position == 'before_search' && $edi_row[0] == $before) {
$position = 'before_is';
continue;
}
if ($position == 'before_search') {
continue;
}
if ($position == 'before_is' && $edi_row[0] == $before) {
continue;
}
// after before search start
if ($position == 'before_is' && $edi_row[0] == $start) {
$position = 'group_is';
$group[] = $edi_row;
continue;
}
// if after before segment no start segment, search again before segment
if ($position == 'before_is') {
$position = 'before_search';
continue;
}
// get group element
if ($position == 'group_is' && $edi_row[0] != $end) {
$group[] = $edi_row;
continue;
}
// found end of group
if ($position == 'group_is' && $edi_row[0] == $end) {
$position = 'group_finish';
$group[] = $edi_row;
$groups[] = $group;
$group = [];
continue;
}
// next group start
if ($position == 'group_finish' && $edi_row[0] == $start) {
$group[] = $edi_row;
$position = 'group_is';
continue;
}
// finish
if ($position == 'group_finish' && $edi_row[0] == $after) {
break;
}
$this->errors[] = 'Reading group ' . $before . '/' . $start . '/' . $end . '/' . $after
. '. Error on position: ' . $position;
return false;
}
return $groups;
} | php | public function readGroups(string $before, string $start, string $end, string $after)
{
// init
$groups = [];
$group = [];
$position = 'before_search';
foreach ($this->parsedfile as $edi_row) {
// search before group segment
if ($position == 'before_search' && $edi_row[0] == $before) {
$position = 'before_is';
continue;
}
if ($position == 'before_search') {
continue;
}
if ($position == 'before_is' && $edi_row[0] == $before) {
continue;
}
// after before search start
if ($position == 'before_is' && $edi_row[0] == $start) {
$position = 'group_is';
$group[] = $edi_row;
continue;
}
// if after before segment no start segment, search again before segment
if ($position == 'before_is') {
$position = 'before_search';
continue;
}
// get group element
if ($position == 'group_is' && $edi_row[0] != $end) {
$group[] = $edi_row;
continue;
}
// found end of group
if ($position == 'group_is' && $edi_row[0] == $end) {
$position = 'group_finish';
$group[] = $edi_row;
$groups[] = $group;
$group = [];
continue;
}
// next group start
if ($position == 'group_finish' && $edi_row[0] == $start) {
$group[] = $edi_row;
$position = 'group_is';
continue;
}
// finish
if ($position == 'group_finish' && $edi_row[0] == $after) {
break;
}
$this->errors[] = 'Reading group ' . $before . '/' . $start . '/' . $end . '/' . $after
. '. Error on position: ' . $position;
return false;
}
return $groups;
} | [
"public",
"function",
"readGroups",
"(",
"string",
"$",
"before",
",",
"string",
"$",
"start",
",",
"string",
"$",
"end",
",",
"string",
"$",
"after",
")",
"{",
"// init",
"$",
"groups",
"=",
"[",
"]",
";",
"$",
"group",
"=",
"[",
"]",
";",
"$",
"position",
"=",
"'before_search'",
";",
"foreach",
"(",
"$",
"this",
"->",
"parsedfile",
"as",
"$",
"edi_row",
")",
"{",
"// search before group segment",
"if",
"(",
"$",
"position",
"==",
"'before_search'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"before",
")",
"{",
"$",
"position",
"=",
"'before_is'",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"position",
"==",
"'before_search'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"position",
"==",
"'before_is'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"before",
")",
"{",
"continue",
";",
"}",
"// after before search start",
"if",
"(",
"$",
"position",
"==",
"'before_is'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"start",
")",
"{",
"$",
"position",
"=",
"'group_is'",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"edi_row",
";",
"continue",
";",
"}",
"// if after before segment no start segment, search again before segment",
"if",
"(",
"$",
"position",
"==",
"'before_is'",
")",
"{",
"$",
"position",
"=",
"'before_search'",
";",
"continue",
";",
"}",
"// get group element",
"if",
"(",
"$",
"position",
"==",
"'group_is'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"!=",
"$",
"end",
")",
"{",
"$",
"group",
"[",
"]",
"=",
"$",
"edi_row",
";",
"continue",
";",
"}",
"// found end of group",
"if",
"(",
"$",
"position",
"==",
"'group_is'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"end",
")",
"{",
"$",
"position",
"=",
"'group_finish'",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"edi_row",
";",
"$",
"groups",
"[",
"]",
"=",
"$",
"group",
";",
"$",
"group",
"=",
"[",
"]",
";",
"continue",
";",
"}",
"// next group start",
"if",
"(",
"$",
"position",
"==",
"'group_finish'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"start",
")",
"{",
"$",
"group",
"[",
"]",
"=",
"$",
"edi_row",
";",
"$",
"position",
"=",
"'group_is'",
";",
"continue",
";",
"}",
"// finish",
"if",
"(",
"$",
"position",
"==",
"'group_finish'",
"&&",
"$",
"edi_row",
"[",
"0",
"]",
"==",
"$",
"after",
")",
"{",
"break",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"'Reading group '",
".",
"$",
"before",
".",
"'/'",
".",
"$",
"start",
".",
"'/'",
".",
"$",
"end",
".",
"'/'",
".",
"$",
"after",
".",
"'. Error on position: '",
".",
"$",
"position",
";",
"return",
"false",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | Get groups from message.
@param string $before segment before groups
@param string $start first segment of group
@param string $end last segment of group
@param string $after segment after groups
@return false|array | [
"Get",
"groups",
"from",
"message",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L432-L501 |
php-edifact/edifact | src/EDI/Reader.php | Reader.groupsExtract | public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): array
{
// init
$groups = [];
$group = [];
$position = 'before_search';
foreach ($this->getParsedFile() as $edi_row) {
$segment = $edi_row[0];
if (
$position == 'group_is'
&&
(
$segment == $start
||
\in_array($segment, $barrier, true)
)
) {
// end of group
$groups[] = $group;
// start new group
$group = [];
$position = 'group_finish';
}
if ($segment == $start) {
$position = 'group_is';
}
// add element to group
if ($position == 'group_is') {
$group[] = $edi_row;
}
}
return $groups;
} | php | public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): array
{
// init
$groups = [];
$group = [];
$position = 'before_search';
foreach ($this->getParsedFile() as $edi_row) {
$segment = $edi_row[0];
if (
$position == 'group_is'
&&
(
$segment == $start
||
\in_array($segment, $barrier, true)
)
) {
// end of group
$groups[] = $group;
// start new group
$group = [];
$position = 'group_finish';
}
if ($segment == $start) {
$position = 'group_is';
}
// add element to group
if ($position == 'group_is') {
$group[] = $edi_row;
}
}
return $groups;
} | [
"public",
"function",
"groupsExtract",
"(",
"string",
"$",
"start",
"=",
"'LIN'",
",",
"array",
"$",
"barrier",
"=",
"[",
"'UNS'",
"]",
")",
":",
"array",
"{",
"// init",
"$",
"groups",
"=",
"[",
"]",
";",
"$",
"group",
"=",
"[",
"]",
";",
"$",
"position",
"=",
"'before_search'",
";",
"foreach",
"(",
"$",
"this",
"->",
"getParsedFile",
"(",
")",
"as",
"$",
"edi_row",
")",
"{",
"$",
"segment",
"=",
"$",
"edi_row",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"position",
"==",
"'group_is'",
"&&",
"(",
"$",
"segment",
"==",
"$",
"start",
"||",
"\\",
"in_array",
"(",
"$",
"segment",
",",
"$",
"barrier",
",",
"true",
")",
")",
")",
"{",
"// end of group",
"$",
"groups",
"[",
"]",
"=",
"$",
"group",
";",
"// start new group",
"$",
"group",
"=",
"[",
"]",
";",
"$",
"position",
"=",
"'group_finish'",
";",
"}",
"if",
"(",
"$",
"segment",
"==",
"$",
"start",
")",
"{",
"$",
"position",
"=",
"'group_is'",
";",
"}",
"// add element to group",
"if",
"(",
"$",
"position",
"==",
"'group_is'",
")",
"{",
"$",
"group",
"[",
"]",
"=",
"$",
"edi_row",
";",
"}",
"}",
"return",
"$",
"groups",
";",
"}"
] | Get groups from message when last segment is unknown but you know the barrier
useful for invoices by default.
@param string $start first segment start a new group
@param array $barrier barrier segment (NOT in group)
@return array | [
"Get",
"groups",
"from",
"message",
"when",
"last",
"segment",
"is",
"unknown",
"but",
"you",
"know",
"the",
"barrier",
"useful",
"for",
"invoices",
"by",
"default",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Reader.php#L512-L548 |
php-edifact/edifact | src/EDI/Parser.php | Parser.parse | public function parse(array &$file2): array
{
$i = 0;
foreach ($file2 as &$line) {
++$i;
// Null byte and carriage return removal. (CR+LF)
$line = str_replace(["\x00", "\r", "\n"], '', $line);
// Basic sanitization, remove non printable chars.
$lineTrim = \trim($line);
$line = \preg_replace($this->stripChars, '', $lineTrim);
$line_bytes = \strlen($line);
if ($line_bytes !== \strlen($lineTrim)) {
$this->errors[] = "There's a not printable character on line " . $i . ": " . $lineTrim;
}
if ($line_bytes < 2) {
continue;
}
switch (\substr($line, 0, 3)) {
case "UNA":
if (!$this->unaChecked) {
$this->analyseUNA(\substr($line, 4, 6));
}
break;
case "UNB":
$line = $this->splitSegment($line);
if (!$this->unbChecked) {
$this->analyseUNB($line[1]);
}
$this->parsedfile[] = $line;
break;
case "UNH":
$line = $this->splitSegment($line);
$this->analyseUNH($line);
$this->parsedfile[] = $line;
break;
default:
$line = $this->splitSegment($line);
$this->parsedfile[] = $line;
break;
}
}
return $this->parsedfile;
} | php | public function parse(array &$file2): array
{
$i = 0;
foreach ($file2 as &$line) {
++$i;
// Null byte and carriage return removal. (CR+LF)
$line = str_replace(["\x00", "\r", "\n"], '', $line);
// Basic sanitization, remove non printable chars.
$lineTrim = \trim($line);
$line = \preg_replace($this->stripChars, '', $lineTrim);
$line_bytes = \strlen($line);
if ($line_bytes !== \strlen($lineTrim)) {
$this->errors[] = "There's a not printable character on line " . $i . ": " . $lineTrim;
}
if ($line_bytes < 2) {
continue;
}
switch (\substr($line, 0, 3)) {
case "UNA":
if (!$this->unaChecked) {
$this->analyseUNA(\substr($line, 4, 6));
}
break;
case "UNB":
$line = $this->splitSegment($line);
if (!$this->unbChecked) {
$this->analyseUNB($line[1]);
}
$this->parsedfile[] = $line;
break;
case "UNH":
$line = $this->splitSegment($line);
$this->analyseUNH($line);
$this->parsedfile[] = $line;
break;
default:
$line = $this->splitSegment($line);
$this->parsedfile[] = $line;
break;
}
}
return $this->parsedfile;
} | [
"public",
"function",
"parse",
"(",
"array",
"&",
"$",
"file2",
")",
":",
"array",
"{",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"file2",
"as",
"&",
"$",
"line",
")",
"{",
"++",
"$",
"i",
";",
"// Null byte and carriage return removal. (CR+LF)",
"$",
"line",
"=",
"str_replace",
"(",
"[",
"\"\\x00\"",
",",
"\"\\r\"",
",",
"\"\\n\"",
"]",
",",
"''",
",",
"$",
"line",
")",
";",
"// Basic sanitization, remove non printable chars.",
"$",
"lineTrim",
"=",
"\\",
"trim",
"(",
"$",
"line",
")",
";",
"$",
"line",
"=",
"\\",
"preg_replace",
"(",
"$",
"this",
"->",
"stripChars",
",",
"''",
",",
"$",
"lineTrim",
")",
";",
"$",
"line_bytes",
"=",
"\\",
"strlen",
"(",
"$",
"line",
")",
";",
"if",
"(",
"$",
"line_bytes",
"!==",
"\\",
"strlen",
"(",
"$",
"lineTrim",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"\"There's a not printable character on line \"",
".",
"$",
"i",
".",
"\": \"",
".",
"$",
"lineTrim",
";",
"}",
"if",
"(",
"$",
"line_bytes",
"<",
"2",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"\\",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"3",
")",
")",
"{",
"case",
"\"UNA\"",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"unaChecked",
")",
"{",
"$",
"this",
"->",
"analyseUNA",
"(",
"\\",
"substr",
"(",
"$",
"line",
",",
"4",
",",
"6",
")",
")",
";",
"}",
"break",
";",
"case",
"\"UNB\"",
":",
"$",
"line",
"=",
"$",
"this",
"->",
"splitSegment",
"(",
"$",
"line",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"unbChecked",
")",
"{",
"$",
"this",
"->",
"analyseUNB",
"(",
"$",
"line",
"[",
"1",
"]",
")",
";",
"}",
"$",
"this",
"->",
"parsedfile",
"[",
"]",
"=",
"$",
"line",
";",
"break",
";",
"case",
"\"UNH\"",
":",
"$",
"line",
"=",
"$",
"this",
"->",
"splitSegment",
"(",
"$",
"line",
")",
";",
"$",
"this",
"->",
"analyseUNH",
"(",
"$",
"line",
")",
";",
"$",
"this",
"->",
"parsedfile",
"[",
"]",
"=",
"$",
"line",
";",
"break",
";",
"default",
":",
"$",
"line",
"=",
"$",
"this",
"->",
"splitSegment",
"(",
"$",
"line",
")",
";",
"$",
"this",
"->",
"parsedfile",
"[",
"]",
"=",
"$",
"line",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"parsedfile",
";",
"}"
] | Parse edi array
@param array $file2
@return array | [
"Parse",
"edi",
"array"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L174-L222 |
php-edifact/edifact | src/EDI/Parser.php | Parser.resetUNA | private function resetUNA()
{
$this->sepComp = "\:";
$this->sepUnescapedComp = ":";
$this->sepData = "\+";
$this->sepDec = "."; // See later if a preg_quote is needed
$this->symbRel = "\?";
$this->symbUnescapedRel = "?";
$this->symbRep = "*"; // See later if a preg_quote is needed
$this->symbEnd = "'";
$this->stringSafe = "§SS§";
$this->unaChecked = false;
} | php | private function resetUNA()
{
$this->sepComp = "\:";
$this->sepUnescapedComp = ":";
$this->sepData = "\+";
$this->sepDec = "."; // See later if a preg_quote is needed
$this->symbRel = "\?";
$this->symbUnescapedRel = "?";
$this->symbRep = "*"; // See later if a preg_quote is needed
$this->symbEnd = "'";
$this->stringSafe = "§SS§";
$this->unaChecked = false;
} | [
"private",
"function",
"resetUNA",
"(",
")",
"{",
"$",
"this",
"->",
"sepComp",
"=",
"\"\\:\"",
";",
"$",
"this",
"->",
"sepUnescapedComp",
"=",
"\":\"",
";",
"$",
"this",
"->",
"sepData",
"=",
"\"\\+\"",
";",
"$",
"this",
"->",
"sepDec",
"=",
"\".\"",
";",
"// See later if a preg_quote is needed",
"$",
"this",
"->",
"symbRel",
"=",
"\"\\?\"",
";",
"$",
"this",
"->",
"symbUnescapedRel",
"=",
"\"?\"",
";",
"$",
"this",
"->",
"symbRep",
"=",
"\"*\"",
";",
"// See later if a preg_quote is needed",
"$",
"this",
"->",
"symbEnd",
"=",
"\"'\"",
";",
"$",
"this",
"->",
"stringSafe",
"=",
"\"§SS§\";",
"",
"$",
"this",
"->",
"unaChecked",
"=",
"false",
";",
"}"
] | Reset UNA's characters definition
@return void | [
"Reset",
"UNA",
"s",
"characters",
"definition"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L229-L241 |
php-edifact/edifact | src/EDI/Parser.php | Parser.analyseUNA | public function analyseUNA(string $line)
{
$line = \substr($line, 0, 6);
if (isset($line[0])) {
$this->sepComp = \preg_quote($line[0], self::$DELIMITER);
$this->sepUnescapedComp = $line[0];
if (isset($line[1])) {
$this->sepData = \preg_quote($line[1], self::$DELIMITER);
if (isset($line[2])) {
$this->sepDec = $line[2]; // See later if a preg_quote is needed
if (isset($line[3])) {
$this->symbRel = \preg_quote($line[3], self::$DELIMITER);
$this->symbUnescapedRel = $line[3];
if (isset($line[4])) {
$this->symbRep = $line[4]; // See later if a preg_quote is needed
if (isset($line[5])) {
$this->symbEnd = \preg_quote($line[5], self::$DELIMITER);
}
}
}
}
}
$this->unaChecked = true;
}
} | php | public function analyseUNA(string $line)
{
$line = \substr($line, 0, 6);
if (isset($line[0])) {
$this->sepComp = \preg_quote($line[0], self::$DELIMITER);
$this->sepUnescapedComp = $line[0];
if (isset($line[1])) {
$this->sepData = \preg_quote($line[1], self::$DELIMITER);
if (isset($line[2])) {
$this->sepDec = $line[2]; // See later if a preg_quote is needed
if (isset($line[3])) {
$this->symbRel = \preg_quote($line[3], self::$DELIMITER);
$this->symbUnescapedRel = $line[3];
if (isset($line[4])) {
$this->symbRep = $line[4]; // See later if a preg_quote is needed
if (isset($line[5])) {
$this->symbEnd = \preg_quote($line[5], self::$DELIMITER);
}
}
}
}
}
$this->unaChecked = true;
}
} | [
"public",
"function",
"analyseUNA",
"(",
"string",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"\\",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"6",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sepComp",
"=",
"\\",
"preg_quote",
"(",
"$",
"line",
"[",
"0",
"]",
",",
"self",
"::",
"$",
"DELIMITER",
")",
";",
"$",
"this",
"->",
"sepUnescapedComp",
"=",
"$",
"line",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sepData",
"=",
"\\",
"preg_quote",
"(",
"$",
"line",
"[",
"1",
"]",
",",
"self",
"::",
"$",
"DELIMITER",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"2",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sepDec",
"=",
"$",
"line",
"[",
"2",
"]",
";",
"// See later if a preg_quote is needed",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"3",
"]",
")",
")",
"{",
"$",
"this",
"->",
"symbRel",
"=",
"\\",
"preg_quote",
"(",
"$",
"line",
"[",
"3",
"]",
",",
"self",
"::",
"$",
"DELIMITER",
")",
";",
"$",
"this",
"->",
"symbUnescapedRel",
"=",
"$",
"line",
"[",
"3",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"4",
"]",
")",
")",
"{",
"$",
"this",
"->",
"symbRep",
"=",
"$",
"line",
"[",
"4",
"]",
";",
"// See later if a preg_quote is needed",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"5",
"]",
")",
")",
"{",
"$",
"this",
"->",
"symbEnd",
"=",
"\\",
"preg_quote",
"(",
"$",
"line",
"[",
"5",
"]",
",",
"self",
"::",
"$",
"DELIMITER",
")",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"unaChecked",
"=",
"true",
";",
"}",
"}"
] | Read UNA's characters definition
@param string $line : UNA definition line (without UNA tag). Example : :+.? '
@return void | [
"Read",
"UNA",
"s",
"characters",
"definition"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L261-L285 |
php-edifact/edifact | src/EDI/Parser.php | Parser.analyseUNB | public function analyseUNB($encoding)
{
if (\is_array($encoding)) {
$encoding = $encoding[0];
}
$this->encoding = $encoding;
// If there's a regex defined for this character set, use it.
/** @noinspection OffsetOperationsInspection */
if (isset(self::$encodingToStripChars[$encoding])) {
/** @noinspection OffsetOperationsInspection */
$this->setStripRegex(self::$encodingToStripChars[$encoding]);
}
$this->unbChecked = true;
} | php | public function analyseUNB($encoding)
{
if (\is_array($encoding)) {
$encoding = $encoding[0];
}
$this->encoding = $encoding;
// If there's a regex defined for this character set, use it.
/** @noinspection OffsetOperationsInspection */
if (isset(self::$encodingToStripChars[$encoding])) {
/** @noinspection OffsetOperationsInspection */
$this->setStripRegex(self::$encodingToStripChars[$encoding]);
}
$this->unbChecked = true;
} | [
"public",
"function",
"analyseUNB",
"(",
"$",
"encoding",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"encoding",
")",
")",
"{",
"$",
"encoding",
"=",
"$",
"encoding",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"encoding",
"=",
"$",
"encoding",
";",
"// If there's a regex defined for this character set, use it.",
"/** @noinspection OffsetOperationsInspection */",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"encodingToStripChars",
"[",
"$",
"encoding",
"]",
")",
")",
"{",
"/** @noinspection OffsetOperationsInspection */",
"$",
"this",
"->",
"setStripRegex",
"(",
"self",
"::",
"$",
"encodingToStripChars",
"[",
"$",
"encoding",
"]",
")",
";",
"}",
"$",
"this",
"->",
"unbChecked",
"=",
"true",
";",
"}"
] | UNB line analysis
@param string|string[] $encoding UNB definition line (without UNB tag). Example UNOA:2
@return void | [
"UNB",
"line",
"analysis"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L294-L310 |
php-edifact/edifact | src/EDI/Parser.php | Parser.analyseUNH | public function analyseUNH(array $line)
{
if (\count($line) < 3) {
return;
}
$lineElement = $line[2];
if (!\is_array($lineElement)) {
$this->messageFormat = $lineElement;
return;
}
$this->messageFormat = $lineElement[0];
$this->messageDirectory = $lineElement[2];
} | php | public function analyseUNH(array $line)
{
if (\count($line) < 3) {
return;
}
$lineElement = $line[2];
if (!\is_array($lineElement)) {
$this->messageFormat = $lineElement;
return;
}
$this->messageFormat = $lineElement[0];
$this->messageDirectory = $lineElement[2];
} | [
"public",
"function",
"analyseUNH",
"(",
"array",
"$",
"line",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"line",
")",
"<",
"3",
")",
"{",
"return",
";",
"}",
"$",
"lineElement",
"=",
"$",
"line",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"lineElement",
")",
")",
"{",
"$",
"this",
"->",
"messageFormat",
"=",
"$",
"lineElement",
";",
"return",
";",
"}",
"$",
"this",
"->",
"messageFormat",
"=",
"$",
"lineElement",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"messageDirectory",
"=",
"$",
"lineElement",
"[",
"2",
"]",
";",
"}"
] | Identify message type
@param string[] $line UNH segment
@return void | [
"Identify",
"message",
"type"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L319-L334 |
php-edifact/edifact | src/EDI/Parser.php | Parser.unwrap | private function unwrap(string &$string): array
{
if (
!$this->unaChecked
&&
\strpos($string, 'UNA') === 0
) {
$this->analyseUNA(
\substr(\substr($string, 3), 0, 9)
);
}
if (
!$this->unbChecked
&&
\strpos($string, 'UNB') === 0
) {
$this->analyseUNB(
\preg_replace(
"#^UNB\+#",
'',
\substr($string, 0, 8)
)
);
}
$string = \preg_replace(
"/(([^" . $this->symbRel . "]" . $this->symbRel . "{2})+|[^" . $this->symbRel . "])" . $this->symbEnd . "/",
"$1" . $this->stringSafe,
$string
);
$file = \preg_split(
self::$DELIMITER . $this->stringSafe . self::$DELIMITER . "i",
$string
);
// fallback
if ($file === false) {
$file = [];
}
$end = \stripslashes($this->symbEnd);
foreach ($file as $fc => &$line) {
if (\trim($line) == '') {
/* @noinspection OffsetOperationsInspection */
unset($file[$fc]);
}
$line .= $end;
}
return $file;
} | php | private function unwrap(string &$string): array
{
if (
!$this->unaChecked
&&
\strpos($string, 'UNA') === 0
) {
$this->analyseUNA(
\substr(\substr($string, 3), 0, 9)
);
}
if (
!$this->unbChecked
&&
\strpos($string, 'UNB') === 0
) {
$this->analyseUNB(
\preg_replace(
"#^UNB\+#",
'',
\substr($string, 0, 8)
)
);
}
$string = \preg_replace(
"/(([^" . $this->symbRel . "]" . $this->symbRel . "{2})+|[^" . $this->symbRel . "])" . $this->symbEnd . "/",
"$1" . $this->stringSafe,
$string
);
$file = \preg_split(
self::$DELIMITER . $this->stringSafe . self::$DELIMITER . "i",
$string
);
// fallback
if ($file === false) {
$file = [];
}
$end = \stripslashes($this->symbEnd);
foreach ($file as $fc => &$line) {
if (\trim($line) == '') {
/* @noinspection OffsetOperationsInspection */
unset($file[$fc]);
}
$line .= $end;
}
return $file;
} | [
"private",
"function",
"unwrap",
"(",
"string",
"&",
"$",
"string",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"unaChecked",
"&&",
"\\",
"strpos",
"(",
"$",
"string",
",",
"'UNA'",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"analyseUNA",
"(",
"\\",
"substr",
"(",
"\\",
"substr",
"(",
"$",
"string",
",",
"3",
")",
",",
"0",
",",
"9",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"unbChecked",
"&&",
"\\",
"strpos",
"(",
"$",
"string",
",",
"'UNB'",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"analyseUNB",
"(",
"\\",
"preg_replace",
"(",
"\"#^UNB\\+#\"",
",",
"''",
",",
"\\",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"8",
")",
")",
")",
";",
"}",
"$",
"string",
"=",
"\\",
"preg_replace",
"(",
"\"/(([^\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"]\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"{2})+|[^\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"])\"",
".",
"$",
"this",
"->",
"symbEnd",
".",
"\"/\"",
",",
"\"$1\"",
".",
"$",
"this",
"->",
"stringSafe",
",",
"$",
"string",
")",
";",
"$",
"file",
"=",
"\\",
"preg_split",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"$",
"this",
"->",
"stringSafe",
".",
"self",
"::",
"$",
"DELIMITER",
".",
"\"i\"",
",",
"$",
"string",
")",
";",
"// fallback",
"if",
"(",
"$",
"file",
"===",
"false",
")",
"{",
"$",
"file",
"=",
"[",
"]",
";",
"}",
"$",
"end",
"=",
"\\",
"stripslashes",
"(",
"$",
"this",
"->",
"symbEnd",
")",
";",
"foreach",
"(",
"$",
"file",
"as",
"$",
"fc",
"=>",
"&",
"$",
"line",
")",
"{",
"if",
"(",
"\\",
"trim",
"(",
"$",
"line",
")",
"==",
"''",
")",
"{",
"/* @noinspection OffsetOperationsInspection */",
"unset",
"(",
"$",
"file",
"[",
"$",
"fc",
"]",
")",
";",
"}",
"$",
"line",
".=",
"$",
"end",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | Unwrap string splitting rows on terminator (if not escaped)
@param string $string
@return string[] | [
"Unwrap",
"string",
"splitting",
"rows",
"on",
"terminator",
"(",
"if",
"not",
"escaped",
")"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L343-L394 |
php-edifact/edifact | src/EDI/Parser.php | Parser.splitSegment | private function splitSegment(string &$str): array
{
// remove ending "symbEnd"
$str = \trim(
\preg_replace(
self::$DELIMITER . $this->symbEnd . '$' . self::$DELIMITER,
'',
$str
)
);
// replace duplicate "symbRel"
$str = \str_replace(
$this->symbUnescapedRel . $this->symbUnescapedRel,
$this->stringSafe,
$str
);
// split on "sepData" if not escaped (negative lookbehind)
$matches = \preg_split(
self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->sepData . self::$DELIMITER,
$str
);
// fallback
if ($matches === false) {
$matches = [];
}
foreach ($matches as &$value) {
if ($value === '') {
continue;
}
// INFO:
//
// ? immediately preceding one of the characters '+:? restores their normal meaning
//
// e.g. 10?+10=20 means 10+10=20
//
// Question mark is represented by ??
if (\strpos($value, $this->symbEnd) !== false) {
if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbEnd . self::$DELIMITER, $value)) {
$this->errors[] = "There's a " . \stripslashes($this->symbEnd) . " not escaped in the data; string " . $str;
}
}
if (\strpos($value, $this->symbUnescapedRel) !== false) {
if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbRel . "(?!" . $this->symbRel . ")(?!" . $this->sepData . ")(?!" . $this->sepComp . ")(?!" . $this->symbEnd . ")" . self::$DELIMITER, $value)) {
$this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel) . " in the data; string " . $value;
}
}
// split on "sepComp"
$value = $this->splitData($value);
}
unset($value);
return $matches;
} | php | private function splitSegment(string &$str): array
{
// remove ending "symbEnd"
$str = \trim(
\preg_replace(
self::$DELIMITER . $this->symbEnd . '$' . self::$DELIMITER,
'',
$str
)
);
// replace duplicate "symbRel"
$str = \str_replace(
$this->symbUnescapedRel . $this->symbUnescapedRel,
$this->stringSafe,
$str
);
// split on "sepData" if not escaped (negative lookbehind)
$matches = \preg_split(
self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->sepData . self::$DELIMITER,
$str
);
// fallback
if ($matches === false) {
$matches = [];
}
foreach ($matches as &$value) {
if ($value === '') {
continue;
}
// INFO:
//
// ? immediately preceding one of the characters '+:? restores their normal meaning
//
// e.g. 10?+10=20 means 10+10=20
//
// Question mark is represented by ??
if (\strpos($value, $this->symbEnd) !== false) {
if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbEnd . self::$DELIMITER, $value)) {
$this->errors[] = "There's a " . \stripslashes($this->symbEnd) . " not escaped in the data; string " . $str;
}
}
if (\strpos($value, $this->symbUnescapedRel) !== false) {
if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbRel . "(?!" . $this->symbRel . ")(?!" . $this->sepData . ")(?!" . $this->sepComp . ")(?!" . $this->symbEnd . ")" . self::$DELIMITER, $value)) {
$this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel) . " in the data; string " . $value;
}
}
// split on "sepComp"
$value = $this->splitData($value);
}
unset($value);
return $matches;
} | [
"private",
"function",
"splitSegment",
"(",
"string",
"&",
"$",
"str",
")",
":",
"array",
"{",
"// remove ending \"symbEnd\"",
"$",
"str",
"=",
"\\",
"trim",
"(",
"\\",
"preg_replace",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"$",
"this",
"->",
"symbEnd",
".",
"'$'",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"''",
",",
"$",
"str",
")",
")",
";",
"// replace duplicate \"symbRel\"",
"$",
"str",
"=",
"\\",
"str_replace",
"(",
"$",
"this",
"->",
"symbUnescapedRel",
".",
"$",
"this",
"->",
"symbUnescapedRel",
",",
"$",
"this",
"->",
"stringSafe",
",",
"$",
"str",
")",
";",
"// split on \"sepData\" if not escaped (negative lookbehind)",
"$",
"matches",
"=",
"\\",
"preg_split",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"\"(?<!\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")\"",
".",
"$",
"this",
"->",
"sepData",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"$",
"str",
")",
";",
"// fallback",
"if",
"(",
"$",
"matches",
"===",
"false",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"matches",
"as",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"// INFO:",
"//",
"// ? immediately preceding one of the characters '+:? restores their normal meaning",
"//",
"// e.g. 10?+10=20 means 10+10=20",
"//",
"// Question mark is represented by ??",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"symbEnd",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"\"(?<!\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")\"",
".",
"$",
"this",
"->",
"symbEnd",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"\"There's a \"",
".",
"\\",
"stripslashes",
"(",
"$",
"this",
"->",
"symbEnd",
")",
".",
"\" not escaped in the data; string \"",
".",
"$",
"str",
";",
"}",
"}",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"symbUnescapedRel",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"\"(?<!\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"(?!\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")(?!\"",
".",
"$",
"this",
"->",
"sepData",
".",
"\")(?!\"",
".",
"$",
"this",
"->",
"sepComp",
".",
"\")(?!\"",
".",
"$",
"this",
"->",
"symbEnd",
".",
"\")\"",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"\"There's a character not escaped with \"",
".",
"\\",
"stripslashes",
"(",
"$",
"this",
"->",
"symbRel",
")",
".",
"\" in the data; string \"",
".",
"$",
"value",
";",
"}",
"}",
"// split on \"sepComp\"",
"$",
"value",
"=",
"$",
"this",
"->",
"splitData",
"(",
"$",
"value",
")",
";",
"}",
"unset",
"(",
"$",
"value",
")",
";",
"return",
"$",
"matches",
";",
"}"
] | Segments
@param string $str
@return array|string[] | [
"Segments"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L403-L462 |
php-edifact/edifact | src/EDI/Parser.php | Parser.splitData | private function splitData(string &$str)
{
if ($str === '') {
return $str;
}
$replace = function (&$string) {
if (\strpos($string, $this->symbUnescapedRel) !== false) {
$string = \preg_replace(
self::$DELIMITER . $this->symbRel . "(?=" . $this->symbRel . ")|" . $this->symbRel . "(?=" . $this->sepData . ")|" . $this->symbRel . "(?=" . $this->sepComp . ")|" . $this->symbRel . "(?=" . $this->symbEnd . ")" . self::$DELIMITER,
'',
$string
);
}
return \str_replace(
$this->stringSafe,
$this->symbUnescapedRel,
$string
);
};
// check for "sepUnescapedComp" in the string
if (\strpos($str, $this->sepUnescapedComp) === false) {
return $replace($str);
}
// split on "sepComp" if not escaped (negative lookbehind)
$array = \preg_split(
self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->sepComp . self::$DELIMITER,
$str
);
// fallback
if ($array === false) {
$array = [[]];
}
if (\count($array) === 1) {
return $replace($str);
}
foreach ($array as &$value) {
$value = $replace($value);
}
return $array;
} | php | private function splitData(string &$str)
{
if ($str === '') {
return $str;
}
$replace = function (&$string) {
if (\strpos($string, $this->symbUnescapedRel) !== false) {
$string = \preg_replace(
self::$DELIMITER . $this->symbRel . "(?=" . $this->symbRel . ")|" . $this->symbRel . "(?=" . $this->sepData . ")|" . $this->symbRel . "(?=" . $this->sepComp . ")|" . $this->symbRel . "(?=" . $this->symbEnd . ")" . self::$DELIMITER,
'',
$string
);
}
return \str_replace(
$this->stringSafe,
$this->symbUnescapedRel,
$string
);
};
// check for "sepUnescapedComp" in the string
if (\strpos($str, $this->sepUnescapedComp) === false) {
return $replace($str);
}
// split on "sepComp" if not escaped (negative lookbehind)
$array = \preg_split(
self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->sepComp . self::$DELIMITER,
$str
);
// fallback
if ($array === false) {
$array = [[]];
}
if (\count($array) === 1) {
return $replace($str);
}
foreach ($array as &$value) {
$value = $replace($value);
}
return $array;
} | [
"private",
"function",
"splitData",
"(",
"string",
"&",
"$",
"str",
")",
"{",
"if",
"(",
"$",
"str",
"===",
"''",
")",
"{",
"return",
"$",
"str",
";",
"}",
"$",
"replace",
"=",
"function",
"(",
"&",
"$",
"string",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"symbUnescapedRel",
")",
"!==",
"false",
")",
"{",
"$",
"string",
"=",
"\\",
"preg_replace",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"(?=\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")|\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"(?=\"",
".",
"$",
"this",
"->",
"sepData",
".",
"\")|\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"(?=\"",
".",
"$",
"this",
"->",
"sepComp",
".",
"\")|\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\"(?=\"",
".",
"$",
"this",
"->",
"symbEnd",
".",
"\")\"",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"''",
",",
"$",
"string",
")",
";",
"}",
"return",
"\\",
"str_replace",
"(",
"$",
"this",
"->",
"stringSafe",
",",
"$",
"this",
"->",
"symbUnescapedRel",
",",
"$",
"string",
")",
";",
"}",
";",
"// check for \"sepUnescapedComp\" in the string",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"str",
",",
"$",
"this",
"->",
"sepUnescapedComp",
")",
"===",
"false",
")",
"{",
"return",
"$",
"replace",
"(",
"$",
"str",
")",
";",
"}",
"// split on \"sepComp\" if not escaped (negative lookbehind)",
"$",
"array",
"=",
"\\",
"preg_split",
"(",
"self",
"::",
"$",
"DELIMITER",
".",
"\"(?<!\"",
".",
"$",
"this",
"->",
"symbRel",
".",
"\")\"",
".",
"$",
"this",
"->",
"sepComp",
".",
"self",
"::",
"$",
"DELIMITER",
",",
"$",
"str",
")",
";",
"// fallback",
"if",
"(",
"$",
"array",
"===",
"false",
")",
"{",
"$",
"array",
"=",
"[",
"[",
"]",
"]",
";",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"array",
")",
"===",
"1",
")",
"{",
"return",
"$",
"replace",
"(",
"$",
"str",
")",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"replace",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Composite data element
@param string $str
@return mixed | [
"Composite",
"data",
"element"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L471-L518 |
php-edifact/edifact | src/EDI/Parser.php | Parser.loadString | public function loadString(&$string): array
{
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
$string = $this->unwrap($string);
$this->rawSegments = $string;
return $this->parse($string);
} | php | public function loadString(&$string): array
{
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
$string = $this->unwrap($string);
$this->rawSegments = $string;
return $this->parse($string);
} | [
"public",
"function",
"loadString",
"(",
"&",
"$",
"string",
")",
":",
"array",
"{",
"/** @noinspection CallableParameterUseCaseInTypeContextInspection */",
"$",
"string",
"=",
"$",
"this",
"->",
"unwrap",
"(",
"$",
"string",
")",
";",
"$",
"this",
"->",
"rawSegments",
"=",
"$",
"string",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
"$",
"string",
")",
";",
"}"
] | Load the message from a string.
@param string $string
@return array | [
"Load",
"the",
"message",
"from",
"a",
"string",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Parser.php#L571-L578 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.loadMessageXml | public function loadMessageXml(string $message_xml_file): array
{
$messageXmlString = \file_get_contents($message_xml_file);
$messageXml = new \SimpleXMLIterator($messageXmlString);
unset($messageXmlString);
$message = [
"defaults" => $this->readMessageDefaults($messageXml),
"segments" => $this->readXmlNodes($messageXml),
];
unset($messageXml);
return $message;
} | php | public function loadMessageXml(string $message_xml_file): array
{
$messageXmlString = \file_get_contents($message_xml_file);
$messageXml = new \SimpleXMLIterator($messageXmlString);
unset($messageXmlString);
$message = [
"defaults" => $this->readMessageDefaults($messageXml),
"segments" => $this->readXmlNodes($messageXml),
];
unset($messageXml);
return $message;
} | [
"public",
"function",
"loadMessageXml",
"(",
"string",
"$",
"message_xml_file",
")",
":",
"array",
"{",
"$",
"messageXmlString",
"=",
"\\",
"file_get_contents",
"(",
"$",
"message_xml_file",
")",
";",
"$",
"messageXml",
"=",
"new",
"\\",
"SimpleXMLIterator",
"(",
"$",
"messageXmlString",
")",
";",
"unset",
"(",
"$",
"messageXmlString",
")",
";",
"$",
"message",
"=",
"[",
"\"defaults\"",
"=>",
"$",
"this",
"->",
"readMessageDefaults",
"(",
"$",
"messageXml",
")",
",",
"\"segments\"",
"=>",
"$",
"this",
"->",
"readXmlNodes",
"(",
"$",
"messageXml",
")",
",",
"]",
";",
"unset",
"(",
"$",
"messageXml",
")",
";",
"return",
"$",
"message",
";",
"}"
] | @param string $message_xml_file
@return array | [
"@param",
"string",
"$message_xml_file"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L22-L34 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.readMessageDefaults | protected function readMessageDefaults(\SimpleXMLElement $message): array
{
// init
$defaults = [];
/* @var \SimpleXMLElement $defaultValueNode */
foreach ($message->defaults[0] ?? [] as $defaultValueNode) {
$attributes = $defaultValueNode->attributes();
$id = (string)$attributes->id;
$defaults[$id] = (string)$attributes->value;
}
return $defaults;
} | php | protected function readMessageDefaults(\SimpleXMLElement $message): array
{
// init
$defaults = [];
/* @var \SimpleXMLElement $defaultValueNode */
foreach ($message->defaults[0] ?? [] as $defaultValueNode) {
$attributes = $defaultValueNode->attributes();
$id = (string)$attributes->id;
$defaults[$id] = (string)$attributes->value;
}
return $defaults;
} | [
"protected",
"function",
"readMessageDefaults",
"(",
"\\",
"SimpleXMLElement",
"$",
"message",
")",
":",
"array",
"{",
"// init",
"$",
"defaults",
"=",
"[",
"]",
";",
"/* @var \\SimpleXMLElement $defaultValueNode */",
"foreach",
"(",
"$",
"message",
"->",
"defaults",
"[",
"0",
"]",
"??",
"[",
"]",
"as",
"$",
"defaultValueNode",
")",
"{",
"$",
"attributes",
"=",
"$",
"defaultValueNode",
"->",
"attributes",
"(",
")",
";",
"$",
"id",
"=",
"(",
"string",
")",
"$",
"attributes",
"->",
"id",
";",
"$",
"defaults",
"[",
"$",
"id",
"]",
"=",
"(",
"string",
")",
"$",
"attributes",
"->",
"value",
";",
"}",
"return",
"$",
"defaults",
";",
"}"
] | read default values in given message xml
@param \SimpleXMLElement $message
@return array | [
"read",
"default",
"values",
"in",
"given",
"message",
"xml"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L43-L56 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.readXmlNodes | protected function readXmlNodes(\SimpleXMLElement $element): array
{
$arrayElements = [];
foreach ($element as $name => $node) {
if ($name == "defaults") {
continue;
}
$arrayElement = [];
$arrayElement["type"] = $name;
$arrayElement["attributes"] = $this->readAttributesArray($node);
$details = $this->readXmlNodes($node);
if (!empty($details)) {
$arrayElement["details"] = $details;
}
$arrayElements[] = $arrayElement;
}
return $arrayElements;
} | php | protected function readXmlNodes(\SimpleXMLElement $element): array
{
$arrayElements = [];
foreach ($element as $name => $node) {
if ($name == "defaults") {
continue;
}
$arrayElement = [];
$arrayElement["type"] = $name;
$arrayElement["attributes"] = $this->readAttributesArray($node);
$details = $this->readXmlNodes($node);
if (!empty($details)) {
$arrayElement["details"] = $details;
}
$arrayElements[] = $arrayElement;
}
return $arrayElements;
} | [
"protected",
"function",
"readXmlNodes",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
":",
"array",
"{",
"$",
"arrayElements",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"element",
"as",
"$",
"name",
"=>",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"\"defaults\"",
")",
"{",
"continue",
";",
"}",
"$",
"arrayElement",
"=",
"[",
"]",
";",
"$",
"arrayElement",
"[",
"\"type\"",
"]",
"=",
"$",
"name",
";",
"$",
"arrayElement",
"[",
"\"attributes\"",
"]",
"=",
"$",
"this",
"->",
"readAttributesArray",
"(",
"$",
"node",
")",
";",
"$",
"details",
"=",
"$",
"this",
"->",
"readXmlNodes",
"(",
"$",
"node",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"details",
")",
")",
"{",
"$",
"arrayElement",
"[",
"\"details\"",
"]",
"=",
"$",
"details",
";",
"}",
"$",
"arrayElements",
"[",
"]",
"=",
"$",
"arrayElement",
";",
"}",
"return",
"$",
"arrayElements",
";",
"}"
] | read message segments and groups
@param \SimpleXMLElement $element
@return array | [
"read",
"message",
"segments",
"and",
"groups"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L65-L83 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.readAttributesArray | protected function readAttributesArray(\SimpleXMLElement $element): array
{
$attributes = [];
foreach ($element->attributes() as $attrName => $attr) {
$attributes[(string)$attrName] = (string)$attr;
}
return $attributes;
} | php | protected function readAttributesArray(\SimpleXMLElement $element): array
{
$attributes = [];
foreach ($element->attributes() as $attrName => $attr) {
$attributes[(string)$attrName] = (string)$attr;
}
return $attributes;
} | [
"protected",
"function",
"readAttributesArray",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
":",
"array",
"{",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"element",
"->",
"attributes",
"(",
")",
"as",
"$",
"attrName",
"=>",
"$",
"attr",
")",
"{",
"$",
"attributes",
"[",
"(",
"string",
")",
"$",
"attrName",
"]",
"=",
"(",
"string",
")",
"$",
"attr",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | return an xml elements attributes in as array
@param \SimpleXMLElement $element
@return array | [
"return",
"an",
"xml",
"elements",
"attributes",
"in",
"as",
"array"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L92-L100 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.loadCodesXml | public function loadCodesXml(string $codesXml): array
{
$codesXmlString = \file_get_contents($codesXml);
$codesXml = new \SimpleXMLIterator($codesXmlString);
unset($codesXmlString);
$codes = [];
/* @var \SimpleXmlIterator $codeCollection */
foreach ($codesXml as $codeCollection) {
$id = (string)$codeCollection->attributes()->id;
$codes[$id] = [];
/* @var \SimpleXmlIterator $codeNode */
foreach ($codeCollection as $codeNode) {
$codeAttributes = $codeNode->attributes();
$code = (string)$codeAttributes->id;
$codes[$id][$code] = (string)$codeAttributes->desc;
}
}
return $codes;
} | php | public function loadCodesXml(string $codesXml): array
{
$codesXmlString = \file_get_contents($codesXml);
$codesXml = new \SimpleXMLIterator($codesXmlString);
unset($codesXmlString);
$codes = [];
/* @var \SimpleXmlIterator $codeCollection */
foreach ($codesXml as $codeCollection) {
$id = (string)$codeCollection->attributes()->id;
$codes[$id] = [];
/* @var \SimpleXmlIterator $codeNode */
foreach ($codeCollection as $codeNode) {
$codeAttributes = $codeNode->attributes();
$code = (string)$codeAttributes->id;
$codes[$id][$code] = (string)$codeAttributes->desc;
}
}
return $codes;
} | [
"public",
"function",
"loadCodesXml",
"(",
"string",
"$",
"codesXml",
")",
":",
"array",
"{",
"$",
"codesXmlString",
"=",
"\\",
"file_get_contents",
"(",
"$",
"codesXml",
")",
";",
"$",
"codesXml",
"=",
"new",
"\\",
"SimpleXMLIterator",
"(",
"$",
"codesXmlString",
")",
";",
"unset",
"(",
"$",
"codesXmlString",
")",
";",
"$",
"codes",
"=",
"[",
"]",
";",
"/* @var \\SimpleXmlIterator $codeCollection */",
"foreach",
"(",
"$",
"codesXml",
"as",
"$",
"codeCollection",
")",
"{",
"$",
"id",
"=",
"(",
"string",
")",
"$",
"codeCollection",
"->",
"attributes",
"(",
")",
"->",
"id",
";",
"$",
"codes",
"[",
"$",
"id",
"]",
"=",
"[",
"]",
";",
"/* @var \\SimpleXmlIterator $codeNode */",
"foreach",
"(",
"$",
"codeCollection",
"as",
"$",
"codeNode",
")",
"{",
"$",
"codeAttributes",
"=",
"$",
"codeNode",
"->",
"attributes",
"(",
")",
";",
"$",
"code",
"=",
"(",
"string",
")",
"$",
"codeAttributes",
"->",
"id",
";",
"$",
"codes",
"[",
"$",
"id",
"]",
"[",
"$",
"code",
"]",
"=",
"(",
"string",
")",
"$",
"codeAttributes",
"->",
"desc",
";",
"}",
"}",
"return",
"$",
"codes",
";",
"}"
] | get all data element codes
@param string $codesXml
@return array | [
"get",
"all",
"data",
"element",
"codes"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L109-L128 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.loadSegmentsXml | public function loadSegmentsXml(string $segment_xml_file): array
{
$segments_xml = \file_get_contents($segment_xml_file);
$xml = \simplexml_load_string($segments_xml);
unset($segments_xml);
$this->segments = [];
/* @var \SimpleXMLElement $segmentNode */
foreach ($xml as $segmentNode) {
$qualifier = (string)$segmentNode->attributes()->id;
$segment = [];
$segment["attributes"] = $this->readAttributesArray($segmentNode);
$details = $this->readXmlNodes($segmentNode);
if (!empty($details)) {
$segment["details"] = $details;
}
$this->segments[$qualifier] = $segment;
}
return $this->segments;
} | php | public function loadSegmentsXml(string $segment_xml_file): array
{
$segments_xml = \file_get_contents($segment_xml_file);
$xml = \simplexml_load_string($segments_xml);
unset($segments_xml);
$this->segments = [];
/* @var \SimpleXMLElement $segmentNode */
foreach ($xml as $segmentNode) {
$qualifier = (string)$segmentNode->attributes()->id;
$segment = [];
$segment["attributes"] = $this->readAttributesArray($segmentNode);
$details = $this->readXmlNodes($segmentNode);
if (!empty($details)) {
$segment["details"] = $details;
}
$this->segments[$qualifier] = $segment;
}
return $this->segments;
} | [
"public",
"function",
"loadSegmentsXml",
"(",
"string",
"$",
"segment_xml_file",
")",
":",
"array",
"{",
"$",
"segments_xml",
"=",
"\\",
"file_get_contents",
"(",
"$",
"segment_xml_file",
")",
";",
"$",
"xml",
"=",
"\\",
"simplexml_load_string",
"(",
"$",
"segments_xml",
")",
";",
"unset",
"(",
"$",
"segments_xml",
")",
";",
"$",
"this",
"->",
"segments",
"=",
"[",
"]",
";",
"/* @var \\SimpleXMLElement $segmentNode */",
"foreach",
"(",
"$",
"xml",
"as",
"$",
"segmentNode",
")",
"{",
"$",
"qualifier",
"=",
"(",
"string",
")",
"$",
"segmentNode",
"->",
"attributes",
"(",
")",
"->",
"id",
";",
"$",
"segment",
"=",
"[",
"]",
";",
"$",
"segment",
"[",
"\"attributes\"",
"]",
"=",
"$",
"this",
"->",
"readAttributesArray",
"(",
"$",
"segmentNode",
")",
";",
"$",
"details",
"=",
"$",
"this",
"->",
"readXmlNodes",
"(",
"$",
"segmentNode",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"details",
")",
")",
"{",
"$",
"segment",
"[",
"\"details\"",
"]",
"=",
"$",
"details",
";",
"}",
"$",
"this",
"->",
"segments",
"[",
"$",
"qualifier",
"]",
"=",
"$",
"segment",
";",
"}",
"return",
"$",
"this",
"->",
"segments",
";",
"}"
] | convert segment definition from XML to array. Sequence of data_elements and
composite_data_element same as in XML
@param string $segment_xml_file
@return array | [
"convert",
"segment",
"definition",
"from",
"XML",
"to",
"array",
".",
"Sequence",
"of",
"data_elements",
"and",
"composite_data_element",
"same",
"as",
"in",
"XML"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L138-L159 |
php-edifact/edifact | src/EDI/Analyser.php | Analyser.process | public function process(array $data, array $rawSegments = null): string
{
$r = [];
foreach ($data as $nrow => $segment) {
$id = $segment[0];
$r[] = '';
$jsonsegment = [];
if (isset($rawSegments[$nrow])) {
$r[] = \trim($rawSegments[$nrow]);
}
if (isset($this->segments[$id])) {
$attributes = $this->segments[$id]['attributes'];
$details_desc = $this->segments[$id]['details'];
$r[] = $id . ' - ' . $attributes['name'];
$r[] = ' (' . \wordwrap($attributes['desc'], 75, PHP_EOL . ' ') . ')';
$jsonelements = ["segmentCode" => $id];
foreach ($segment as $idx => $detail) {
$n = $idx - 1;
if ($idx == 0 || !isset($details_desc[$n])) {
continue;
}
$d_desc_attr = $details_desc[$n]['attributes'];
$l1 = ' ' . $d_desc_attr['id'] . ' - ' . $d_desc_attr['name'];
$l2 = ' ' . \wordwrap($d_desc_attr['desc'], 71, PHP_EOL . ' ');
if (\is_array($detail)) {
$r[] = ' [' . $n . '] ' . \implode(',', $detail);
$r[] = $l1;
$r[] = $l2;
$jsoncomposite = [];
if (isset($details_desc[$n]['details'])) {
$sub_details_desc = $details_desc[$n]['details'];
foreach ($detail as $d_n => $d_detail) {
$d_sub_desc_attr = $sub_details_desc[$d_n]['attributes'];
$r[] = ' [' . $d_n . '] ' . $d_detail;
$r[] = ' id: ' . $d_sub_desc_attr['id'] . ' - ' . $d_sub_desc_attr['name'];
$r[] = ' ' . \wordwrap($d_sub_desc_attr['desc'], 69, PHP_EOL . ' ');
$r[] = ' type: ' . $d_sub_desc_attr['type'];
$jsoncomposite[$d_sub_desc_attr['name']] = $d_detail;
if (isset($d_sub_desc_attr['maxlength'])) {
$r[] = ' maxlen: ' . $d_sub_desc_attr['maxlength'];
}
if (isset($d_sub_desc_attr['required'])) {
$r[] = ' required: ' . $d_sub_desc_attr['required'];
}
if (isset($d_sub_desc_attr['length'])) {
$r[] = ' length: ' . $d_sub_desc_attr['length'];
}
//check for skipped data
unset(
$d_sub_desc_attr['id'],
$d_sub_desc_attr['name'],
$d_sub_desc_attr['desc'],
$d_sub_desc_attr['type'],
$d_sub_desc_attr['maxlength'],
$d_sub_desc_attr['required'],
$d_sub_desc_attr['length']
);
/*
if (!empty($d_sub_desc_attr)) {
var_dump($d_sub_desc_attr);
}
*/
}
}
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
} else {
$r[] = ' [' . $n . '] ' . $detail;
$r[] = $l1;
$r[] = $l2;
$jsonelements[$d_desc_attr['name']] = $detail;
}
}
$jsonsegment[$attributes['name']] = $jsonelements;
} else {
$r[] = $id;
$jsonsegment["UnrecognisedType"] = $segment;
}
$this->jsonedi[] = $jsonsegment;
}
return \implode(PHP_EOL, $r);
} | php | public function process(array $data, array $rawSegments = null): string
{
$r = [];
foreach ($data as $nrow => $segment) {
$id = $segment[0];
$r[] = '';
$jsonsegment = [];
if (isset($rawSegments[$nrow])) {
$r[] = \trim($rawSegments[$nrow]);
}
if (isset($this->segments[$id])) {
$attributes = $this->segments[$id]['attributes'];
$details_desc = $this->segments[$id]['details'];
$r[] = $id . ' - ' . $attributes['name'];
$r[] = ' (' . \wordwrap($attributes['desc'], 75, PHP_EOL . ' ') . ')';
$jsonelements = ["segmentCode" => $id];
foreach ($segment as $idx => $detail) {
$n = $idx - 1;
if ($idx == 0 || !isset($details_desc[$n])) {
continue;
}
$d_desc_attr = $details_desc[$n]['attributes'];
$l1 = ' ' . $d_desc_attr['id'] . ' - ' . $d_desc_attr['name'];
$l2 = ' ' . \wordwrap($d_desc_attr['desc'], 71, PHP_EOL . ' ');
if (\is_array($detail)) {
$r[] = ' [' . $n . '] ' . \implode(',', $detail);
$r[] = $l1;
$r[] = $l2;
$jsoncomposite = [];
if (isset($details_desc[$n]['details'])) {
$sub_details_desc = $details_desc[$n]['details'];
foreach ($detail as $d_n => $d_detail) {
$d_sub_desc_attr = $sub_details_desc[$d_n]['attributes'];
$r[] = ' [' . $d_n . '] ' . $d_detail;
$r[] = ' id: ' . $d_sub_desc_attr['id'] . ' - ' . $d_sub_desc_attr['name'];
$r[] = ' ' . \wordwrap($d_sub_desc_attr['desc'], 69, PHP_EOL . ' ');
$r[] = ' type: ' . $d_sub_desc_attr['type'];
$jsoncomposite[$d_sub_desc_attr['name']] = $d_detail;
if (isset($d_sub_desc_attr['maxlength'])) {
$r[] = ' maxlen: ' . $d_sub_desc_attr['maxlength'];
}
if (isset($d_sub_desc_attr['required'])) {
$r[] = ' required: ' . $d_sub_desc_attr['required'];
}
if (isset($d_sub_desc_attr['length'])) {
$r[] = ' length: ' . $d_sub_desc_attr['length'];
}
//check for skipped data
unset(
$d_sub_desc_attr['id'],
$d_sub_desc_attr['name'],
$d_sub_desc_attr['desc'],
$d_sub_desc_attr['type'],
$d_sub_desc_attr['maxlength'],
$d_sub_desc_attr['required'],
$d_sub_desc_attr['length']
);
/*
if (!empty($d_sub_desc_attr)) {
var_dump($d_sub_desc_attr);
}
*/
}
}
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
} else {
$r[] = ' [' . $n . '] ' . $detail;
$r[] = $l1;
$r[] = $l2;
$jsonelements[$d_desc_attr['name']] = $detail;
}
}
$jsonsegment[$attributes['name']] = $jsonelements;
} else {
$r[] = $id;
$jsonsegment["UnrecognisedType"] = $segment;
}
$this->jsonedi[] = $jsonsegment;
}
return \implode(PHP_EOL, $r);
} | [
"public",
"function",
"process",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"rawSegments",
"=",
"null",
")",
":",
"string",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"nrow",
"=>",
"$",
"segment",
")",
"{",
"$",
"id",
"=",
"$",
"segment",
"[",
"0",
"]",
";",
"$",
"r",
"[",
"]",
"=",
"''",
";",
"$",
"jsonsegment",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"rawSegments",
"[",
"$",
"nrow",
"]",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"\\",
"trim",
"(",
"$",
"rawSegments",
"[",
"$",
"nrow",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"segments",
"[",
"$",
"id",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"details_desc",
"=",
"$",
"this",
"->",
"segments",
"[",
"$",
"id",
"]",
"[",
"'details'",
"]",
";",
"$",
"r",
"[",
"]",
"=",
"$",
"id",
".",
"' - '",
".",
"$",
"attributes",
"[",
"'name'",
"]",
";",
"$",
"r",
"[",
"]",
"=",
"' ('",
".",
"\\",
"wordwrap",
"(",
"$",
"attributes",
"[",
"'desc'",
"]",
",",
"75",
",",
"PHP_EOL",
".",
"' '",
")",
".",
"')'",
";",
"$",
"jsonelements",
"=",
"[",
"\"segmentCode\"",
"=>",
"$",
"id",
"]",
";",
"foreach",
"(",
"$",
"segment",
"as",
"$",
"idx",
"=>",
"$",
"detail",
")",
"{",
"$",
"n",
"=",
"$",
"idx",
"-",
"1",
";",
"if",
"(",
"$",
"idx",
"==",
"0",
"||",
"!",
"isset",
"(",
"$",
"details_desc",
"[",
"$",
"n",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"d_desc_attr",
"=",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"l1",
"=",
"' '",
".",
"$",
"d_desc_attr",
"[",
"'id'",
"]",
".",
"' - '",
".",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
";",
"$",
"l2",
"=",
"' '",
".",
"\\",
"wordwrap",
"(",
"$",
"d_desc_attr",
"[",
"'desc'",
"]",
",",
"71",
",",
"PHP_EOL",
".",
"' '",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"detail",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"' ['",
".",
"$",
"n",
".",
"'] '",
".",
"\\",
"implode",
"(",
"','",
",",
"$",
"detail",
")",
";",
"$",
"r",
"[",
"]",
"=",
"$",
"l1",
";",
"$",
"r",
"[",
"]",
"=",
"$",
"l2",
";",
"$",
"jsoncomposite",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'details'",
"]",
")",
")",
"{",
"$",
"sub_details_desc",
"=",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'details'",
"]",
";",
"foreach",
"(",
"$",
"detail",
"as",
"$",
"d_n",
"=>",
"$",
"d_detail",
")",
"{",
"$",
"d_sub_desc_attr",
"=",
"$",
"sub_details_desc",
"[",
"$",
"d_n",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"r",
"[",
"]",
"=",
"' ['",
".",
"$",
"d_n",
".",
"'] '",
".",
"$",
"d_detail",
";",
"$",
"r",
"[",
"]",
"=",
"' id: '",
".",
"$",
"d_sub_desc_attr",
"[",
"'id'",
"]",
".",
"' - '",
".",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
";",
"$",
"r",
"[",
"]",
"=",
"' '",
".",
"\\",
"wordwrap",
"(",
"$",
"d_sub_desc_attr",
"[",
"'desc'",
"]",
",",
"69",
",",
"PHP_EOL",
".",
"' '",
")",
";",
"$",
"r",
"[",
"]",
"=",
"' type: '",
".",
"$",
"d_sub_desc_attr",
"[",
"'type'",
"]",
";",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"d_detail",
";",
"if",
"(",
"isset",
"(",
"$",
"d_sub_desc_attr",
"[",
"'maxlength'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"' maxlen: '",
".",
"$",
"d_sub_desc_attr",
"[",
"'maxlength'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"d_sub_desc_attr",
"[",
"'required'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"' required: '",
".",
"$",
"d_sub_desc_attr",
"[",
"'required'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"d_sub_desc_attr",
"[",
"'length'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"' length: '",
".",
"$",
"d_sub_desc_attr",
"[",
"'length'",
"]",
";",
"}",
"//check for skipped data",
"unset",
"(",
"$",
"d_sub_desc_attr",
"[",
"'id'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'desc'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'type'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'maxlength'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'required'",
"]",
",",
"$",
"d_sub_desc_attr",
"[",
"'length'",
"]",
")",
";",
"/*\n if (!empty($d_sub_desc_attr)) {\n var_dump($d_sub_desc_attr);\n }\n */",
"}",
"}",
"$",
"jsonelements",
"[",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"jsoncomposite",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"]",
"=",
"' ['",
".",
"$",
"n",
".",
"'] '",
".",
"$",
"detail",
";",
"$",
"r",
"[",
"]",
"=",
"$",
"l1",
";",
"$",
"r",
"[",
"]",
"=",
"$",
"l2",
";",
"$",
"jsonelements",
"[",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"detail",
";",
"}",
"}",
"$",
"jsonsegment",
"[",
"$",
"attributes",
"[",
"'name'",
"]",
"]",
"=",
"$",
"jsonelements",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"]",
"=",
"$",
"id",
";",
"$",
"jsonsegment",
"[",
"\"UnrecognisedType\"",
"]",
"=",
"$",
"segment",
";",
"}",
"$",
"this",
"->",
"jsonedi",
"[",
"]",
"=",
"$",
"jsonsegment",
";",
"}",
"return",
"\\",
"implode",
"(",
"PHP_EOL",
",",
"$",
"r",
")",
";",
"}"
] | create readable EDI MESSAGE with comments
@param array $data by EDI\Parser:parse() created array from plain EDI message
@param array $rawSegments (optional) List of raw segments from EDI\Parser::getRawSegments
@return string file | [
"create",
"readable",
"EDI",
"MESSAGE",
"with",
"comments"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Analyser.php#L169-L263 |
php-edifact/edifact | src/EDI/Encoder.php | Encoder.encode | public function encode(array $array, $wrap = true, $filterKeys = false): string
{
$this->originalArray = $array;
$this->wrap = $wrap;
$edistring = '';
$count = \count($array);
$k = 0;
foreach ($array as $row) {
$k++;
if ($filterKeys) {
unset($row['segmentIdx']);
}
$row = \array_values($row);
$edistring .= $this->encodeSegment($row);
if (!$wrap && $k < $count) {
$edistring .= "\n";
}
}
$this->output = $edistring;
return $edistring;
} | php | public function encode(array $array, $wrap = true, $filterKeys = false): string
{
$this->originalArray = $array;
$this->wrap = $wrap;
$edistring = '';
$count = \count($array);
$k = 0;
foreach ($array as $row) {
$k++;
if ($filterKeys) {
unset($row['segmentIdx']);
}
$row = \array_values($row);
$edistring .= $this->encodeSegment($row);
if (!$wrap && $k < $count) {
$edistring .= "\n";
}
}
$this->output = $edistring;
return $edistring;
} | [
"public",
"function",
"encode",
"(",
"array",
"$",
"array",
",",
"$",
"wrap",
"=",
"true",
",",
"$",
"filterKeys",
"=",
"false",
")",
":",
"string",
"{",
"$",
"this",
"->",
"originalArray",
"=",
"$",
"array",
";",
"$",
"this",
"->",
"wrap",
"=",
"$",
"wrap",
";",
"$",
"edistring",
"=",
"''",
";",
"$",
"count",
"=",
"\\",
"count",
"(",
"$",
"array",
")",
";",
"$",
"k",
"=",
"0",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"k",
"++",
";",
"if",
"(",
"$",
"filterKeys",
")",
"{",
"unset",
"(",
"$",
"row",
"[",
"'segmentIdx'",
"]",
")",
";",
"}",
"$",
"row",
"=",
"\\",
"array_values",
"(",
"$",
"row",
")",
";",
"$",
"edistring",
".=",
"$",
"this",
"->",
"encodeSegment",
"(",
"$",
"row",
")",
";",
"if",
"(",
"!",
"$",
"wrap",
"&&",
"$",
"k",
"<",
"$",
"count",
")",
"{",
"$",
"edistring",
".=",
"\"\\n\"",
";",
"}",
"}",
"$",
"this",
"->",
"output",
"=",
"$",
"edistring",
";",
"return",
"$",
"edistring",
";",
"}"
] | @param array $array
@param bool $wrap
@param bool $filterKeys
@return string | [
"@param",
"array",
"$array",
"@param",
"bool",
"$wrap",
"@param",
"bool",
"$filterKeys"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Encoder.php#L87-L109 |
php-edifact/edifact | src/EDI/Encoder.php | Encoder.encodeSegment | public function encodeSegment(array $row): string
{
// init
$str = '';
$t = \count($row);
foreach ($row as $i => &$iValue) {
if (\is_array($iValue)) {
if (\count($iValue) === 1
&& \is_array(\reset($iValue))
) {
$iValue = \array_pop($iValue);
}
if (\is_array($iValue)) {
foreach ($iValue as &$temp) {
$temp = $this->escapeValue($temp);
}
unset($temp);
}
$elm = \implode($this->sepComp, $iValue);
} else {
$elm = $this->escapeValue($iValue);
}
$str .= $elm;
if ($i == $t - 1) {
break;
}
$str .= $this->sepData;
}
unset($iValue);
$str .= $this->symbEnd;
return $str;
} | php | public function encodeSegment(array $row): string
{
// init
$str = '';
$t = \count($row);
foreach ($row as $i => &$iValue) {
if (\is_array($iValue)) {
if (\count($iValue) === 1
&& \is_array(\reset($iValue))
) {
$iValue = \array_pop($iValue);
}
if (\is_array($iValue)) {
foreach ($iValue as &$temp) {
$temp = $this->escapeValue($temp);
}
unset($temp);
}
$elm = \implode($this->sepComp, $iValue);
} else {
$elm = $this->escapeValue($iValue);
}
$str .= $elm;
if ($i == $t - 1) {
break;
}
$str .= $this->sepData;
}
unset($iValue);
$str .= $this->symbEnd;
return $str;
} | [
"public",
"function",
"encodeSegment",
"(",
"array",
"$",
"row",
")",
":",
"string",
"{",
"// init",
"$",
"str",
"=",
"''",
";",
"$",
"t",
"=",
"\\",
"count",
"(",
"$",
"row",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"i",
"=>",
"&",
"$",
"iValue",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"iValue",
")",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"iValue",
")",
"===",
"1",
"&&",
"\\",
"is_array",
"(",
"\\",
"reset",
"(",
"$",
"iValue",
")",
")",
")",
"{",
"$",
"iValue",
"=",
"\\",
"array_pop",
"(",
"$",
"iValue",
")",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"iValue",
")",
")",
"{",
"foreach",
"(",
"$",
"iValue",
"as",
"&",
"$",
"temp",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"temp",
")",
";",
"}",
"unset",
"(",
"$",
"temp",
")",
";",
"}",
"$",
"elm",
"=",
"\\",
"implode",
"(",
"$",
"this",
"->",
"sepComp",
",",
"$",
"iValue",
")",
";",
"}",
"else",
"{",
"$",
"elm",
"=",
"$",
"this",
"->",
"escapeValue",
"(",
"$",
"iValue",
")",
";",
"}",
"$",
"str",
".=",
"$",
"elm",
";",
"if",
"(",
"$",
"i",
"==",
"$",
"t",
"-",
"1",
")",
"{",
"break",
";",
"}",
"$",
"str",
".=",
"$",
"this",
"->",
"sepData",
";",
"}",
"unset",
"(",
"$",
"iValue",
")",
";",
"$",
"str",
".=",
"$",
"this",
"->",
"symbEnd",
";",
"return",
"$",
"str",
";",
"}"
] | @param array $row
@return string | [
"@param",
"array",
"$row"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Encoder.php#L116-L153 |
php-edifact/edifact | src/EDI/Encoder.php | Encoder.escapeValue | private function escapeValue(&$str): string
{
$search = [
$this->symbRel,
$this->sepComp,
$this->sepData,
$this->symbEnd,
];
$replace = [
$this->symbRel . $this->symbRel,
$this->symbRel . $this->sepComp,
$this->symbRel . $this->sepData,
$this->symbRel . $this->symbEnd,
];
return \str_replace($search, $replace, $str);
} | php | private function escapeValue(&$str): string
{
$search = [
$this->symbRel,
$this->sepComp,
$this->sepData,
$this->symbEnd,
];
$replace = [
$this->symbRel . $this->symbRel,
$this->symbRel . $this->sepComp,
$this->symbRel . $this->sepData,
$this->symbRel . $this->symbEnd,
];
return \str_replace($search, $replace, $str);
} | [
"private",
"function",
"escapeValue",
"(",
"&",
"$",
"str",
")",
":",
"string",
"{",
"$",
"search",
"=",
"[",
"$",
"this",
"->",
"symbRel",
",",
"$",
"this",
"->",
"sepComp",
",",
"$",
"this",
"->",
"sepData",
",",
"$",
"this",
"->",
"symbEnd",
",",
"]",
";",
"$",
"replace",
"=",
"[",
"$",
"this",
"->",
"symbRel",
".",
"$",
"this",
"->",
"symbRel",
",",
"$",
"this",
"->",
"symbRel",
".",
"$",
"this",
"->",
"sepComp",
",",
"$",
"this",
"->",
"symbRel",
".",
"$",
"this",
"->",
"sepData",
",",
"$",
"this",
"->",
"symbRel",
".",
"$",
"this",
"->",
"symbEnd",
",",
"]",
";",
"return",
"\\",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"str",
")",
";",
"}"
] | @param string|int $str
@return string | [
"@param",
"string|int",
"$str"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Encoder.php#L160-L176 |
php-edifact/edifact | src/EDI/Encoder.php | Encoder.setUNA | public function setUNA(string $chars, bool $user_call = true): bool
{
if (\is_string($chars)
&& \strlen($chars) == 6
) {
$this->sepComp = $chars[0];
$this->sepData = $chars[1];
$this->sepDec = $chars[2];
$this->symbRel = $chars[3];
$this->symbRep = $chars[4];
$this->symbEnd = $chars[5];
if ($user_call) {
$this->enableUNA();
}
if ($this->output != '') {
$this->output = $this->encode($this->originalArray);
}
return true;
}
return false;
} | php | public function setUNA(string $chars, bool $user_call = true): bool
{
if (\is_string($chars)
&& \strlen($chars) == 6
) {
$this->sepComp = $chars[0];
$this->sepData = $chars[1];
$this->sepDec = $chars[2];
$this->symbRel = $chars[3];
$this->symbRep = $chars[4];
$this->symbEnd = $chars[5];
if ($user_call) {
$this->enableUNA();
}
if ($this->output != '') {
$this->output = $this->encode($this->originalArray);
}
return true;
}
return false;
} | [
"public",
"function",
"setUNA",
"(",
"string",
"$",
"chars",
",",
"bool",
"$",
"user_call",
"=",
"true",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"chars",
")",
"&&",
"\\",
"strlen",
"(",
"$",
"chars",
")",
"==",
"6",
")",
"{",
"$",
"this",
"->",
"sepComp",
"=",
"$",
"chars",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"sepData",
"=",
"$",
"chars",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"sepDec",
"=",
"$",
"chars",
"[",
"2",
"]",
";",
"$",
"this",
"->",
"symbRel",
"=",
"$",
"chars",
"[",
"3",
"]",
";",
"$",
"this",
"->",
"symbRep",
"=",
"$",
"chars",
"[",
"4",
"]",
";",
"$",
"this",
"->",
"symbEnd",
"=",
"$",
"chars",
"[",
"5",
"]",
";",
"if",
"(",
"$",
"user_call",
")",
"{",
"$",
"this",
"->",
"enableUNA",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"output",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"this",
"->",
"originalArray",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | @param string $chars
@param bool $user_call
@return bool | [
"@param",
"string",
"$chars",
"@param",
"bool",
"$user_call"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Encoder.php#L206-L230 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.prepare | public function prepare(array $parsed): array
{
$this->msgs = $this->splitMessages($parsed, $this->errors);
$groups = [];
$service = $this->msgs['service'];
$this->serviceSeg = $this->processService($service);
foreach ($this->msgs as $k => $msg) {
if ($k === 'service') {
continue;
}
$grouped = $this->loopMessage($msg, $this->xmlMsg, $this->errors);
$groups[] = $grouped['message'];
}
$this->ediGroups = $groups;
return $groups;
} | php | public function prepare(array $parsed): array
{
$this->msgs = $this->splitMessages($parsed, $this->errors);
$groups = [];
$service = $this->msgs['service'];
$this->serviceSeg = $this->processService($service);
foreach ($this->msgs as $k => $msg) {
if ($k === 'service') {
continue;
}
$grouped = $this->loopMessage($msg, $this->xmlMsg, $this->errors);
$groups[] = $grouped['message'];
}
$this->ediGroups = $groups;
return $groups;
} | [
"public",
"function",
"prepare",
"(",
"array",
"$",
"parsed",
")",
":",
"array",
"{",
"$",
"this",
"->",
"msgs",
"=",
"$",
"this",
"->",
"splitMessages",
"(",
"$",
"parsed",
",",
"$",
"this",
"->",
"errors",
")",
";",
"$",
"groups",
"=",
"[",
"]",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"msgs",
"[",
"'service'",
"]",
";",
"$",
"this",
"->",
"serviceSeg",
"=",
"$",
"this",
"->",
"processService",
"(",
"$",
"service",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"msgs",
"as",
"$",
"k",
"=>",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"k",
"===",
"'service'",
")",
"{",
"continue",
";",
"}",
"$",
"grouped",
"=",
"$",
"this",
"->",
"loopMessage",
"(",
"$",
"msg",
",",
"$",
"this",
"->",
"xmlMsg",
",",
"$",
"this",
"->",
"errors",
")",
";",
"$",
"groups",
"[",
"]",
"=",
"$",
"grouped",
"[",
"'message'",
"]",
";",
"}",
"$",
"this",
"->",
"ediGroups",
"=",
"$",
"groups",
";",
"return",
"$",
"groups",
";",
"}"
] | Split multiple messages and process
@param array $parsed An array coming from EDI\Parser
@return array | [
"Split",
"multiple",
"messages",
"and",
"process"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L161-L178 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.splitMessages | private function splitMessages(&$parsed, &$errors): array
{
// init
$messages = [];
$tmpmsg = [];
$service = [];
$hasInterchangeDelimiters = 0;
$hasMessageDelimiters = 0;
foreach ($parsed as $c => $segment) {
switch ($segment[0]) {
case 'UNB':
$hasInterchangeDelimiters = 0;
$hasInterchangeDelimiters++;
$service['UNB'] = $segment;
break;
case 'UNZ':
$hasInterchangeDelimiters--;
if ($hasInterchangeDelimiters != 0) {
$sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ";
$errors[] = [
"text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'],
"position" => $c,
"segmentId" => $sid,
];
}
$service['UNZ'] = $segment;
break;
case 'UNH':
$hasMessageDelimiters = 0;
$hasMessageDelimiters++;
$tmpmsg = [$segment];
break;
case 'UNT':
$hasMessageDelimiters--;
$tmpmsg[] = $segment;
$messages[] = $tmpmsg;
if ($hasMessageDelimiters != 0) {
$sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT";
$errors[] = [
"text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'],
"position" => $c,
"segmentId" => $sid,
];
}
break;
default:
$tmpmsg[] = $segment;
break;
}
}
if ($hasInterchangeDelimiters != 0) {
$sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ";
$errors[] = [
"text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'],
"position" => $c ?? '',
"segmentId" => $sid,
];
}
if ($hasMessageDelimiters != 0) {
$sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT";
$errors[] = [
"text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'],
"position" => $c ?? '',
"segmentId" => $sid,
];
}
$messages['service'] = $service;
return $messages;
} | php | private function splitMessages(&$parsed, &$errors): array
{
// init
$messages = [];
$tmpmsg = [];
$service = [];
$hasInterchangeDelimiters = 0;
$hasMessageDelimiters = 0;
foreach ($parsed as $c => $segment) {
switch ($segment[0]) {
case 'UNB':
$hasInterchangeDelimiters = 0;
$hasInterchangeDelimiters++;
$service['UNB'] = $segment;
break;
case 'UNZ':
$hasInterchangeDelimiters--;
if ($hasInterchangeDelimiters != 0) {
$sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ";
$errors[] = [
"text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'],
"position" => $c,
"segmentId" => $sid,
];
}
$service['UNZ'] = $segment;
break;
case 'UNH':
$hasMessageDelimiters = 0;
$hasMessageDelimiters++;
$tmpmsg = [$segment];
break;
case 'UNT':
$hasMessageDelimiters--;
$tmpmsg[] = $segment;
$messages[] = $tmpmsg;
if ($hasMessageDelimiters != 0) {
$sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT";
$errors[] = [
"text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'],
"position" => $c,
"segmentId" => $sid,
];
}
break;
default:
$tmpmsg[] = $segment;
break;
}
}
if ($hasInterchangeDelimiters != 0) {
$sid = ($hasInterchangeDelimiters < 0) ? "UNB" : "UNZ";
$errors[] = [
"text" => $this->messageTextConf['MISSINGINTERCHANGEDELIMITER'],
"position" => $c ?? '',
"segmentId" => $sid,
];
}
if ($hasMessageDelimiters != 0) {
$sid = ($hasMessageDelimiters < 0) ? "UNH" : "UNT";
$errors[] = [
"text" => $this->messageTextConf['MISSINGMESSAGEDELIMITER'],
"position" => $c ?? '',
"segmentId" => $sid,
];
}
$messages['service'] = $service;
return $messages;
} | [
"private",
"function",
"splitMessages",
"(",
"&",
"$",
"parsed",
",",
"&",
"$",
"errors",
")",
":",
"array",
"{",
"// init",
"$",
"messages",
"=",
"[",
"]",
";",
"$",
"tmpmsg",
"=",
"[",
"]",
";",
"$",
"service",
"=",
"[",
"]",
";",
"$",
"hasInterchangeDelimiters",
"=",
"0",
";",
"$",
"hasMessageDelimiters",
"=",
"0",
";",
"foreach",
"(",
"$",
"parsed",
"as",
"$",
"c",
"=>",
"$",
"segment",
")",
"{",
"switch",
"(",
"$",
"segment",
"[",
"0",
"]",
")",
"{",
"case",
"'UNB'",
":",
"$",
"hasInterchangeDelimiters",
"=",
"0",
";",
"$",
"hasInterchangeDelimiters",
"++",
";",
"$",
"service",
"[",
"'UNB'",
"]",
"=",
"$",
"segment",
";",
"break",
";",
"case",
"'UNZ'",
":",
"$",
"hasInterchangeDelimiters",
"--",
";",
"if",
"(",
"$",
"hasInterchangeDelimiters",
"!=",
"0",
")",
"{",
"$",
"sid",
"=",
"(",
"$",
"hasInterchangeDelimiters",
"<",
"0",
")",
"?",
"\"UNB\"",
":",
"\"UNZ\"",
";",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGINTERCHANGEDELIMITER'",
"]",
",",
"\"position\"",
"=>",
"$",
"c",
",",
"\"segmentId\"",
"=>",
"$",
"sid",
",",
"]",
";",
"}",
"$",
"service",
"[",
"'UNZ'",
"]",
"=",
"$",
"segment",
";",
"break",
";",
"case",
"'UNH'",
":",
"$",
"hasMessageDelimiters",
"=",
"0",
";",
"$",
"hasMessageDelimiters",
"++",
";",
"$",
"tmpmsg",
"=",
"[",
"$",
"segment",
"]",
";",
"break",
";",
"case",
"'UNT'",
":",
"$",
"hasMessageDelimiters",
"--",
";",
"$",
"tmpmsg",
"[",
"]",
"=",
"$",
"segment",
";",
"$",
"messages",
"[",
"]",
"=",
"$",
"tmpmsg",
";",
"if",
"(",
"$",
"hasMessageDelimiters",
"!=",
"0",
")",
"{",
"$",
"sid",
"=",
"(",
"$",
"hasMessageDelimiters",
"<",
"0",
")",
"?",
"\"UNH\"",
":",
"\"UNT\"",
";",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGMESSAGEDELIMITER'",
"]",
",",
"\"position\"",
"=>",
"$",
"c",
",",
"\"segmentId\"",
"=>",
"$",
"sid",
",",
"]",
";",
"}",
"break",
";",
"default",
":",
"$",
"tmpmsg",
"[",
"]",
"=",
"$",
"segment",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"hasInterchangeDelimiters",
"!=",
"0",
")",
"{",
"$",
"sid",
"=",
"(",
"$",
"hasInterchangeDelimiters",
"<",
"0",
")",
"?",
"\"UNB\"",
":",
"\"UNZ\"",
";",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGINTERCHANGEDELIMITER'",
"]",
",",
"\"position\"",
"=>",
"$",
"c",
"??",
"''",
",",
"\"segmentId\"",
"=>",
"$",
"sid",
",",
"]",
";",
"}",
"if",
"(",
"$",
"hasMessageDelimiters",
"!=",
"0",
")",
"{",
"$",
"sid",
"=",
"(",
"$",
"hasMessageDelimiters",
"<",
"0",
")",
"?",
"\"UNH\"",
":",
"\"UNT\"",
";",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGMESSAGEDELIMITER'",
"]",
",",
"\"position\"",
"=>",
"$",
"c",
"??",
"''",
",",
"\"segmentId\"",
"=>",
"$",
"sid",
",",
"]",
";",
"}",
"$",
"messages",
"[",
"'service'",
"]",
"=",
"$",
"service",
";",
"return",
"$",
"messages",
";",
"}"
] | Split multiple messages
@param array $parsed An array coming from EDI\Parser
@param array $errors
@return array | [
"Split",
"multiple",
"messages"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L188-L261 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.loopMessage | private function loopMessage(array &$message, \SimpleXMLElement $xml, array &$errors): array
{
// init
$groupedEdi = [];
$segmentIdx = 0;
foreach ($xml->children() as $elm) {
if ($elm->getName() == "group") {
$this->processXmlGroup($elm, $message, $segmentIdx, $groupedEdi, $errors);
} elseif ($elm->getName() == "segment") {
$this->processXmlSegment($elm, $message, $segmentIdx, $groupedEdi, $errors);
}
}
if ($segmentIdx != \count($message)) {
$errors[] = [
"text" => $this->messageTextConf['NOTCONFORMANT'],
];
}
return ['message' => $groupedEdi, 'errors' => $errors];
} | php | private function loopMessage(array &$message, \SimpleXMLElement $xml, array &$errors): array
{
// init
$groupedEdi = [];
$segmentIdx = 0;
foreach ($xml->children() as $elm) {
if ($elm->getName() == "group") {
$this->processXmlGroup($elm, $message, $segmentIdx, $groupedEdi, $errors);
} elseif ($elm->getName() == "segment") {
$this->processXmlSegment($elm, $message, $segmentIdx, $groupedEdi, $errors);
}
}
if ($segmentIdx != \count($message)) {
$errors[] = [
"text" => $this->messageTextConf['NOTCONFORMANT'],
];
}
return ['message' => $groupedEdi, 'errors' => $errors];
} | [
"private",
"function",
"loopMessage",
"(",
"array",
"&",
"$",
"message",
",",
"\\",
"SimpleXMLElement",
"$",
"xml",
",",
"array",
"&",
"$",
"errors",
")",
":",
"array",
"{",
"// init",
"$",
"groupedEdi",
"=",
"[",
"]",
";",
"$",
"segmentIdx",
"=",
"0",
";",
"foreach",
"(",
"$",
"xml",
"->",
"children",
"(",
")",
"as",
"$",
"elm",
")",
"{",
"if",
"(",
"$",
"elm",
"->",
"getName",
"(",
")",
"==",
"\"group\"",
")",
"{",
"$",
"this",
"->",
"processXmlGroup",
"(",
"$",
"elm",
",",
"$",
"message",
",",
"$",
"segmentIdx",
",",
"$",
"groupedEdi",
",",
"$",
"errors",
")",
";",
"}",
"elseif",
"(",
"$",
"elm",
"->",
"getName",
"(",
")",
"==",
"\"segment\"",
")",
"{",
"$",
"this",
"->",
"processXmlSegment",
"(",
"$",
"elm",
",",
"$",
"message",
",",
"$",
"segmentIdx",
",",
"$",
"groupedEdi",
",",
"$",
"errors",
")",
";",
"}",
"}",
"if",
"(",
"$",
"segmentIdx",
"!=",
"\\",
"count",
"(",
"$",
"message",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'NOTCONFORMANT'",
"]",
",",
"]",
";",
"}",
"return",
"[",
"'message'",
"=>",
"$",
"groupedEdi",
",",
"'errors'",
"=>",
"$",
"errors",
"]",
";",
"}"
] | Transform a parsed edi in its groupings
@param array $message Single message (Without UNB and UNZ)
@param \SimpleXMLElement $xml The xml representation of the message
@param array $errors
@return array | [
"Transform",
"a",
"parsed",
"edi",
"in",
"its",
"groupings"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L272-L293 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.processXmlGroup | private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$segmentIdx, array &$array, array &$errors)
{
// init
$groupVisited = false;
$newGroup = [];
for ($g = 0; $g < $elm['maxrepeat']; $g++) {
$grouptemp = [];
if ($message[$segmentIdx][0] != $elm->children()[0]['id']) {
if (
!$groupVisited
&&
isset($elm['required'])
) {
$elmType = $elm['id']->__toString();
$fixed = false;
if (isset($this->groupTemplates[$elmType])) {
\array_splice($message, $segmentIdx, 0, $this->groupTemplates[$elmType]);
$fixed = true;
}
$errors[] = [
"text" => $this->messageTextConf['MISSINGREQUIREDGROUP'] . " " . ($fixed ? '(patched)' : ''),
"position" => $segmentIdx,
"segmentId" => $elmType,
];
} else {
break;
}
}
foreach ($elm->children() as $elm2) {
if ($elm2->getName() == "group") {
$this->processXmlGroup($elm2, $message, $segmentIdx, $grouptemp, $errors);
} else {
$this->processXmlSegment($elm2, $message, $segmentIdx, $grouptemp, $errors);
}
$groupVisited = true;
}
$newGroup[] = $grouptemp;
}
if (\count($newGroup) === 0) {
return;
}
$array[$elm['id']->__toString()] = $newGroup;
} | php | private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$segmentIdx, array &$array, array &$errors)
{
// init
$groupVisited = false;
$newGroup = [];
for ($g = 0; $g < $elm['maxrepeat']; $g++) {
$grouptemp = [];
if ($message[$segmentIdx][0] != $elm->children()[0]['id']) {
if (
!$groupVisited
&&
isset($elm['required'])
) {
$elmType = $elm['id']->__toString();
$fixed = false;
if (isset($this->groupTemplates[$elmType])) {
\array_splice($message, $segmentIdx, 0, $this->groupTemplates[$elmType]);
$fixed = true;
}
$errors[] = [
"text" => $this->messageTextConf['MISSINGREQUIREDGROUP'] . " " . ($fixed ? '(patched)' : ''),
"position" => $segmentIdx,
"segmentId" => $elmType,
];
} else {
break;
}
}
foreach ($elm->children() as $elm2) {
if ($elm2->getName() == "group") {
$this->processXmlGroup($elm2, $message, $segmentIdx, $grouptemp, $errors);
} else {
$this->processXmlSegment($elm2, $message, $segmentIdx, $grouptemp, $errors);
}
$groupVisited = true;
}
$newGroup[] = $grouptemp;
}
if (\count($newGroup) === 0) {
return;
}
$array[$elm['id']->__toString()] = $newGroup;
} | [
"private",
"function",
"processXmlGroup",
"(",
"\\",
"SimpleXMLElement",
"$",
"elm",
",",
"array",
"&",
"$",
"message",
",",
"int",
"&",
"$",
"segmentIdx",
",",
"array",
"&",
"$",
"array",
",",
"array",
"&",
"$",
"errors",
")",
"{",
"// init",
"$",
"groupVisited",
"=",
"false",
";",
"$",
"newGroup",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"g",
"=",
"0",
";",
"$",
"g",
"<",
"$",
"elm",
"[",
"'maxrepeat'",
"]",
";",
"$",
"g",
"++",
")",
"{",
"$",
"grouptemp",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"message",
"[",
"$",
"segmentIdx",
"]",
"[",
"0",
"]",
"!=",
"$",
"elm",
"->",
"children",
"(",
")",
"[",
"0",
"]",
"[",
"'id'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"groupVisited",
"&&",
"isset",
"(",
"$",
"elm",
"[",
"'required'",
"]",
")",
")",
"{",
"$",
"elmType",
"=",
"$",
"elm",
"[",
"'id'",
"]",
"->",
"__toString",
"(",
")",
";",
"$",
"fixed",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"groupTemplates",
"[",
"$",
"elmType",
"]",
")",
")",
"{",
"\\",
"array_splice",
"(",
"$",
"message",
",",
"$",
"segmentIdx",
",",
"0",
",",
"$",
"this",
"->",
"groupTemplates",
"[",
"$",
"elmType",
"]",
")",
";",
"$",
"fixed",
"=",
"true",
";",
"}",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGREQUIREDGROUP'",
"]",
".",
"\" \"",
".",
"(",
"$",
"fixed",
"?",
"'(patched)'",
":",
"''",
")",
",",
"\"position\"",
"=>",
"$",
"segmentIdx",
",",
"\"segmentId\"",
"=>",
"$",
"elmType",
",",
"]",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"foreach",
"(",
"$",
"elm",
"->",
"children",
"(",
")",
"as",
"$",
"elm2",
")",
"{",
"if",
"(",
"$",
"elm2",
"->",
"getName",
"(",
")",
"==",
"\"group\"",
")",
"{",
"$",
"this",
"->",
"processXmlGroup",
"(",
"$",
"elm2",
",",
"$",
"message",
",",
"$",
"segmentIdx",
",",
"$",
"grouptemp",
",",
"$",
"errors",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"processXmlSegment",
"(",
"$",
"elm2",
",",
"$",
"message",
",",
"$",
"segmentIdx",
",",
"$",
"grouptemp",
",",
"$",
"errors",
")",
";",
"}",
"$",
"groupVisited",
"=",
"true",
";",
"}",
"$",
"newGroup",
"[",
"]",
"=",
"$",
"grouptemp",
";",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"newGroup",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"array",
"[",
"$",
"elm",
"[",
"'id'",
"]",
"->",
"__toString",
"(",
")",
"]",
"=",
"$",
"newGroup",
";",
"}"
] | Process an XML Group
@param \SimpleXMLElement $elm
@param array $message
@param int $segmentIdx
@param array $array
@param array $errors
@return void | [
"Process",
"an",
"XML",
"Group"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L306-L355 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.processXmlSegment | private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int &$segmentIdx, array &$array, array &$errors)
{
// init
$segmentVisited = false;
for ($i = 0; $i < $elm['maxrepeat']; $i++) {
if (\call_user_func($this->comparisonFunction, $message[$segmentIdx], $elm)) {
$jsonMessage = $this->processSegment($message[$segmentIdx], $this->xmlSeg, $segmentIdx, $errors);
$segmentVisited = true;
$this->doAddArray($array, $jsonMessage);
$segmentIdx++;
} else {
if (!$segmentVisited && isset($elm['required'])) {
$fixed = false;
if ($elm['replacewith'] !== null) {
$elmType = (string)$elm['replacewith'];
} else {
$elmType = (string)$elm['id'];
}
if (isset($this->segmentTemplates[$elmType])) {
$jsonMessage = $this->processSegment($this->segmentTemplates[$elmType], $this->xmlSeg, $segmentIdx, $errors);
$fixed = true;
$this->doAddArray($array, $jsonMessage);
}
$errors[] = [
"text" => $this->messageTextConf['MISSINGREQUIREDSEGMENT'] . " " . ($fixed ? '(patched)' : ''),
"position" => $segmentIdx,
"segmentId" => (string)$elm['id'],
];
}
return;
}
}
} | php | private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int &$segmentIdx, array &$array, array &$errors)
{
// init
$segmentVisited = false;
for ($i = 0; $i < $elm['maxrepeat']; $i++) {
if (\call_user_func($this->comparisonFunction, $message[$segmentIdx], $elm)) {
$jsonMessage = $this->processSegment($message[$segmentIdx], $this->xmlSeg, $segmentIdx, $errors);
$segmentVisited = true;
$this->doAddArray($array, $jsonMessage);
$segmentIdx++;
} else {
if (!$segmentVisited && isset($elm['required'])) {
$fixed = false;
if ($elm['replacewith'] !== null) {
$elmType = (string)$elm['replacewith'];
} else {
$elmType = (string)$elm['id'];
}
if (isset($this->segmentTemplates[$elmType])) {
$jsonMessage = $this->processSegment($this->segmentTemplates[$elmType], $this->xmlSeg, $segmentIdx, $errors);
$fixed = true;
$this->doAddArray($array, $jsonMessage);
}
$errors[] = [
"text" => $this->messageTextConf['MISSINGREQUIREDSEGMENT'] . " " . ($fixed ? '(patched)' : ''),
"position" => $segmentIdx,
"segmentId" => (string)$elm['id'],
];
}
return;
}
}
} | [
"private",
"function",
"processXmlSegment",
"(",
"\\",
"SimpleXMLElement",
"$",
"elm",
",",
"array",
"&",
"$",
"message",
",",
"int",
"&",
"$",
"segmentIdx",
",",
"array",
"&",
"$",
"array",
",",
"array",
"&",
"$",
"errors",
")",
"{",
"// init",
"$",
"segmentVisited",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elm",
"[",
"'maxrepeat'",
"]",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"\\",
"call_user_func",
"(",
"$",
"this",
"->",
"comparisonFunction",
",",
"$",
"message",
"[",
"$",
"segmentIdx",
"]",
",",
"$",
"elm",
")",
")",
"{",
"$",
"jsonMessage",
"=",
"$",
"this",
"->",
"processSegment",
"(",
"$",
"message",
"[",
"$",
"segmentIdx",
"]",
",",
"$",
"this",
"->",
"xmlSeg",
",",
"$",
"segmentIdx",
",",
"$",
"errors",
")",
";",
"$",
"segmentVisited",
"=",
"true",
";",
"$",
"this",
"->",
"doAddArray",
"(",
"$",
"array",
",",
"$",
"jsonMessage",
")",
";",
"$",
"segmentIdx",
"++",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"segmentVisited",
"&&",
"isset",
"(",
"$",
"elm",
"[",
"'required'",
"]",
")",
")",
"{",
"$",
"fixed",
"=",
"false",
";",
"if",
"(",
"$",
"elm",
"[",
"'replacewith'",
"]",
"!==",
"null",
")",
"{",
"$",
"elmType",
"=",
"(",
"string",
")",
"$",
"elm",
"[",
"'replacewith'",
"]",
";",
"}",
"else",
"{",
"$",
"elmType",
"=",
"(",
"string",
")",
"$",
"elm",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"segmentTemplates",
"[",
"$",
"elmType",
"]",
")",
")",
"{",
"$",
"jsonMessage",
"=",
"$",
"this",
"->",
"processSegment",
"(",
"$",
"this",
"->",
"segmentTemplates",
"[",
"$",
"elmType",
"]",
",",
"$",
"this",
"->",
"xmlSeg",
",",
"$",
"segmentIdx",
",",
"$",
"errors",
")",
";",
"$",
"fixed",
"=",
"true",
";",
"$",
"this",
"->",
"doAddArray",
"(",
"$",
"array",
",",
"$",
"jsonMessage",
")",
";",
"}",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'MISSINGREQUIREDSEGMENT'",
"]",
".",
"\" \"",
".",
"(",
"$",
"fixed",
"?",
"'(patched)'",
":",
"''",
")",
",",
"\"position\"",
"=>",
"$",
"segmentIdx",
",",
"\"segmentId\"",
"=>",
"(",
"string",
")",
"$",
"elm",
"[",
"'id'",
"]",
",",
"]",
";",
"}",
"return",
";",
"}",
"}",
"}"
] | Process an XML Segment.
@param \SimpleXMLElement $elm
@param array $message
@param int $segmentIdx
@param array $array
@param array $errors
@return void | [
"Process",
"an",
"XML",
"Segment",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L368-L409 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.doAddArray | private function doAddArray(array &$array, array &$jsonMessage)
{
if (isset($array[$jsonMessage['key']])) {
if (
isset($array[$jsonMessage['key']]['segmentCode'])
||
$jsonMessage['key'] === 'UnrecognisedType'
) {
$temp = $array[$jsonMessage['key']];
$array[$jsonMessage['key']] = [];
$array[$jsonMessage['key']][] = $temp;
}
$array[$jsonMessage['key']][] = $jsonMessage['value'];
} else {
$array[$jsonMessage['key']] = $jsonMessage['value'];
}
} | php | private function doAddArray(array &$array, array &$jsonMessage)
{
if (isset($array[$jsonMessage['key']])) {
if (
isset($array[$jsonMessage['key']]['segmentCode'])
||
$jsonMessage['key'] === 'UnrecognisedType'
) {
$temp = $array[$jsonMessage['key']];
$array[$jsonMessage['key']] = [];
$array[$jsonMessage['key']][] = $temp;
}
$array[$jsonMessage['key']][] = $jsonMessage['value'];
} else {
$array[$jsonMessage['key']] = $jsonMessage['value'];
}
} | [
"private",
"function",
"doAddArray",
"(",
"array",
"&",
"$",
"array",
",",
"array",
"&",
"$",
"jsonMessage",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
"[",
"'segmentCode'",
"]",
")",
"||",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"===",
"'UnrecognisedType'",
")",
"{",
"$",
"temp",
"=",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
";",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
"=",
"[",
"]",
";",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
"[",
"]",
"=",
"$",
"temp",
";",
"}",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
"[",
"]",
"=",
"$",
"jsonMessage",
"[",
"'value'",
"]",
";",
"}",
"else",
"{",
"$",
"array",
"[",
"$",
"jsonMessage",
"[",
"'key'",
"]",
"]",
"=",
"$",
"jsonMessage",
"[",
"'value'",
"]",
";",
"}",
"}"
] | Adds a processed segment to the current group.
@param array $array a reference to the group
@param array $jsonMessage a segment processed by processSegment()
@return void | [
"Adds",
"a",
"processed",
"segment",
"to",
"the",
"current",
"group",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L419-L435 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.processSegment | private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, array &$errors = null): array
{
$id = $segment[0];
$jsonsegment = [];
if (isset($xmlMap[$id])) {
$attributes = $xmlMap[$id]['attributes'];
$details_desc = $xmlMap[$id]['details'];
$jsonelements = ["segmentIdx" => $segmentIdx, "segmentCode" => $id];
foreach ($segment as $idx => $detail) {
$n = $idx - 1;
if ($idx == 0) {
continue;
}
if (!isset($details_desc[$n])) {
$errors[] = [
"text" => $this->messageTextConf['TOOMANYELEMENTS'],
"position" => $segmentIdx,
"segmentId" => $id,
];
$jsonelements["Extension" . $n] = $detail;
continue;
}
$d_desc_attr = $details_desc[$n]['attributes'];
$jsoncomposite = [];
if (
$detail !== ''
&&
isset($details_desc[$n]['details'])
) {
$sub_details_desc = $details_desc[$n]['details'];
if (\is_array($detail)) {
foreach ($detail as $d_n => $d_detail) {
if (!isset($sub_details_desc[$d_n])) {
$errors[] = [
"text" => $this->messageTextConf['TOOMANYELEMENTS_COMPOSITE'],
"position" => $segmentIdx . "/" . $idx,
"segmentId" => $id,
];
$jsoncomposite["CompositeExtension" . $d_n] = $d_detail;
continue;
}
$d_sub_desc_attr = $sub_details_desc[$d_n]['attributes'];
if (!isset($jsoncomposite[$d_sub_desc_attr['name']])) { //New
$jsoncomposite[$d_sub_desc_attr['name']] = $d_detail;
} elseif (\is_string($jsoncomposite[$d_sub_desc_attr['name']])) { // More data than one string
$jsoncomposite[$d_sub_desc_attr['name']] = [
$jsoncomposite[$d_sub_desc_attr['name']],
$d_detail,
];
} else { // More and more
$jsoncomposite[$d_sub_desc_attr['name']][] = $d_detail;
}
}
} else {
$d_sub_desc_attr = $sub_details_desc[0]['attributes'];
$jsoncomposite[$d_sub_desc_attr['name']] = $detail;
}
} else {
$jsoncomposite = $detail;
}
if (\array_key_exists($d_desc_attr['name'], $jsonelements)) {
$jsonelements[$d_desc_attr['name'] . $n] = $jsoncomposite;
} else {
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
}
}
$jsonsegment['key'] = $attributes['name'];
$jsonsegment['value'] = $jsonelements;
} elseif ($xmlMap !== $this->xmlSvc) {
$jsonsegment = $this->processSegment($segment, $this->xmlSvc, $segmentIdx, $errors);
} else {
$jsonsegment['key'] = 'UnrecognisedType';
$jsonsegment['value'] = $segment;
}
return $jsonsegment;
} | php | private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, array &$errors = null): array
{
$id = $segment[0];
$jsonsegment = [];
if (isset($xmlMap[$id])) {
$attributes = $xmlMap[$id]['attributes'];
$details_desc = $xmlMap[$id]['details'];
$jsonelements = ["segmentIdx" => $segmentIdx, "segmentCode" => $id];
foreach ($segment as $idx => $detail) {
$n = $idx - 1;
if ($idx == 0) {
continue;
}
if (!isset($details_desc[$n])) {
$errors[] = [
"text" => $this->messageTextConf['TOOMANYELEMENTS'],
"position" => $segmentIdx,
"segmentId" => $id,
];
$jsonelements["Extension" . $n] = $detail;
continue;
}
$d_desc_attr = $details_desc[$n]['attributes'];
$jsoncomposite = [];
if (
$detail !== ''
&&
isset($details_desc[$n]['details'])
) {
$sub_details_desc = $details_desc[$n]['details'];
if (\is_array($detail)) {
foreach ($detail as $d_n => $d_detail) {
if (!isset($sub_details_desc[$d_n])) {
$errors[] = [
"text" => $this->messageTextConf['TOOMANYELEMENTS_COMPOSITE'],
"position" => $segmentIdx . "/" . $idx,
"segmentId" => $id,
];
$jsoncomposite["CompositeExtension" . $d_n] = $d_detail;
continue;
}
$d_sub_desc_attr = $sub_details_desc[$d_n]['attributes'];
if (!isset($jsoncomposite[$d_sub_desc_attr['name']])) { //New
$jsoncomposite[$d_sub_desc_attr['name']] = $d_detail;
} elseif (\is_string($jsoncomposite[$d_sub_desc_attr['name']])) { // More data than one string
$jsoncomposite[$d_sub_desc_attr['name']] = [
$jsoncomposite[$d_sub_desc_attr['name']],
$d_detail,
];
} else { // More and more
$jsoncomposite[$d_sub_desc_attr['name']][] = $d_detail;
}
}
} else {
$d_sub_desc_attr = $sub_details_desc[0]['attributes'];
$jsoncomposite[$d_sub_desc_attr['name']] = $detail;
}
} else {
$jsoncomposite = $detail;
}
if (\array_key_exists($d_desc_attr['name'], $jsonelements)) {
$jsonelements[$d_desc_attr['name'] . $n] = $jsoncomposite;
} else {
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
}
}
$jsonsegment['key'] = $attributes['name'];
$jsonsegment['value'] = $jsonelements;
} elseif ($xmlMap !== $this->xmlSvc) {
$jsonsegment = $this->processSegment($segment, $this->xmlSvc, $segmentIdx, $errors);
} else {
$jsonsegment['key'] = 'UnrecognisedType';
$jsonsegment['value'] = $segment;
}
return $jsonsegment;
} | [
"private",
"function",
"processSegment",
"(",
"array",
"&",
"$",
"segment",
",",
"array",
"&",
"$",
"xmlMap",
",",
"$",
"segmentIdx",
",",
"array",
"&",
"$",
"errors",
"=",
"null",
")",
":",
"array",
"{",
"$",
"id",
"=",
"$",
"segment",
"[",
"0",
"]",
";",
"$",
"jsonsegment",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"xmlMap",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"attributes",
"=",
"$",
"xmlMap",
"[",
"$",
"id",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"details_desc",
"=",
"$",
"xmlMap",
"[",
"$",
"id",
"]",
"[",
"'details'",
"]",
";",
"$",
"jsonelements",
"=",
"[",
"\"segmentIdx\"",
"=>",
"$",
"segmentIdx",
",",
"\"segmentCode\"",
"=>",
"$",
"id",
"]",
";",
"foreach",
"(",
"$",
"segment",
"as",
"$",
"idx",
"=>",
"$",
"detail",
")",
"{",
"$",
"n",
"=",
"$",
"idx",
"-",
"1",
";",
"if",
"(",
"$",
"idx",
"==",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"details_desc",
"[",
"$",
"n",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'TOOMANYELEMENTS'",
"]",
",",
"\"position\"",
"=>",
"$",
"segmentIdx",
",",
"\"segmentId\"",
"=>",
"$",
"id",
",",
"]",
";",
"$",
"jsonelements",
"[",
"\"Extension\"",
".",
"$",
"n",
"]",
"=",
"$",
"detail",
";",
"continue",
";",
"}",
"$",
"d_desc_attr",
"=",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"jsoncomposite",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"detail",
"!==",
"''",
"&&",
"isset",
"(",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'details'",
"]",
")",
")",
"{",
"$",
"sub_details_desc",
"=",
"$",
"details_desc",
"[",
"$",
"n",
"]",
"[",
"'details'",
"]",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"detail",
")",
")",
"{",
"foreach",
"(",
"$",
"detail",
"as",
"$",
"d_n",
"=>",
"$",
"d_detail",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"sub_details_desc",
"[",
"$",
"d_n",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"[",
"\"text\"",
"=>",
"$",
"this",
"->",
"messageTextConf",
"[",
"'TOOMANYELEMENTS_COMPOSITE'",
"]",
",",
"\"position\"",
"=>",
"$",
"segmentIdx",
".",
"\"/\"",
".",
"$",
"idx",
",",
"\"segmentId\"",
"=>",
"$",
"id",
",",
"]",
";",
"$",
"jsoncomposite",
"[",
"\"CompositeExtension\"",
".",
"$",
"d_n",
"]",
"=",
"$",
"d_detail",
";",
"continue",
";",
"}",
"$",
"d_sub_desc_attr",
"=",
"$",
"sub_details_desc",
"[",
"$",
"d_n",
"]",
"[",
"'attributes'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
")",
")",
"{",
"//New",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"d_detail",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
")",
")",
"{",
"// More data than one string",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"[",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
",",
"$",
"d_detail",
",",
"]",
";",
"}",
"else",
"{",
"// More and more",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
"[",
"]",
"=",
"$",
"d_detail",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"d_sub_desc_attr",
"=",
"$",
"sub_details_desc",
"[",
"0",
"]",
"[",
"'attributes'",
"]",
";",
"$",
"jsoncomposite",
"[",
"$",
"d_sub_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"detail",
";",
"}",
"}",
"else",
"{",
"$",
"jsoncomposite",
"=",
"$",
"detail",
";",
"}",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
",",
"$",
"jsonelements",
")",
")",
"{",
"$",
"jsonelements",
"[",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
".",
"$",
"n",
"]",
"=",
"$",
"jsoncomposite",
";",
"}",
"else",
"{",
"$",
"jsonelements",
"[",
"$",
"d_desc_attr",
"[",
"'name'",
"]",
"]",
"=",
"$",
"jsoncomposite",
";",
"}",
"}",
"$",
"jsonsegment",
"[",
"'key'",
"]",
"=",
"$",
"attributes",
"[",
"'name'",
"]",
";",
"$",
"jsonsegment",
"[",
"'value'",
"]",
"=",
"$",
"jsonelements",
";",
"}",
"elseif",
"(",
"$",
"xmlMap",
"!==",
"$",
"this",
"->",
"xmlSvc",
")",
"{",
"$",
"jsonsegment",
"=",
"$",
"this",
"->",
"processSegment",
"(",
"$",
"segment",
",",
"$",
"this",
"->",
"xmlSvc",
",",
"$",
"segmentIdx",
",",
"$",
"errors",
")",
";",
"}",
"else",
"{",
"$",
"jsonsegment",
"[",
"'key'",
"]",
"=",
"'UnrecognisedType'",
";",
"$",
"jsonsegment",
"[",
"'value'",
"]",
"=",
"$",
"segment",
";",
"}",
"return",
"$",
"jsonsegment",
";",
"}"
] | Add human readable keys as in Analyser.
@param array $segment
@param array $xmlMap
@param null|int $segmentIdx
@param null|array $errors
@return array | [
"Add",
"human",
"readable",
"keys",
"as",
"in",
"Analyser",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L447-L533 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.processService | private function processService(array &$segments): array
{
// init
$processed = [];
foreach ($segments as &$seg) {
$jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
$processed[$jsonsegment['key']] = $jsonsegment['value'];
}
return $processed;
} | php | private function processService(array &$segments): array
{
// init
$processed = [];
foreach ($segments as &$seg) {
$jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
$processed[$jsonsegment['key']] = $jsonsegment['value'];
}
return $processed;
} | [
"private",
"function",
"processService",
"(",
"array",
"&",
"$",
"segments",
")",
":",
"array",
"{",
"// init",
"$",
"processed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"segments",
"as",
"&",
"$",
"seg",
")",
"{",
"$",
"jsonsegment",
"=",
"$",
"this",
"->",
"processSegment",
"(",
"$",
"seg",
",",
"$",
"this",
"->",
"xmlSvc",
",",
"null",
")",
";",
"$",
"processed",
"[",
"$",
"jsonsegment",
"[",
"'key'",
"]",
"]",
"=",
"$",
"jsonsegment",
"[",
"'value'",
"]",
";",
"}",
"return",
"$",
"processed",
";",
"}"
] | Process UNB / UNZ segments
@param array $segments
@return array | [
"Process",
"UNB",
"/",
"UNZ",
"segments"
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L542-L553 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.getJson | public function getJson(bool $pretty = false)
{
if ($pretty) {
return \json_encode($this->ediGroups, JSON_PRETTY_PRINT);
}
return \json_encode($this->ediGroups);
} | php | public function getJson(bool $pretty = false)
{
if ($pretty) {
return \json_encode($this->ediGroups, JSON_PRETTY_PRINT);
}
return \json_encode($this->ediGroups);
} | [
"public",
"function",
"getJson",
"(",
"bool",
"$",
"pretty",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"pretty",
")",
"{",
"return",
"\\",
"json_encode",
"(",
"$",
"this",
"->",
"ediGroups",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}",
"return",
"\\",
"json_encode",
"(",
"$",
"this",
"->",
"ediGroups",
")",
";",
"}"
] | Get result as json.
@param bool $pretty
@return false|string | [
"Get",
"result",
"as",
"json",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L562-L569 |
php-edifact/edifact | src/EDI/Interpreter.php | Interpreter.getJsonServiceSegments | public function getJsonServiceSegments(bool $pretty = false)
{
if ($pretty) {
return \json_encode($this->serviceSeg, JSON_PRETTY_PRINT);
}
return \json_encode($this->serviceSeg);
} | php | public function getJsonServiceSegments(bool $pretty = false)
{
if ($pretty) {
return \json_encode($this->serviceSeg, JSON_PRETTY_PRINT);
}
return \json_encode($this->serviceSeg);
} | [
"public",
"function",
"getJsonServiceSegments",
"(",
"bool",
"$",
"pretty",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"pretty",
")",
"{",
"return",
"\\",
"json_encode",
"(",
"$",
"this",
"->",
"serviceSeg",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}",
"return",
"\\",
"json_encode",
"(",
"$",
"this",
"->",
"serviceSeg",
")",
";",
"}"
] | Get json service segments.
@param bool $pretty
@return false|string | [
"Get",
"json",
"service",
"segments",
"."
] | train | https://github.com/php-edifact/edifact/blob/a24b01089f63f84e607caddf0e34cad307ac230c/src/EDI/Interpreter.php#L618-L625 |
byjg/migration | src/Migration.php | Migration.getMigrationSql | public function getMigrationSql($version, $increment)
{
// I could use the GLOB_BRACE but it is not supported on ALPINE distros.
// So, I have to call multiple times to simulate the braces.
if (intval($version) != $version) {
throw new \InvalidArgumentException("Version '$version' should be a integer number");
}
$version = intval($version);
$filePattern = $this->folder
. "/migrations"
. "/" . ($increment < 0 ? "down" : "up")
. "/*.sql";
$result = array_filter(glob($filePattern), function ($file) use ($version) {
return preg_match("/^0*$version(-dev)?\.sql$/", basename($file));
});
// Valid values are 0 or 1
if (count($result) > 1) {
throw new InvalidMigrationFile("You have two files with the same version number '$version'");
}
foreach ($result as $file) {
if (intval(basename($file)) === $version) {
return $file;
}
}
return null;
} | php | public function getMigrationSql($version, $increment)
{
// I could use the GLOB_BRACE but it is not supported on ALPINE distros.
// So, I have to call multiple times to simulate the braces.
if (intval($version) != $version) {
throw new \InvalidArgumentException("Version '$version' should be a integer number");
}
$version = intval($version);
$filePattern = $this->folder
. "/migrations"
. "/" . ($increment < 0 ? "down" : "up")
. "/*.sql";
$result = array_filter(glob($filePattern), function ($file) use ($version) {
return preg_match("/^0*$version(-dev)?\.sql$/", basename($file));
});
// Valid values are 0 or 1
if (count($result) > 1) {
throw new InvalidMigrationFile("You have two files with the same version number '$version'");
}
foreach ($result as $file) {
if (intval(basename($file)) === $version) {
return $file;
}
}
return null;
} | [
"public",
"function",
"getMigrationSql",
"(",
"$",
"version",
",",
"$",
"increment",
")",
"{",
"// I could use the GLOB_BRACE but it is not supported on ALPINE distros.",
"// So, I have to call multiple times to simulate the braces.",
"if",
"(",
"intval",
"(",
"$",
"version",
")",
"!=",
"$",
"version",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Version '$version' should be a integer number\"",
")",
";",
"}",
"$",
"version",
"=",
"intval",
"(",
"$",
"version",
")",
";",
"$",
"filePattern",
"=",
"$",
"this",
"->",
"folder",
".",
"\"/migrations\"",
".",
"\"/\"",
".",
"(",
"$",
"increment",
"<",
"0",
"?",
"\"down\"",
":",
"\"up\"",
")",
".",
"\"/*.sql\"",
";",
"$",
"result",
"=",
"array_filter",
"(",
"glob",
"(",
"$",
"filePattern",
")",
",",
"function",
"(",
"$",
"file",
")",
"use",
"(",
"$",
"version",
")",
"{",
"return",
"preg_match",
"(",
"\"/^0*$version(-dev)?\\.sql$/\"",
",",
"basename",
"(",
"$",
"file",
")",
")",
";",
"}",
")",
";",
"// Valid values are 0 or 1",
"if",
"(",
"count",
"(",
"$",
"result",
")",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidMigrationFile",
"(",
"\"You have two files with the same version number '$version'\"",
")",
";",
"}",
"foreach",
"(",
"$",
"result",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"intval",
"(",
"basename",
"(",
"$",
"file",
")",
")",
"===",
"$",
"version",
")",
"{",
"return",
"$",
"file",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get the full path script based on the version
@param $version
@param $increment
@return string
@throws \ByJG\DbMigration\Exception\InvalidMigrationFile | [
"Get",
"the",
"full",
"path",
"script",
"based",
"on",
"the",
"version"
] | train | https://github.com/byjg/migration/blob/41f0642f5a9697fc2d99123c58e0e9f4fa26ad58/src/Migration.php#L136-L166 |
byjg/migration | src/Migration.php | Migration.reset | public function reset($upVersion = null)
{
if ($this->callableProgress) {
call_user_func_array($this->callableProgress, ['reset', 0]);
}
$this->getDbCommand()->dropDatabase();
$this->getDbCommand()->createDatabase();
$this->getDbCommand()->createVersion();
if (file_exists($this->getBaseSql())) {
$this->getDbCommand()->executeSql(file_get_contents($this->getBaseSql()));
}
$this->getDbCommand()->setVersion(0, Migration::VERSION_STATUS_COMPLETE);
$this->up($upVersion);
} | php | public function reset($upVersion = null)
{
if ($this->callableProgress) {
call_user_func_array($this->callableProgress, ['reset', 0]);
}
$this->getDbCommand()->dropDatabase();
$this->getDbCommand()->createDatabase();
$this->getDbCommand()->createVersion();
if (file_exists($this->getBaseSql())) {
$this->getDbCommand()->executeSql(file_get_contents($this->getBaseSql()));
}
$this->getDbCommand()->setVersion(0, Migration::VERSION_STATUS_COMPLETE);
$this->up($upVersion);
} | [
"public",
"function",
"reset",
"(",
"$",
"upVersion",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"callableProgress",
")",
"{",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callableProgress",
",",
"[",
"'reset'",
",",
"0",
"]",
")",
";",
"}",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"dropDatabase",
"(",
")",
";",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"createDatabase",
"(",
")",
";",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"createVersion",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"getBaseSql",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"executeSql",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"getBaseSql",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"setVersion",
"(",
"0",
",",
"Migration",
"::",
"VERSION_STATUS_COMPLETE",
")",
";",
"$",
"this",
"->",
"up",
"(",
"$",
"upVersion",
")",
";",
"}"
] | Restore the database using the "base.sql" script and run all migration scripts
Note: the database must exists. If dont exist run the method prepareEnvironment
@param int $upVersion
@throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered
@throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException
@throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException
@throws \ByJG\DbMigration\Exception\InvalidMigrationFile
@throws \ByJG\DbMigration\Exception\OldVersionSchemaException | [
"Restore",
"the",
"database",
"using",
"the",
"base",
".",
"sql",
"script",
"and",
"run",
"all",
"migration",
"scripts",
"Note",
":",
"the",
"database",
"must",
"exists",
".",
"If",
"dont",
"exist",
"run",
"the",
"method",
"prepareEnvironment"
] | train | https://github.com/byjg/migration/blob/41f0642f5a9697fc2d99123c58e0e9f4fa26ad58/src/Migration.php#L190-L205 |
byjg/migration | src/Migration.php | Migration.migrate | protected function migrate($upVersion, $increment, $force)
{
$versionInfo = $this->getCurrentVersion();
$currentVersion = intval($versionInfo['version']) + $increment;
if (strpos($versionInfo['status'], Migration::VERSION_STATUS_PARTIAL) !== false && !$force) {
throw new DatabaseIsIncompleteException('Database was not fully updated. Use --force for migrate.');
}
while ($this->canContinue($currentVersion, $upVersion, $increment)
&& file_exists($file = $this->getMigrationSql($currentVersion, $increment))
) {
if ($this->callableProgress) {
call_user_func_array($this->callableProgress, ['migrate', $currentVersion]);
}
$this->getDbCommand()->setVersion($currentVersion, Migration::VERSION_STATUS_PARTIAL . ' ' . ($increment>0 ? 'up' : 'down'));
$this->getDbCommand()->executeSql(file_get_contents($file));
$this->getDbCommand()->setVersion($currentVersion, Migration::VERSION_STATUS_COMPLETE);
$currentVersion = $currentVersion + $increment;
}
} | php | protected function migrate($upVersion, $increment, $force)
{
$versionInfo = $this->getCurrentVersion();
$currentVersion = intval($versionInfo['version']) + $increment;
if (strpos($versionInfo['status'], Migration::VERSION_STATUS_PARTIAL) !== false && !$force) {
throw new DatabaseIsIncompleteException('Database was not fully updated. Use --force for migrate.');
}
while ($this->canContinue($currentVersion, $upVersion, $increment)
&& file_exists($file = $this->getMigrationSql($currentVersion, $increment))
) {
if ($this->callableProgress) {
call_user_func_array($this->callableProgress, ['migrate', $currentVersion]);
}
$this->getDbCommand()->setVersion($currentVersion, Migration::VERSION_STATUS_PARTIAL . ' ' . ($increment>0 ? 'up' : 'down'));
$this->getDbCommand()->executeSql(file_get_contents($file));
$this->getDbCommand()->setVersion($currentVersion, Migration::VERSION_STATUS_COMPLETE);
$currentVersion = $currentVersion + $increment;
}
} | [
"protected",
"function",
"migrate",
"(",
"$",
"upVersion",
",",
"$",
"increment",
",",
"$",
"force",
")",
"{",
"$",
"versionInfo",
"=",
"$",
"this",
"->",
"getCurrentVersion",
"(",
")",
";",
"$",
"currentVersion",
"=",
"intval",
"(",
"$",
"versionInfo",
"[",
"'version'",
"]",
")",
"+",
"$",
"increment",
";",
"if",
"(",
"strpos",
"(",
"$",
"versionInfo",
"[",
"'status'",
"]",
",",
"Migration",
"::",
"VERSION_STATUS_PARTIAL",
")",
"!==",
"false",
"&&",
"!",
"$",
"force",
")",
"{",
"throw",
"new",
"DatabaseIsIncompleteException",
"(",
"'Database was not fully updated. Use --force for migrate.'",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"canContinue",
"(",
"$",
"currentVersion",
",",
"$",
"upVersion",
",",
"$",
"increment",
")",
"&&",
"file_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getMigrationSql",
"(",
"$",
"currentVersion",
",",
"$",
"increment",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"callableProgress",
")",
"{",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callableProgress",
",",
"[",
"'migrate'",
",",
"$",
"currentVersion",
"]",
")",
";",
"}",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"setVersion",
"(",
"$",
"currentVersion",
",",
"Migration",
"::",
"VERSION_STATUS_PARTIAL",
".",
"' '",
".",
"(",
"$",
"increment",
">",
"0",
"?",
"'up'",
":",
"'down'",
")",
")",
";",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"executeSql",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"$",
"this",
"->",
"getDbCommand",
"(",
")",
"->",
"setVersion",
"(",
"$",
"currentVersion",
",",
"Migration",
"::",
"VERSION_STATUS_COMPLETE",
")",
";",
"$",
"currentVersion",
"=",
"$",
"currentVersion",
"+",
"$",
"increment",
";",
"}",
"}"
] | Method for execute the migration.
@param int $upVersion
@param int $increment Can accept 1 for UP or -1 for down
@param bool $force
@throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered
@throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException
@throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException
@throws \ByJG\DbMigration\Exception\InvalidMigrationFile
@throws \ByJG\DbMigration\Exception\OldVersionSchemaException | [
"Method",
"for",
"execute",
"the",
"migration",
"."
] | train | https://github.com/byjg/migration/blob/41f0642f5a9697fc2d99123c58e0e9f4fa26ad58/src/Migration.php#L265-L286 |
byjg/migration | src/Migration.php | Migration.update | public function update($upVersion = null, $force = false)
{
$versionInfo = $this->getCurrentVersion();
$version = intval($versionInfo['version']);
$increment = 1;
if ($upVersion !== null && $upVersion < $version) {
$increment = -1;
}
$this->migrate($upVersion, $increment, $force);
} | php | public function update($upVersion = null, $force = false)
{
$versionInfo = $this->getCurrentVersion();
$version = intval($versionInfo['version']);
$increment = 1;
if ($upVersion !== null && $upVersion < $version) {
$increment = -1;
}
$this->migrate($upVersion, $increment, $force);
} | [
"public",
"function",
"update",
"(",
"$",
"upVersion",
"=",
"null",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"versionInfo",
"=",
"$",
"this",
"->",
"getCurrentVersion",
"(",
")",
";",
"$",
"version",
"=",
"intval",
"(",
"$",
"versionInfo",
"[",
"'version'",
"]",
")",
";",
"$",
"increment",
"=",
"1",
";",
"if",
"(",
"$",
"upVersion",
"!==",
"null",
"&&",
"$",
"upVersion",
"<",
"$",
"version",
")",
"{",
"$",
"increment",
"=",
"-",
"1",
";",
"}",
"$",
"this",
"->",
"migrate",
"(",
"$",
"upVersion",
",",
"$",
"increment",
",",
"$",
"force",
")",
";",
"}"
] | Run all scripts to up or down the database version from current up to latest version or the specified version.
@param int $upVersion
@param bool $force
@throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered
@throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException
@throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException
@throws \ByJG\DbMigration\Exception\InvalidMigrationFile
@throws \ByJG\DbMigration\Exception\OldVersionSchemaException | [
"Run",
"all",
"scripts",
"to",
"up",
"or",
"down",
"the",
"database",
"version",
"from",
"current",
"up",
"to",
"latest",
"version",
"or",
"the",
"specified",
"version",
"."
] | train | https://github.com/byjg/migration/blob/41f0642f5a9697fc2d99123c58e0e9f4fa26ad58/src/Migration.php#L315-L324 |
winzou/StateMachineBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$configNode = $treeBuilder
->root('winzou_state_machine')
->useAttributeAsKey('name')
->prototype('array')
->children()
;
$configNode
->scalarNode('class')->isRequired()->end()
->scalarNode('graph')->defaultValue('default')->end()
->scalarNode('property_path')->defaultValue('state')->end()
->scalarNode('state_machine_class')->defaultValue('SM\\StateMachine\\StateMachine')->end()
;
$this->addStateSection($configNode);
$this->addTransitionSection($configNode);
$this->addCallbackSection($configNode);
$configNode->end()->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$configNode = $treeBuilder
->root('winzou_state_machine')
->useAttributeAsKey('name')
->prototype('array')
->children()
;
$configNode
->scalarNode('class')->isRequired()->end()
->scalarNode('graph')->defaultValue('default')->end()
->scalarNode('property_path')->defaultValue('state')->end()
->scalarNode('state_machine_class')->defaultValue('SM\\StateMachine\\StateMachine')->end()
;
$this->addStateSection($configNode);
$this->addTransitionSection($configNode);
$this->addCallbackSection($configNode);
$configNode->end()->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"configNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'winzou_state_machine'",
")",
"->",
"useAttributeAsKey",
"(",
"'name'",
")",
"->",
"prototype",
"(",
"'array'",
")",
"->",
"children",
"(",
")",
";",
"$",
"configNode",
"->",
"scalarNode",
"(",
"'class'",
")",
"->",
"isRequired",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'graph'",
")",
"->",
"defaultValue",
"(",
"'default'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'property_path'",
")",
"->",
"defaultValue",
"(",
"'state'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'state_machine_class'",
")",
"->",
"defaultValue",
"(",
"'SM\\\\StateMachine\\\\StateMachine'",
")",
"->",
"end",
"(",
")",
";",
"$",
"this",
"->",
"addStateSection",
"(",
"$",
"configNode",
")",
";",
"$",
"this",
"->",
"addTransitionSection",
"(",
"$",
"configNode",
")",
";",
"$",
"this",
"->",
"addCallbackSection",
"(",
"$",
"configNode",
")",
";",
"$",
"configNode",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/DependencyInjection/Configuration.php#L23-L48 |
winzou/StateMachineBundle | Callback/ContainerAwareCallback.php | ContainerAwareCallback.call | public function call(TransitionEvent $event)
{
// Load the services only now (when the callback is actually called)
if (is_array($this->callable) && is_string($this->callable[0])) {
if (0 === strpos($this->callable[0], '@')) {
// BC for sf < 4.0, we refer to the service via its '@name'
$serviceId = substr($this->callable[0], 1);
} else {
$serviceId = $this->callable[0];
// We allow static calls so no Exception thrown if callable is not a service
if (!$this->container->has($serviceId)) {
return parent::call($event);
}
}
// Callback services have to be public
$this->callable[0] = $this->container->get($serviceId);
}
return parent::call($event);
} | php | public function call(TransitionEvent $event)
{
// Load the services only now (when the callback is actually called)
if (is_array($this->callable) && is_string($this->callable[0])) {
if (0 === strpos($this->callable[0], '@')) {
// BC for sf < 4.0, we refer to the service via its '@name'
$serviceId = substr($this->callable[0], 1);
} else {
$serviceId = $this->callable[0];
// We allow static calls so no Exception thrown if callable is not a service
if (!$this->container->has($serviceId)) {
return parent::call($event);
}
}
// Callback services have to be public
$this->callable[0] = $this->container->get($serviceId);
}
return parent::call($event);
} | [
"public",
"function",
"call",
"(",
"TransitionEvent",
"$",
"event",
")",
"{",
"// Load the services only now (when the callback is actually called)",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"callable",
")",
"&&",
"is_string",
"(",
"$",
"this",
"->",
"callable",
"[",
"0",
"]",
")",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"this",
"->",
"callable",
"[",
"0",
"]",
",",
"'@'",
")",
")",
"{",
"// BC for sf < 4.0, we refer to the service via its '@name'",
"$",
"serviceId",
"=",
"substr",
"(",
"$",
"this",
"->",
"callable",
"[",
"0",
"]",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"serviceId",
"=",
"$",
"this",
"->",
"callable",
"[",
"0",
"]",
";",
"// We allow static calls so no Exception thrown if callable is not a service",
"if",
"(",
"!",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"serviceId",
")",
")",
"{",
"return",
"parent",
"::",
"call",
"(",
"$",
"event",
")",
";",
"}",
"}",
"// Callback services have to be public",
"$",
"this",
"->",
"callable",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"serviceId",
")",
";",
"}",
"return",
"parent",
"::",
"call",
"(",
"$",
"event",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/Callback/ContainerAwareCallback.php#L35-L56 |
winzou/StateMachineBundle | DependencyInjection/winzouStateMachineExtension.php | winzouStateMachineExtension.parseConfig | public function parseConfig(array $configs)
{
foreach ($configs as &$config) {
$config['states'] = $this->parseStates($config['states']);
if (isset($config['callbacks'])) {
$config['callbacks'] = $this->parseCallbacks($config['callbacks']);
}
}
return $configs;
} | php | public function parseConfig(array $configs)
{
foreach ($configs as &$config) {
$config['states'] = $this->parseStates($config['states']);
if (isset($config['callbacks'])) {
$config['callbacks'] = $this->parseCallbacks($config['callbacks']);
}
}
return $configs;
} | [
"public",
"function",
"parseConfig",
"(",
"array",
"$",
"configs",
")",
"{",
"foreach",
"(",
"$",
"configs",
"as",
"&",
"$",
"config",
")",
"{",
"$",
"config",
"[",
"'states'",
"]",
"=",
"$",
"this",
"->",
"parseStates",
"(",
"$",
"config",
"[",
"'states'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'callbacks'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'callbacks'",
"]",
"=",
"$",
"this",
"->",
"parseCallbacks",
"(",
"$",
"config",
"[",
"'callbacks'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"configs",
";",
"}"
] | Does whatever is needed to transform the config in an acceptable argument for the factory
@param array $configs
@return array | [
"Does",
"whatever",
"is",
"needed",
"to",
"transform",
"the",
"config",
"in",
"an",
"acceptable",
"argument",
"for",
"the",
"factory"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/DependencyInjection/winzouStateMachineExtension.php#L43-L54 |
winzou/StateMachineBundle | DependencyInjection/winzouStateMachineExtension.php | winzouStateMachineExtension.parseStates | protected function parseStates(array $states)
{
$newStates = array();
foreach ($states as $key => $state) {
if (null === $state) {
$newStates[] = $key;
} elseif (self::CFG_STATE_DISABLE !== $state) {
$newStates[] = $state;
} elseif (null !== $index = array_search($key, $newStates)) {
unset($newStates[$index]);
}
}
return $newStates;
} | php | protected function parseStates(array $states)
{
$newStates = array();
foreach ($states as $key => $state) {
if (null === $state) {
$newStates[] = $key;
} elseif (self::CFG_STATE_DISABLE !== $state) {
$newStates[] = $state;
} elseif (null !== $index = array_search($key, $newStates)) {
unset($newStates[$index]);
}
}
return $newStates;
} | [
"protected",
"function",
"parseStates",
"(",
"array",
"$",
"states",
")",
"{",
"$",
"newStates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"states",
"as",
"$",
"key",
"=>",
"$",
"state",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"state",
")",
"{",
"$",
"newStates",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"elseif",
"(",
"self",
"::",
"CFG_STATE_DISABLE",
"!==",
"$",
"state",
")",
"{",
"$",
"newStates",
"[",
"]",
"=",
"$",
"state",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"index",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"newStates",
")",
")",
"{",
"unset",
"(",
"$",
"newStates",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"return",
"$",
"newStates",
";",
"}"
] | Allows the disabling of states
@param array $states
@return array | [
"Allows",
"the",
"disabling",
"of",
"states"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/DependencyInjection/winzouStateMachineExtension.php#L63-L77 |
winzou/StateMachineBundle | DependencyInjection/winzouStateMachineExtension.php | winzouStateMachineExtension.parseCallbacks | protected function parseCallbacks(array $callbacks)
{
foreach (array('before', 'after') as $position) {
// Remove disabled callbacks
foreach ($callbacks[$position] as $i => $callback) {
if ($callback['disabled']) {
unset($callbacks[$position][$i]);
}
}
// Order callbacks according to priority index
uasort($callbacks[$position], function($a, $b) {
if ($a['priority'] === $b['priority']) {
return 0;
}
return $a['priority'] < $b['priority'] ? -1 : 1;
});
}
return $callbacks;
} | php | protected function parseCallbacks(array $callbacks)
{
foreach (array('before', 'after') as $position) {
// Remove disabled callbacks
foreach ($callbacks[$position] as $i => $callback) {
if ($callback['disabled']) {
unset($callbacks[$position][$i]);
}
}
// Order callbacks according to priority index
uasort($callbacks[$position], function($a, $b) {
if ($a['priority'] === $b['priority']) {
return 0;
}
return $a['priority'] < $b['priority'] ? -1 : 1;
});
}
return $callbacks;
} | [
"protected",
"function",
"parseCallbacks",
"(",
"array",
"$",
"callbacks",
")",
"{",
"foreach",
"(",
"array",
"(",
"'before'",
",",
"'after'",
")",
"as",
"$",
"position",
")",
"{",
"// Remove disabled callbacks",
"foreach",
"(",
"$",
"callbacks",
"[",
"$",
"position",
"]",
"as",
"$",
"i",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"$",
"callback",
"[",
"'disabled'",
"]",
")",
"{",
"unset",
"(",
"$",
"callbacks",
"[",
"$",
"position",
"]",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"// Order callbacks according to priority index",
"uasort",
"(",
"$",
"callbacks",
"[",
"$",
"position",
"]",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"[",
"'priority'",
"]",
"===",
"$",
"b",
"[",
"'priority'",
"]",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"a",
"[",
"'priority'",
"]",
"<",
"$",
"b",
"[",
"'priority'",
"]",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}",
"return",
"$",
"callbacks",
";",
"}"
] | Allows the disabling of callbacks
@param array $callbacks
@return array | [
"Allows",
"the",
"disabling",
"of",
"callbacks"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/DependencyInjection/winzouStateMachineExtension.php#L86-L106 |
winzou/StateMachineBundle | Callback/ContainerAwareCallbackFactory.php | ContainerAwareCallbackFactory.get | public function get(array $specs)
{
if (!isset($specs['do'])) {
throw new SMException(sprintf(
'CallbackFactory::get needs the index "do" to be able to build a callback, array %s given.',
json_encode($specs)
));
}
$class = $this->class;
return new $class($specs, $specs['do'], $this->container);
} | php | public function get(array $specs)
{
if (!isset($specs['do'])) {
throw new SMException(sprintf(
'CallbackFactory::get needs the index "do" to be able to build a callback, array %s given.',
json_encode($specs)
));
}
$class = $this->class;
return new $class($specs, $specs['do'], $this->container);
} | [
"public",
"function",
"get",
"(",
"array",
"$",
"specs",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"specs",
"[",
"'do'",
"]",
")",
")",
"{",
"throw",
"new",
"SMException",
"(",
"sprintf",
"(",
"'CallbackFactory::get needs the index \"do\" to be able to build a callback, array %s given.'",
",",
"json_encode",
"(",
"$",
"specs",
")",
")",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"class",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"specs",
",",
"$",
"specs",
"[",
"'do'",
"]",
",",
"$",
"this",
"->",
"container",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/Callback/ContainerAwareCallbackFactory.php#L35-L46 |
winzou/StateMachineBundle | Command/winzouStateMachineDebugCommand.php | winzouStateMachineDebugCommand.initialize | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->config = $this->getContainer()->getParameter('sm.configs');
if (empty($this->config)) {
throw new \RuntimeException('There is no state machine configured.');
}
} | php | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->config = $this->getContainer()->getParameter('sm.configs');
if (empty($this->config)) {
throw new \RuntimeException('There is no state machine configured.');
}
} | [
"protected",
"function",
"initialize",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'sm.configs'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'There is no state machine configured.'",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/Command/winzouStateMachineDebugCommand.php#L36-L43 |
winzou/StateMachineBundle | Command/winzouStateMachineDebugCommand.php | winzouStateMachineDebugCommand.interact | protected function interact(InputInterface $input, OutputInterface $output)
{
if (null !== $input->getArgument('key')) {
return;
}
$choices = array_map(function ($name, $config) {
return $name . "\t(" . $config['class'] . ' - ' . $config['graph'] . ')';
}, array_keys($this->config), $this->config);
$question = new ChoiceQuestion(
'<question>Which state machine would you like to know about?</question>',
$choices,
0
);
$question->setErrorMessage('State Machine %s does not exists.');
$choice = $this->getHelper('question')->ask($input, $output, $question);
$choice = substr($choice, 0, strpos($choice, "\t"));
$output->writeln('<info>You have just selected: '.$choice.'</info>');
$input->setArgument('key', $choice);
} | php | protected function interact(InputInterface $input, OutputInterface $output)
{
if (null !== $input->getArgument('key')) {
return;
}
$choices = array_map(function ($name, $config) {
return $name . "\t(" . $config['class'] . ' - ' . $config['graph'] . ')';
}, array_keys($this->config), $this->config);
$question = new ChoiceQuestion(
'<question>Which state machine would you like to know about?</question>',
$choices,
0
);
$question->setErrorMessage('State Machine %s does not exists.');
$choice = $this->getHelper('question')->ask($input, $output, $question);
$choice = substr($choice, 0, strpos($choice, "\t"));
$output->writeln('<info>You have just selected: '.$choice.'</info>');
$input->setArgument('key', $choice);
} | [
"protected",
"function",
"interact",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"input",
"->",
"getArgument",
"(",
"'key'",
")",
")",
"{",
"return",
";",
"}",
"$",
"choices",
"=",
"array_map",
"(",
"function",
"(",
"$",
"name",
",",
"$",
"config",
")",
"{",
"return",
"$",
"name",
".",
"\"\\t(\"",
".",
"$",
"config",
"[",
"'class'",
"]",
".",
"' - '",
".",
"$",
"config",
"[",
"'graph'",
"]",
".",
"')'",
";",
"}",
",",
"array_keys",
"(",
"$",
"this",
"->",
"config",
")",
",",
"$",
"this",
"->",
"config",
")",
";",
"$",
"question",
"=",
"new",
"ChoiceQuestion",
"(",
"'<question>Which state machine would you like to know about?</question>'",
",",
"$",
"choices",
",",
"0",
")",
";",
"$",
"question",
"->",
"setErrorMessage",
"(",
"'State Machine %s does not exists.'",
")",
";",
"$",
"choice",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'question'",
")",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"$",
"choice",
"=",
"substr",
"(",
"$",
"choice",
",",
"0",
",",
"strpos",
"(",
"$",
"choice",
",",
"\"\\t\"",
")",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'<info>You have just selected: '",
".",
"$",
"choice",
".",
"'</info>'",
")",
";",
"$",
"input",
"->",
"setArgument",
"(",
"'key'",
",",
"$",
"choice",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/Command/winzouStateMachineDebugCommand.php#L48-L71 |
winzou/StateMachineBundle | Command/winzouStateMachineDebugCommand.php | winzouStateMachineDebugCommand.execute | public function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getArgument('key');
if (!array_key_exists($key, $this->config)) {
throw new \RuntimeException("The provided state machine key is not configured.");
}
$config = $this->config[$key];
$this->printStates($config['states'], $output);
$this->printTransitions($config['transitions'], $output);
if (isset($config['callbacks'])) {
$this->printCallbacks($config['callbacks'], $output);
}
} | php | public function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getArgument('key');
if (!array_key_exists($key, $this->config)) {
throw new \RuntimeException("The provided state machine key is not configured.");
}
$config = $this->config[$key];
$this->printStates($config['states'], $output);
$this->printTransitions($config['transitions'], $output);
if (isset($config['callbacks'])) {
$this->printCallbacks($config['callbacks'], $output);
}
} | [
"public",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"key",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'key'",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The provided state machine key is not configured.\"",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
";",
"$",
"this",
"->",
"printStates",
"(",
"$",
"config",
"[",
"'states'",
"]",
",",
"$",
"output",
")",
";",
"$",
"this",
"->",
"printTransitions",
"(",
"$",
"config",
"[",
"'transitions'",
"]",
",",
"$",
"output",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'callbacks'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"printCallbacks",
"(",
"$",
"config",
"[",
"'callbacks'",
"]",
",",
"$",
"output",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/winzou/StateMachineBundle/blob/c90d4960016bea3cf7759ee7cfe5eca47ae84506/Command/winzouStateMachineDebugCommand.php#L76-L92 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.createChildInstance | protected function createChildInstance()
{
$instance = new static(...\func_get_args());
if (isset($this->document)) {
$instance->setDomDocument($this->document);
}
if (isset($this->root_instance)) {
$instance->root_instance = $this->root_instance;
} else {
$instance->root_instance = $this;
}
if (\is_bool($this->xml_mode)) {
$instance->xml_mode = $this->xml_mode;
}
if (isset($this->document) && $this->dom_xpath instanceof \DOMXPath) {
$instance->dom_xpath = $this->dom_xpath;
}
return $instance;
} | php | protected function createChildInstance()
{
$instance = new static(...\func_get_args());
if (isset($this->document)) {
$instance->setDomDocument($this->document);
}
if (isset($this->root_instance)) {
$instance->root_instance = $this->root_instance;
} else {
$instance->root_instance = $this;
}
if (\is_bool($this->xml_mode)) {
$instance->xml_mode = $this->xml_mode;
}
if (isset($this->document) && $this->dom_xpath instanceof \DOMXPath) {
$instance->dom_xpath = $this->dom_xpath;
}
return $instance;
} | [
"protected",
"function",
"createChildInstance",
"(",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
"...",
"\\",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"document",
")",
")",
"{",
"$",
"instance",
"->",
"setDomDocument",
"(",
"$",
"this",
"->",
"document",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"root_instance",
")",
")",
"{",
"$",
"instance",
"->",
"root_instance",
"=",
"$",
"this",
"->",
"root_instance",
";",
"}",
"else",
"{",
"$",
"instance",
"->",
"root_instance",
"=",
"$",
"this",
";",
"}",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"this",
"->",
"xml_mode",
")",
")",
"{",
"$",
"instance",
"->",
"xml_mode",
"=",
"$",
"this",
"->",
"xml_mode",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"document",
")",
"&&",
"$",
"this",
"->",
"dom_xpath",
"instanceof",
"\\",
"DOMXPath",
")",
"{",
"$",
"instance",
"->",
"dom_xpath",
"=",
"$",
"this",
"->",
"dom_xpath",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Create new instance of self with some properties of its parents
@return static | [
"Create",
"new",
"instance",
"of",
"self",
"with",
"some",
"properties",
"of",
"its",
"parents"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L140-L163 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.xpath | public function xpath(string $xpath_query)
{
$result = $this->createChildInstance();
if (isset($this->document)) {
$result->xpath_query = $xpath_query;
if (isset($this->root_instance) || isset($this->xpath_query)) { // all nodes as context
foreach ($this->nodes as $node) {
if ($result_node_list = $this->xpathQuery('.'.$xpath_query, $node)) {
$result->loadDomNodeList($result_node_list);
}
}
} else { // whole document
if ($result_node_list = $this->xpathQuery($xpath_query)) {
$result->loadDomNodeList($result_node_list);
}
}
}
return $result;
} | php | public function xpath(string $xpath_query)
{
$result = $this->createChildInstance();
if (isset($this->document)) {
$result->xpath_query = $xpath_query;
if (isset($this->root_instance) || isset($this->xpath_query)) { // all nodes as context
foreach ($this->nodes as $node) {
if ($result_node_list = $this->xpathQuery('.'.$xpath_query, $node)) {
$result->loadDomNodeList($result_node_list);
}
}
} else { // whole document
if ($result_node_list = $this->xpathQuery($xpath_query)) {
$result->loadDomNodeList($result_node_list);
}
}
}
return $result;
} | [
"public",
"function",
"xpath",
"(",
"string",
"$",
"xpath_query",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"createChildInstance",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"document",
")",
")",
"{",
"$",
"result",
"->",
"xpath_query",
"=",
"$",
"xpath_query",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"root_instance",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"xpath_query",
")",
")",
"{",
"// all nodes as context",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"result_node_list",
"=",
"$",
"this",
"->",
"xpathQuery",
"(",
"'.'",
".",
"$",
"xpath_query",
",",
"$",
"node",
")",
")",
"{",
"$",
"result",
"->",
"loadDomNodeList",
"(",
"$",
"result_node_list",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// whole document",
"if",
"(",
"$",
"result_node_list",
"=",
"$",
"this",
"->",
"xpathQuery",
"(",
"$",
"xpath_query",
")",
")",
"{",
"$",
"result",
"->",
"loadDomNodeList",
"(",
"$",
"result_node_list",
")",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Use xpath and return new DomQuery with resulting nodes
@param string $xpath_query
@return static | [
"Use",
"xpath",
"and",
"return",
"new",
"DomQuery",
"with",
"resulting",
"nodes"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L172-L193 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.setDomDocument | public function setDomDocument(\DOMDocument $document)
{
if (isset($this->document) && $this->document !== $document) {
throw new \Exception('Other DOMDocument already set!');
}
$this->document = $document;
} | php | public function setDomDocument(\DOMDocument $document)
{
if (isset($this->document) && $this->document !== $document) {
throw new \Exception('Other DOMDocument already set!');
}
$this->document = $document;
} | [
"public",
"function",
"setDomDocument",
"(",
"\\",
"DOMDocument",
"$",
"document",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"document",
")",
"&&",
"$",
"this",
"->",
"document",
"!==",
"$",
"document",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Other DOMDocument already set!'",
")",
";",
"}",
"$",
"this",
"->",
"document",
"=",
"$",
"document",
";",
"}"
] | Set dom document
@param \DOMDocument $document
@return void
@throws \Exception if other document is already set | [
"Set",
"dom",
"document"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L228-L235 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.loadDomNodeList | public function loadDomNodeList(\DOMNodeList $dom_node_list)
{
if (!isset($this->document) && $dom_node_list->length === 0) {
throw new \Exception('DOMDocument is missing!');
}
if ($dom_node_list->length > 0) {
$this->setDomDocument($dom_node_list->item(0)->ownerDocument);
}
foreach ($dom_node_list as $node) {
$this->addDomNode($node);
}
} | php | public function loadDomNodeList(\DOMNodeList $dom_node_list)
{
if (!isset($this->document) && $dom_node_list->length === 0) {
throw new \Exception('DOMDocument is missing!');
}
if ($dom_node_list->length > 0) {
$this->setDomDocument($dom_node_list->item(0)->ownerDocument);
}
foreach ($dom_node_list as $node) {
$this->addDomNode($node);
}
} | [
"public",
"function",
"loadDomNodeList",
"(",
"\\",
"DOMNodeList",
"$",
"dom_node_list",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"document",
")",
"&&",
"$",
"dom_node_list",
"->",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'DOMDocument is missing!'",
")",
";",
"}",
"if",
"(",
"$",
"dom_node_list",
"->",
"length",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setDomDocument",
"(",
"$",
"dom_node_list",
"->",
"item",
"(",
"0",
")",
"->",
"ownerDocument",
")",
";",
"}",
"foreach",
"(",
"$",
"dom_node_list",
"as",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"addDomNode",
"(",
"$",
"node",
")",
";",
"}",
"}"
] | Add nodes from dom node list to result set
@param \DOMNodeList $dom_node_list
@return void
@throws \Exception if no document is set and list is empty | [
"Add",
"nodes",
"from",
"dom",
"node",
"list",
"to",
"result",
"set"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L245-L258 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.addDomNode | public function addDomNode(\DOMNode $dom_node, $prepend=false)
{
if ($prepend) {
array_unshift($this->nodes, $dom_node);
} else {
$this->nodes[] = $dom_node;
}
$this->length = \count($this->nodes);
$this->setDomDocument($dom_node->ownerDocument);
} | php | public function addDomNode(\DOMNode $dom_node, $prepend=false)
{
if ($prepend) {
array_unshift($this->nodes, $dom_node);
} else {
$this->nodes[] = $dom_node;
}
$this->length = \count($this->nodes);
$this->setDomDocument($dom_node->ownerDocument);
} | [
"public",
"function",
"addDomNode",
"(",
"\\",
"DOMNode",
"$",
"dom_node",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"prepend",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"nodes",
",",
"$",
"dom_node",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"dom_node",
";",
"}",
"$",
"this",
"->",
"length",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"nodes",
")",
";",
"$",
"this",
"->",
"setDomDocument",
"(",
"$",
"dom_node",
"->",
"ownerDocument",
")",
";",
"}"
] | Add node to result set
@param \DOMNode $dom_node
@param bool $prepend
@return void | [
"Add",
"node",
"to",
"result",
"set"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L268-L278 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.loadContent | public function loadContent(string $content, $encoding='UTF-8')
{
$this->preserve_no_newlines = (strpos($content, '<') !== false && strpos($content, "\n") === false);
if (!\is_bool($this->xml_mode)) {
$this->xml_mode = (stripos($content, '<?xml') === 0);
}
$this->xml_print_pi = (stripos($content, '<?xml') === 0);
$xml_pi_node_added = false;
if (!$this->xml_mode && $encoding && stripos($content, '<?xml') === false) {
$content = '<?xml encoding="'.$encoding.'">'.$content; // add pi node to make libxml use the correct encoding
$xml_pi_node_added = true;
}
libxml_disable_entity_loader(true);
libxml_use_internal_errors(true);
$dom_document = new \DOMDocument('1.0', $encoding);
$dom_document->strictErrorChecking = false;
$dom_document->validateOnParse = false;
$dom_document->recover = true;
if ($this->xml_mode) {
$dom_document->loadXML($content, $this->libxml_options);
} else {
$dom_document->loadHTML($content, $this->libxml_options);
}
$this->setDomDocument($dom_document);
if ($xml_pi_node_added) { // pi node added, now remove it
foreach ($dom_document->childNodes as $node) {
if ($node->nodeType === XML_PI_NODE) {
$dom_document->removeChild($node);
break;
}
}
}
foreach ($dom_document->childNodes as $node) {
$this->nodes[] = $node;
}
$this->length = \count($this->nodes);
} | php | public function loadContent(string $content, $encoding='UTF-8')
{
$this->preserve_no_newlines = (strpos($content, '<') !== false && strpos($content, "\n") === false);
if (!\is_bool($this->xml_mode)) {
$this->xml_mode = (stripos($content, '<?xml') === 0);
}
$this->xml_print_pi = (stripos($content, '<?xml') === 0);
$xml_pi_node_added = false;
if (!$this->xml_mode && $encoding && stripos($content, '<?xml') === false) {
$content = '<?xml encoding="'.$encoding.'">'.$content; // add pi node to make libxml use the correct encoding
$xml_pi_node_added = true;
}
libxml_disable_entity_loader(true);
libxml_use_internal_errors(true);
$dom_document = new \DOMDocument('1.0', $encoding);
$dom_document->strictErrorChecking = false;
$dom_document->validateOnParse = false;
$dom_document->recover = true;
if ($this->xml_mode) {
$dom_document->loadXML($content, $this->libxml_options);
} else {
$dom_document->loadHTML($content, $this->libxml_options);
}
$this->setDomDocument($dom_document);
if ($xml_pi_node_added) { // pi node added, now remove it
foreach ($dom_document->childNodes as $node) {
if ($node->nodeType === XML_PI_NODE) {
$dom_document->removeChild($node);
break;
}
}
}
foreach ($dom_document->childNodes as $node) {
$this->nodes[] = $node;
}
$this->length = \count($this->nodes);
} | [
"public",
"function",
"loadContent",
"(",
"string",
"$",
"content",
",",
"$",
"encoding",
"=",
"'UTF-8'",
")",
"{",
"$",
"this",
"->",
"preserve_no_newlines",
"=",
"(",
"strpos",
"(",
"$",
"content",
",",
"'<'",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"content",
",",
"\"\\n\"",
")",
"===",
"false",
")",
";",
"if",
"(",
"!",
"\\",
"is_bool",
"(",
"$",
"this",
"->",
"xml_mode",
")",
")",
"{",
"$",
"this",
"->",
"xml_mode",
"=",
"(",
"stripos",
"(",
"$",
"content",
",",
"'<?xml'",
")",
"===",
"0",
")",
";",
"}",
"$",
"this",
"->",
"xml_print_pi",
"=",
"(",
"stripos",
"(",
"$",
"content",
",",
"'<?xml'",
")",
"===",
"0",
")",
";",
"$",
"xml_pi_node_added",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"xml_mode",
"&&",
"$",
"encoding",
"&&",
"stripos",
"(",
"$",
"content",
",",
"'<?xml'",
")",
"===",
"false",
")",
"{",
"$",
"content",
"=",
"'<?xml encoding=\"'",
".",
"$",
"encoding",
".",
"'\">'",
".",
"$",
"content",
";",
"// add pi node to make libxml use the correct encoding",
"$",
"xml_pi_node_added",
"=",
"true",
";",
"}",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"dom_document",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"$",
"encoding",
")",
";",
"$",
"dom_document",
"->",
"strictErrorChecking",
"=",
"false",
";",
"$",
"dom_document",
"->",
"validateOnParse",
"=",
"false",
";",
"$",
"dom_document",
"->",
"recover",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"xml_mode",
")",
"{",
"$",
"dom_document",
"->",
"loadXML",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"libxml_options",
")",
";",
"}",
"else",
"{",
"$",
"dom_document",
"->",
"loadHTML",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"libxml_options",
")",
";",
"}",
"$",
"this",
"->",
"setDomDocument",
"(",
"$",
"dom_document",
")",
";",
"if",
"(",
"$",
"xml_pi_node_added",
")",
"{",
"// pi node added, now remove it",
"foreach",
"(",
"$",
"dom_document",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"===",
"XML_PI_NODE",
")",
"{",
"$",
"dom_document",
"->",
"removeChild",
"(",
"$",
"node",
")",
";",
"break",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"dom_document",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"$",
"this",
"->",
"length",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"nodes",
")",
";",
"}"
] | Load html or xml content
@param string $content
@param string $encoding
@return void | [
"Load",
"html",
"or",
"xml",
"content"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L288-L334 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.get | public function get($index)
{
$result = \array_slice($this->nodes, $index, 1); // note: index can be negative
if (\count($result) > 0) {
return $result[0];
}
return null; // return null if no result for key
} | php | public function get($index)
{
$result = \array_slice($this->nodes, $index, 1); // note: index can be negative
if (\count($result) > 0) {
return $result[0];
}
return null; // return null if no result for key
} | [
"public",
"function",
"get",
"(",
"$",
"index",
")",
"{",
"$",
"result",
"=",
"\\",
"array_slice",
"(",
"$",
"this",
"->",
"nodes",
",",
"$",
"index",
",",
"1",
")",
";",
"// note: index can be negative",
"if",
"(",
"\\",
"count",
"(",
"$",
"result",
")",
">",
"0",
")",
"{",
"return",
"$",
"result",
"[",
"0",
"]",
";",
"}",
"return",
"null",
";",
"// return null if no result for key",
"}"
] | Grants access to the DOM nodes of this instance
@param int $index
@return \DOMNode|null | [
"Grants",
"access",
"to",
"the",
"DOM",
"nodes",
"of",
"this",
"instance"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L343-L351 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.find | public function find($selector)
{
if (\is_string($selector)) {
$css_expression = $selector;
} else {
$selector_tag_names = array();
$selector_result = self::create($selector);
foreach ($selector_result as $node) {
$selector_tag_names[] = $node->tagName;
}
$css_expression = implode(',', $selector_tag_names);
}
$xpath_expression = CssToXpath::transform($css_expression);
$result = $this->xpath($xpath_expression);
if (\is_string($selector)) {
$result->css_query = $css_expression;
$result->selector = $css_expression; // jquery style
}
if (isset($selector_result)) {
$new_result_nodes = array();
foreach ($result->nodes as $result_node) {
foreach ($selector_result->nodes as $selector_result_node) {
if ($result_node->isSameNode($selector_result_node)) {
$new_result_nodes[] = $result_node;
}
}
}
$result->nodes = $new_result_nodes;
}
return $result;
} | php | public function find($selector)
{
if (\is_string($selector)) {
$css_expression = $selector;
} else {
$selector_tag_names = array();
$selector_result = self::create($selector);
foreach ($selector_result as $node) {
$selector_tag_names[] = $node->tagName;
}
$css_expression = implode(',', $selector_tag_names);
}
$xpath_expression = CssToXpath::transform($css_expression);
$result = $this->xpath($xpath_expression);
if (\is_string($selector)) {
$result->css_query = $css_expression;
$result->selector = $css_expression; // jquery style
}
if (isset($selector_result)) {
$new_result_nodes = array();
foreach ($result->nodes as $result_node) {
foreach ($selector_result->nodes as $selector_result_node) {
if ($result_node->isSameNode($selector_result_node)) {
$new_result_nodes[] = $result_node;
}
}
}
$result->nodes = $new_result_nodes;
}
return $result;
} | [
"public",
"function",
"find",
"(",
"$",
"selector",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"selector",
")",
")",
"{",
"$",
"css_expression",
"=",
"$",
"selector",
";",
"}",
"else",
"{",
"$",
"selector_tag_names",
"=",
"array",
"(",
")",
";",
"$",
"selector_result",
"=",
"self",
"::",
"create",
"(",
"$",
"selector",
")",
";",
"foreach",
"(",
"$",
"selector_result",
"as",
"$",
"node",
")",
"{",
"$",
"selector_tag_names",
"[",
"]",
"=",
"$",
"node",
"->",
"tagName",
";",
"}",
"$",
"css_expression",
"=",
"implode",
"(",
"','",
",",
"$",
"selector_tag_names",
")",
";",
"}",
"$",
"xpath_expression",
"=",
"CssToXpath",
"::",
"transform",
"(",
"$",
"css_expression",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xpath",
"(",
"$",
"xpath_expression",
")",
";",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"selector",
")",
")",
"{",
"$",
"result",
"->",
"css_query",
"=",
"$",
"css_expression",
";",
"$",
"result",
"->",
"selector",
"=",
"$",
"css_expression",
";",
"// jquery style",
"}",
"if",
"(",
"isset",
"(",
"$",
"selector_result",
")",
")",
"{",
"$",
"new_result_nodes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"nodes",
"as",
"$",
"result_node",
")",
"{",
"foreach",
"(",
"$",
"selector_result",
"->",
"nodes",
"as",
"$",
"selector_result_node",
")",
"{",
"if",
"(",
"$",
"result_node",
"->",
"isSameNode",
"(",
"$",
"selector_result_node",
")",
")",
"{",
"$",
"new_result_nodes",
"[",
"]",
"=",
"$",
"result_node",
";",
"}",
"}",
"}",
"$",
"result",
"->",
"nodes",
"=",
"$",
"new_result_nodes",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the descendants of each element in the current set of matched elements, filtered by a selector
@param string|static|\DOMNodeList|\DOMNode $selector A string containing a selector expression,
or DomQuery|DOMNodeList|DOMNode instance to match against
@return static | [
"Get",
"the",
"descendants",
"of",
"each",
"element",
"in",
"the",
"current",
"set",
"of",
"matched",
"elements",
"filtered",
"by",
"a",
"selector"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L361-L395 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.getNextElement | protected static function getNextElement(\DOMNode $node)
{
while ($node && ($node = $node->nextSibling)) {
if ($node instanceof \DOMElement) {
break;
}
}
return $node;
} | php | protected static function getNextElement(\DOMNode $node)
{
while ($node && ($node = $node->nextSibling)) {
if ($node instanceof \DOMElement) {
break;
}
}
return $node;
} | [
"protected",
"static",
"function",
"getNextElement",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"while",
"(",
"$",
"node",
"&&",
"(",
"$",
"node",
"=",
"$",
"node",
"->",
"nextSibling",
")",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"\\",
"DOMElement",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"node",
";",
"}"
] | Get next element from node
@param \DOMNode $node
@return \DOMNode | [
"Get",
"next",
"element",
"from",
"node"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L404-L413 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.getPreviousElement | protected static function getPreviousElement(\DOMNode $node)
{
while ($node && ($node = $node->previousSibling)) {
if ($node instanceof \DOMElement) {
break;
}
}
return $node;
} | php | protected static function getPreviousElement(\DOMNode $node)
{
while ($node && ($node = $node->previousSibling)) {
if ($node instanceof \DOMElement) {
break;
}
}
return $node;
} | [
"protected",
"static",
"function",
"getPreviousElement",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"while",
"(",
"$",
"node",
"&&",
"(",
"$",
"node",
"=",
"$",
"node",
"->",
"previousSibling",
")",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"\\",
"DOMElement",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"node",
";",
"}"
] | Get next element from node
@param \DOMNode $node
@return \DOMNode | [
"Get",
"next",
"element",
"from",
"node"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L422-L431 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.findOrFail | public function findOrFail($selector)
{
$result = $this->find($selector);
if ($result->length === 0) {
if (\is_string($selector)) {
throw new \Exception('Find with selector "'.$selector.'" failed!');
}
throw new \Exception('Find with node (collection) as selector failed!');
}
return $result;
} | php | public function findOrFail($selector)
{
$result = $this->find($selector);
if ($result->length === 0) {
if (\is_string($selector)) {
throw new \Exception('Find with selector "'.$selector.'" failed!');
}
throw new \Exception('Find with node (collection) as selector failed!');
}
return $result;
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"selector",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"selector",
")",
";",
"if",
"(",
"$",
"result",
"->",
"length",
"===",
"0",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"selector",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Find with selector \"'",
".",
"$",
"selector",
".",
"'\" failed!'",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'Find with node (collection) as selector failed!'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the descendants of each element in the current set of matched elements, filtered by a selector.
If no results are found a exception is thrown.
@param string|static|\DOMNodeList|\DOMNode $selector A string containing a selector expression,
or DomQuery|DOMNodeList|DOMNode instance to match against
@return static
@throws \Exception if no results are found | [
"Get",
"the",
"descendants",
"of",
"each",
"element",
"in",
"the",
"current",
"set",
"of",
"matched",
"elements",
"filtered",
"by",
"a",
"selector",
".",
"If",
"no",
"results",
"are",
"found",
"a",
"exception",
"is",
"thrown",
"."
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L453-L463 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.each | public function each(callable $callback)
{
foreach ($this->nodes as $index => $node) {
$return_value = \call_user_func($callback, $node, $index);
if ($return_value === false) {
break;
}
}
return $this;
} | php | public function each(callable $callback)
{
foreach ($this->nodes as $index => $node) {
$return_value = \call_user_func($callback, $node, $index);
if ($return_value === false) {
break;
}
}
return $this;
} | [
"public",
"function",
"each",
"(",
"callable",
"$",
"callback",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"index",
"=>",
"$",
"node",
")",
"{",
"$",
"return_value",
"=",
"\\",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"node",
",",
"$",
"index",
")",
";",
"if",
"(",
"$",
"return_value",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Iterate over result set and executing a callback for each node
@param callable $callback
@return $this | [
"Iterate",
"over",
"result",
"set",
"and",
"executing",
"a",
"callback",
"for",
"each",
"node"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L472-L483 |
Rct567/DomQuery | src/Rct567/DomQuery/DomQueryNodes.php | DomQueryNodes.map | public function map(callable $callback)
{
$result = array();
foreach ($this->nodes as $index => $node) {
$return_value = \call_user_func($callback, $node, $index);
if ($return_value === null) {
continue;
} elseif (\is_array($return_value)) {
$result = \array_merge($result, $return_value);
} else {
$result[] = $return_value;
}
}
return $result;
} | php | public function map(callable $callback)
{
$result = array();
foreach ($this->nodes as $index => $node) {
$return_value = \call_user_func($callback, $node, $index);
if ($return_value === null) {
continue;
} elseif (\is_array($return_value)) {
$result = \array_merge($result, $return_value);
} else {
$result[] = $return_value;
}
}
return $result;
} | [
"public",
"function",
"map",
"(",
"callable",
"$",
"callback",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"index",
"=>",
"$",
"node",
")",
"{",
"$",
"return_value",
"=",
"\\",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"node",
",",
"$",
"index",
")",
";",
"if",
"(",
"$",
"return_value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"\\",
"is_array",
"(",
"$",
"return_value",
")",
")",
"{",
"$",
"result",
"=",
"\\",
"array_merge",
"(",
"$",
"result",
",",
"$",
"return_value",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"return_value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Pass each element in the current matched set through a function,
producing an array containing the return values
@param callable $callback
@return array | [
"Pass",
"each",
"element",
"in",
"the",
"current",
"matched",
"set",
"through",
"a",
"function",
"producing",
"an",
"array",
"containing",
"the",
"return",
"values"
] | train | https://github.com/Rct567/DomQuery/blob/40ff02b4337e704c5816a6ecae11182dd705f136/src/Rct567/DomQuery/DomQueryNodes.php#L493-L510 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.