-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
216 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\Attributes; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class AsCssProvider | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle; | ||
|
||
final class CssProvider | ||
{ | ||
public function __construct( | ||
private readonly iterable $providers, | ||
) { | ||
} | ||
|
||
public function __invoke(array $config): iterable | ||
{ | ||
foreach ($this->providers as $provider) { | ||
\assert(is_callable($provider), sprintf('Provider "%s" is not callable.', get_debug_type($provider))); | ||
|
||
$reflector = new \ReflectionFunction($provider(...)); | ||
|
||
$arguments = []; | ||
foreach ($reflector->getParameters() as $parameter) { | ||
$name = $parameter->getName(); | ||
$type = $parameter->getType(); | ||
|
||
\assert( | ||
$type instanceof \ReflectionNamedType, | ||
sprintf('Parameter "%s" of provider "%s" has no or more than one type.', $name, $provider::class), | ||
); | ||
|
||
$typeName = $type->getName(); | ||
|
||
\assert( | ||
in_array($typeName, ['array', 'bool', 'float', 'int', 'string']) || class_exists($typeName), | ||
sprintf('Parameter "%s" of provider "%s" has an unsupported type "%s".', $name, $provider::class, $typeName), | ||
); | ||
|
||
if (isset($config[$name])) { | ||
$argument = $config[$name]; | ||
|
||
if (class_exists($typeName)) { | ||
$argument = new $typeName(...$argument); | ||
} | ||
|
||
$arguments[$name] = $argument; | ||
} | ||
} | ||
|
||
if ($arguments || !$reflector->getNumberOfParameters()) { | ||
yield from $provider(...$arguments); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
use Neusta\Pimcore\BackendBrandingBundle\Attributes\AsCssProvider; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssProperty; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssRule; | ||
|
||
#[AsCssProvider] | ||
final class BezelColor | ||
{ | ||
public function __invoke(string $bezelColor): iterable | ||
{ | ||
$backgroundColor = new CssProperty('background-color', $bezelColor); | ||
|
||
yield new CssRule('body.x-body #pimcore_body', $backgroundColor); | ||
yield new CssRule('body.x-body #pimcore_loading.loaded', $backgroundColor); | ||
yield new CssRule('body.x-body .sf-minitoolbar', $backgroundColor); | ||
yield new CssRule('body.x-body #pimcore_panel_tabs > .x-panel-bodyWrap > .x-tab-bar', $backgroundColor); | ||
yield new CssRule('#pimcore_loading.loaded', $backgroundColor); | ||
yield new CssRule('.x-body .sf-minitoolbar', $backgroundColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
use Neusta\Pimcore\BackendBrandingBundle\Attributes\AsCssProvider; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssProperty; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssRule; | ||
|
||
#[AsCssProvider] | ||
final class SidebarColor | ||
{ | ||
public function __invoke(string $sidebarColor): iterable | ||
{ | ||
$backgroundColor = new CssProperty('background-color', $sidebarColor); | ||
|
||
yield new CssRule('#pimcore_sidebar', $backgroundColor); | ||
yield new CssRule('#pimcore_loading.loaded', $backgroundColor); | ||
yield new CssRule('.x-body .sf-minitoolbar', $backgroundColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
use Neusta\Pimcore\BackendBrandingBundle\Attributes\AsCssProvider; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssProperty; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssRule; | ||
|
||
#[AsCssProvider] | ||
final class Signet | ||
{ | ||
public function __invoke(SignetConfig $signet): iterable | ||
{ | ||
yield $signetRule = new CssRule('#pimcore_signet', | ||
new CssProperty('background-image', $signet->url, isUrl: true), | ||
new CssProperty('background-size', $signet->size), | ||
new CssProperty('background-position', $signet->position), | ||
); | ||
|
||
if (isset($signet->color)) { | ||
$signetRule->setProperty(new CssProperty('background-color', $signet->color, isImportant: true)); | ||
|
||
yield new CssRule('#pimcore_avatar', | ||
new CssProperty('background-color', $signet->color, isImportant: true), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
final class SignetConfig | ||
{ | ||
public function __construct( | ||
public readonly string $url, | ||
public readonly string $size, | ||
public readonly string $position, | ||
public readonly ?string $color = null, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
use Neusta\Pimcore\BackendBrandingBundle\Attributes\AsCssProvider; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssProperty; | ||
use Neusta\Pimcore\BackendBrandingBundle\Css\CssRule; | ||
|
||
#[AsCssProvider] | ||
final class TabBarIcon | ||
{ | ||
public function __invoke(TabBarIconConfig $tabBarIcon): iterable | ||
{ | ||
$tabBarIconRule = new CssRule('#pimcore_panel_tabs > .x-panel-bodyWrap > .x-tab-bar', | ||
new CssProperty('background-image', $tabBarIcon->url, isUrl: true), | ||
); | ||
|
||
if (isset($tabBarIcon->size)) { | ||
$tabBarIconRule->setProperty(new CssProperty('background-size', $tabBarIcon->size)); | ||
} | ||
|
||
if (isset($tabBarIcon->position)) { | ||
$tabBarIconRule->setProperty(new CssProperty('background-position', $tabBarIcon->position)); | ||
} | ||
|
||
yield $tabBarIconRule; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\BackendBrandingBundle\CssProvider; | ||
|
||
final class TabBarIconConfig | ||
{ | ||
public function __construct( | ||
public readonly string $url, | ||
public readonly ?string $size = null, | ||
public readonly ?string $position = null, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters