Format setSpec header element as XML tags for inclusion in final record.

@param object $setSpec Header setSpec element (in SimpleXML format).

@return string
180243
protected function getHeaderSetAdditions($setSpec)
    {
        $insert = '';
        foreach ($setSpec as $current) {
            $set = (string)$current;
            if ($this->injectSetSpec) {
                $insert .= $this->createTag($this->injectSetSpec, $set);
            }
            if ($this->injectSetName) {
                $name = $this->setNames[$set] ?? $set;
                $insert .= $this->createTag($this->injectSetName, $name);
            }
        }
        return $insert;
    }
1103449
public function formatHeaderAndRemovePrefix($header, $prefix = 'HTTP_') {
        if (str_starts_with($header, $prefix)) {
            $header = substr($header, strlen($prefix));
        }

        return $this->formatHeader($header);
    }
798840
protected function setHeaderCommon($headerFeatures = [])
    {
        $sReturn = [];
        $this->initializeSprGlbAndSession();
        $sHK     = $this->tCmnSuperGlobals->get('specialHook');
        if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
            return ''; // no Header
        }
        $fixedHeaderElements = [
            'start'    => '<!DOCTYPE html>',
            'lang'     => $this->setHeaderLanguage($headerFeatures),
            'head'     => '<head>',
            'charset'  => '<meta charset="utf-8" />',
            'viewport' => '<meta name="viewport" content="width=device-width height=device-height initial-scale=1" />',
        ];
        if ($headerFeatures !== []) {
            $aFeatures = [];
            foreach ($headerFeatures as $key => $value) {
                $aFeatures[] = $this->setHeaderFeatures($key, $value);
            }
            return implode('', $fixedHeaderElements) . implode('', $aFeatures) . '</head>' . '<body>';
        }
        $sReturn[] = implode('', $fixedHeaderElements) . '</head>' . '<body>'
            . '<p style="background-color:red;color:#FFF;">The parameter sent to '
            . __FUNCTION__ . ' must be a non-empty array</p>' . $this->setFooterCommon();
        throw new \Exception(implode('', $sReturn));
    }
426630
public function build(ResultSpec $result): string
    {
        $response = [];
        $units = $result->getResults();

        foreach ($units as $unit) {
            /** @var AbstractResult $unit */
            if ($unit instanceof Result) {
                /** @var Result $unit */
                $response[] = [
                    'jsonrpc' => '2.0',
                    'result' => $this->preBuild($unit->getResult()),
                    'id'     => $unit->getId()
                ];
            } elseif ($unit instanceof Error) {
                /** @var Error $unit */
                $baseException = $unit->getBaseException();
                $response[] = [
                    'jsonrpc' => '2.0',
                    'error' => [
                        'code'    => $baseException->getJsonRpcCode(),
                        'message' => $this->getErrorMessage($baseException->getJsonRpcCode()),
                        'data'    => $baseException->getJsonRpcData()
                    ],
                    'id' => $unit->getId()
                ];
            }
        }

        if (empty($response)) {
            return '';
        }

        if ($result->isSingleResult()) {
            return json_encode($response[0]);
        }

        return json_encode($response);
    }
406836
@Beta
    public PutItemSpec withExpressionSpec(PutItemExpressionSpec xspec) {
        return withConditionExpression(xspec.getConditionExpression())
              .withNameMap(xspec.getNameMap())
              .withValueMap(xspec.getValueMap())
              ;
    }
965715
public function findHeader($header)
    {
        $xpath = '/thead/tr/th'.(is_int($header) ? '['.$header.']' : '[contains(text(), "'.$header.'")]');

        \PHPUnit_Framework_Assert::assertNotNull(
            $node = $this->findGrid()->find('xpath', $xpath),
            sprintf('The grid header "%s" could not be found.', $header)
        );

        return $node;
    }
546945
final public function createFixedHeader(int $variableHeaderLength): string
    {
        $this->logger->debug('Creating fixed header with values', [
            'controlPacketValue' => self::getControlPacketValue(),
            'specialFlags' => $this->specialFlags,
            'variableHeaderLength' => $variableHeaderLength,
            'composed' => decbin(chr((self::getControlPacketValue() << 4) | $this->specialFlags)),
        ]);

        // Binary OR is safe to do because the first 4 bits are always 0 after shifting
        return
            chr((self::getControlPacketValue() << 4) | $this->specialFlags) .
            Utilities::formatRemainingLengthOutput($variableHeaderLength);
    }
