<?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\Layout\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function ($script = null) { // it's stack for <head> $headScripts = Registry::get('layout:headScripts') ?: []; if (null === $script) { $headScripts = array_unique($headScripts); // clear system vars Registry::set('layout:headScripts', []); $headScripts = array_map([$this, 'script'], $headScripts); return join("\n", $headScripts); } else { $headScripts[] = $script; Registry::set('layout:headScripts', $headScripts); return null; } };
<?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\Layout\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function (array $data = []) { if (sizeof($data)) { Registry::set('layout:breadcrumbs', $data); return null; } else { return Registry::get('layout:breadcrumbs'); } };
* @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\Layout\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function ($title = null, $position = Layout::POS_REPLACE, $separator = ' :: ') { // it's stack for <title> tag if (null === $title) { return Registry::get('layout:title'); } else { $oldTitle = Registry::get('layout:title'); // switch statement for text position switch ($position) { case Layout::POS_PREPEND: $result = $title . (!$oldTitle ?: $separator . $oldTitle); break; case Layout::POS_APPEND: $result = (!$oldTitle ?: $oldTitle . $separator) . $title; break; case Layout::POS_REPLACE: default: $result = $title; break; } Registry::set('layout:title', $result); return null;
/** * Test Registry configuration setup */ public function testRegistry() { $this->assertEquals(["moo" => "baz"], Proxy\Config::getData("registry")); $this->assertEquals("baz", Proxy\Config::getData("registry", "moo")); $this->assertEquals("baz", Proxy\Registry::get('moo')); }
/** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\View\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function ($name = null, $content = null) { // it's stack for <head> $meta = Registry::get('layout:meta') ?: []; if ($name !== null && $content !== null) { $meta[] = ['name' => $name, 'content' => $content]; Registry::set('layout:meta', $meta); return null; } elseif (is_array($name)) { $meta[] = $name; Registry::set('layout:meta', $meta); return null; } elseif (is_null($name) && is_null($content)) { if (sizeof($meta)) { // prepare to output $meta = array_map(function ($attr) { return '<meta ' . $this->attributes($attr) . '/>'; }, $meta); // clear system vars
<?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\Layout\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function ($style = null, $media = 'all') { // it's stack for <head> $headStyle = Registry::get('layout:headStyle') ?: []; if (null === $style) { // clear system vars Registry::set('layout:headStyle', []); array_walk($headStyle, function (&$item, $key) { $item = $this->style($key, $item); }); return join("\n", $headStyle); } else { $headStyle[$style] = $media; Registry::set('layout:headStyle', $headStyle); return null; } };
/** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\View\Helper; use Bluz\Layout\Layout; use Bluz\Proxy\Registry; return function (array $link = null) { // it's stack for <head> $links = Registry::get('layout:link') ?: []; if (is_null($link)) { // prepare to output $links = array_map(function ($attr) { return '<link ' . $this->attributes($attr) . '/>'; }, $links); // clear system vars Registry::set('layout:link', []); $links = array_unique($links); return join("\n", $links); } else { $links[] = $link; Registry::set('layout:link', $links); return null; } };