This repository was archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheme.php
More file actions
96 lines (85 loc) · 1.83 KB
/
Theme.php
File metadata and controls
96 lines (85 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Cli\Component\Theme;
use Ulrack\Cli\Common\Theme\StyleInterface;
use Ulrack\Cli\Common\Theme\ThemeInterface;
class Theme implements ThemeInterface
{
/**
* Contains the styles of the theme.
*
* @var StyleInterface[]
*/
private $styles = [];
/**
* Contains the default style.
*
* @var StyleInterface
*/
private $defaultStyle;
/**
* Contains the variables for the theme.
*
* @var mixed[]
*/
private $variables;
/**
* Constructor.
*
* @param StyleInterface $defaultStyle
*/
public function __construct(
StyleInterface $defaultStyle = null
) {
$this->defaultStyle = $defaultStyle ?? new VoidStyle();
}
/**
* Adds a style to a keyword.
*
* @param string $key
* @param StyleInterface $style
*
* @return void
*/
public function addStyle(string $key, StyleInterface $style): void
{
$this->styles[$key] = $style;
}
/**
* Adds a variable to the theme.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function addVariable(string $key, $value): void
{
$this->variables[$key] = $value;
}
/**
* Retrieve a style based on the provided keyword.
*
* @param string $key
*
* @return StyleInterface
*/
public function getStyle(string $key): StyleInterface
{
return $this->styles[$key] ?? $this->defaultStyle;
}
/**
* Retrieves the variable of the theme.
*
* @param string $key
*
* @return mixed
*/
public function getVariable(string $key)
{
return $this->variables[$key];
}
}