937970
public function convertSimpleSpec($spec) {
    if (($year = Preg::qmatch($spec,'/^([0-9]+) YEARs?/i',1,FALSE)) !== FALSE) {
      return sprintf('P%dY',$year);
    }

    if (($day = Preg::qmatch($spec,'/^([0-9]+) DAYs?/i',1,FALSE)) !== FALSE) {
      return sprintf('P%dD',$day);
    }
    
    return $spec;
  }
482182
private function _createXml($enc)
    {
        $dom = new DOMDocument('1.0', 'UTF-8');
        $root = $dom->createElement("Plugin_".$this->_plugin_name);
        $dom->appendChild($root);
        $this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
    }
317695
public function DKIM_HeaderC($s) {
    $s=preg_replace("/\r\n\s+/"," ",$s);
    $lines=explode("\r\n",$s);
    foreach ($lines as $key=>$line) {
      list($heading,$value)=explode(":",$line,2);
      $heading=strtolower($heading);
      $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
      $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
    }
    $s=implode("\r\n",$lines);
    return $s;
  }
885673
public function parseSubfields($subfieldspec)
    {
        if (!preg_match_all('/'.$this->SUBFIELD.'/', $subfieldspec, $_subfieldMatches, PREG_SET_ORDER)) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::SFCHAR,
                $subfieldspec
            );
        }
        /*
        * For each subfield (array) do anonymous function
        * - first filter empty elements
        * - second look for subspecs
        * - match subspecs and match subTerms
        * - return everything in the array of subfields
        */
        array_walk(
            $_subfieldMatches,
            function (&$_subfield) use (&$test) {
                $_subfield = array_filter($_subfield, 'strlen');

                $test .= $_subfield['subfield'];

                if (array_key_exists('subspecs', $_subfield)) {
                    $_ss = [];

                    if (!$_subfieldSubSpecs = $this->matchSubSpecs($_subfield['subspecs'])) {
                        // TODO: raise error;
                    }

                    foreach ($_subfieldSubSpecs as $key => $_subfieldSubSpec) {
                        if (1 < count($_subfieldSubSpec)) {
                            foreach ($_subfieldSubSpec as $orSubSpec) {
                                $_or[] = $this->matchSubTerms($orSubSpec);
                            }
                            $_ss[] = $_or;
                        } else {
                            $_ss[] = $this->matchSubTerms($_subfieldSubSpec[0]);
                        }
                    }

                    $_subfield['subspecs'] = $_ss;
                }
            }
        );

        if ($test !== $subfieldspec) {
            throw new InvalidMARCspecException(
                InvalidMARCspecException::SF.
                InvalidMARCspecException::USELESS,
                $subfieldspec
            );
        }

        return $_subfieldMatches;
    }
467654
public function setEncoding($enc)
    {
        $enc = strtoupper($enc);
        if ($enc != $this->_encoding) {
            $this->_encoding = $enc;
            if ($this->_translator) $this->_translator->setEncoding($enc);

            $this->resetPrepared();
        }
        return $this;
    }
434947
private static function encodeFlags(Header $header): int
    {
        return 0x0 |
            ($header->isResponse() & 0x1) << 15 |
            ($header->getOpcode() & 0xf) << 11 |
            ($header->isAuthoritative() & 0x1) << 10 |
            ($header->isTruncated() & 0x1) << 9 |
            ($header->isRecursionDesired() & 0x1) << 8 |
            ($header->isRecursionAvailable() & 0x1) << 7 |
            ($header->getZ() & 0x7) << 4 |
            ($header->getRcode() & 0xf);
    }
