for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Phalcon\Html\Link\Serializer;
use function implode;
use function is_array;
use function is_bool;
* Class Phalcon\Http\Link\Serializer\Header
class Header implements SerializerInterface
{
* Serializes all the passed links to a HTTP link header
* @param array $links
* @return string|null
public function serialize(array $links): ?string
$elements = [];
$result = null;
foreach ($links as $link) {
* Leave templated links alone
if ($link->isTemplated()) {
continue;
}
* Split the parts of the attributes so that we can parse them
$attributes = $link->getAttributes();
$rels = $link->getRels();
$parts = [
"",
"rel=\"" . implode(" ", $rels) . "\""
];
foreach ($attributes as $key => $value) {
if (is_array($value)) {
foreach ($value as $subValue) {
$parts[] = $key . "=\"" . $subValue . "\"";
if (!is_bool($value)) {
$parts[] = $key . "=\"" . $value . "\"";
if (true === $value) {
$parts[] = $key;
$elements[] = "<"
. $link->getHref()
. ">"
. implode("; ", $parts);
if (count($elements) > 0) {
$result = implode(",", $elements);
return $result;