<?php
namespace ModulesAbstract\ElectronicInvoice\UBL21Structure; class AbstractPeppolElement { public function __get($name) { throw new \Exception(sprintf("[%s] Undefined attribute '%s' (trying to read it)", get_class($this), $name)); } public function __set($name, $value) { throw new \Exception(sprintf("[%s] Undefined attribute '%s' (trying to set it to '%s')", get_class($this), $name, (is_scalar($value)?$value:var_export($value, true)))); } public function getAttributes() { return []; } public function getChilds() { $members = array_keys(get_object_vars($this)); return array_combine($members, $members); } public function renderField(string $field, $value): string { return $value; } public function tagHasValue(string $field, $value, string $comparisonMode, $object, array $parents): bool { $ret = false; if ($comparisonMode=='strict') { $ret = ($value!==null); } elseif ($comparisonMode=='loose') { if ($value) { $ret = true; } else { $ret = in_array($value, [(int)0, (float)0, false], true); } } else { throw new \Exception("Unknown comparisonMode specified: '$comparisonMode'"); } return $ret; } protected function customRenderer(?string $formatStr, $value): string { $fmtArr = explode(".", (string)$formatStr); switch ($fmtArr[0]) { case 'NF': $decimals = ($fmtArr[1]?:2); if ($fmtArr[1]=='auto') { $decimals = \App\Config\CurrencyDecimals::getCurrencyDecimals($this->currencyID); } return sprintf("%.{$decimals}f", $value); break; case 'NI': return sprintf("%d", $value); break; case 'B': return ($value?'true':'false'); break; case 'D': return $value; break; case 'T': return $value; break; case 'base64': return base64_encode($value); break; case null: return $value; break; default: throw new \Exception("Unknown format {$formatStr}"); } } } 