831801
public static function getRegexp($enc)
    {
        switch($enc) {
        case self::PNO_SE:
            /*
             * All positions except C contain numbers 0-9.
             *
             * PNO:
             * YYYYMMDDCNNNN, C = -|+  length 13
             * YYYYMMDDNNNN                   12
             * YYMMDDCNNNN                    11
             * YYMMDDNNNN                     10
             *
             * ORGNO:
             * XXXXXXNNNN
             * XXXXXX-NNNN
             * 16XXXXXXNNNN
             * 16XXXXXX-NNNN
             *
             */
            return '/^[0-9]{6,6}(([0-9]{2,2}[-\+]{1,1}[0-9]{4,4})|([-\+]'.
                '{1,1}[0-9]{4,4})|([0-9]{4,6}))$/';
        case self::PNO_NO:
            /*
             * All positions contain numbers 0-9.
             *
             * Pno
             * DDMMYYIIIKK    ("fodelsenummer" or "D-nummer") length = 11
             * DDMMYY-IIIKK   ("fodelsenummer" or "D-nummer") length = 12
             * DDMMYYYYIIIKK  ("fodelsenummer" or "D-nummer") length = 13
             * DDMMYYYY-IIIKK ("fodelsenummer" or "D-nummer") length = 14
             *
             * Orgno
             * Starts with 8 or 9.
             *
             * NNNNNNNNK      (orgno)                         length = 9
             */
            return '/^[0-9]{6,6}((-[0-9]{5,5})|([0-9]{2,2}((-[0-9]'.
                '{5,5})|([0-9]{1,1})|([0-9]{3,3})|([0-9]{5,5))))$/';
        case self::PNO_FI:
            /*
             * Pno
             * DDMMYYCIIIT
             * DDMMYYIIIT
             * C = century, '+' = 1800, '-' = 1900 och 'A' = 2000.
             * I = 0-9
             * T = 0-9, A-F, H, J, K-N, P, R-Y
             *
             * Orgno
             * NNNNNNN-T
             * NNNNNNNT
             * T = 0-9, A-F, H, J, K-N, P, R-Y
             */
            return '/^[0-9]{6,6}(([A\+-]{1,1}[0-9]{3,3}[0-9A-FHJK-NPR-Y]'.
                '{1,1})|([0-9]{3,3}[0-9A-FHJK-NPR-Y]{1,1})|([0-9]{1,1}-{0,1}'.
                '[0-9A-FHJK-NPR-Y]{1,1}))$/i';
        case self::PNO_DK:
            /*
             * Pno
             * DDMMYYNNNG       length 10
             * G = gender, odd/even for men/women.
             *
             * Orgno
             * XXXXXXXX         length 8
             */
            return '/^[0-9]{8,8}([0-9]{2,2})?$/';
        case self::PNO_NL:
        case self::PNO_DE:
            /**
             * Pno
             * DDMMYYYYG         length 9
             * DDMMYYYY                 8
             *
             * Orgno
             * XXXXXXX                  7  company org nr
             */
            return '/^[0-9]{7,9}$/';
        case self::EMAIL:
            /**
             * Validates an email.
             */
            return '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]'.
                '+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z0-9-][a-zA-Z0-9-]+)+$/';
        case self::CELLNO:
            /**
             * Validates a cellno.
             * @TODO Is this encoding only for Sweden?
             */
            return '/^07[\ \-0-9]{8,13}$/';
        default:
            throw new Klarna_UnknownEncodingException($enc);
        }
    }
1027118
protected function prepareRequestHeader(Header $header): array
    {
        $result = [];
        foreach ($header as $name => $value) {
            $result[] = $name . ': ' . $value;
        }
        return $result;
    }
247762
private function prepareSetAttributes()
    {
        $fragment = new CNabuPHPMethodBuilder($this, 'setAttributes', CNabuPHPMethodBuilder::METHOD_PROTECTED);
        $fragment->addComment("Set default attributes of $this->entity_name in XML Element.");
        $fragment->addParam(
            'element', 'SimpleXMLElement', false, null, 'SimpleXMLElement',
            'XML Element to set attributes'
        );

        if ($this->is_hashed) {
            $fragment->addFragment(
                "\$element->addAttribute('GUID', \$this->nb_data_object->grantHash(true));"
            );
        }

        if (is_array($this->element_attributes) && count($this->element_attributes) > 0) {
            $fragment->addFragment('$this->putAttributesFromList($element, array(');
            $count = count($this->element_attributes);
            foreach ($this->element_attributes as $field => $attr) {
                $fragment->addFragment("    '$field' => '$attr'" . (--$count > 0 ? ',' : ''));
            }
            $fragment->addFragment('), false);');
        }

        $this->getDocument()->addUse('\SimpleXMLElement');

        $this->addFragment($fragment);
    }
774216
final public static function secondsToSpec($secs)
    {
        if (!empty($secs)) {
            try {
                $interval = self::secondsToInterval($secs);
                return self::intervalToSpec($interval);
            } catch (\Exception $e) {
            }
        }

        return "";
    }