2 declare(strict_types = 1);
102 public function addProperty(
string $property,
string $content, array $subProperties = [],
bool $replace =
false,
string $type =
'')
104 $property = strtolower($property);
106 if (isset($this->handledProperties[$property])) {
107 $subPropertiesArray = [];
108 foreach ($subProperties as $subPropertyKey => $subPropertyValue) {
109 if (isset($this->handledProperties[$property][
'allowedSubProperties'][$subPropertyKey])) {
110 $subPropertiesArray[$subPropertyKey] = is_array($subPropertyValue) ? $subPropertyValue : [$subPropertyValue];
113 if (!isset($this->properties[$property]) || empty($this->properties[$property])) {
114 $this->properties[$property][] = [
'content' => $content,
'subProperties' => $subPropertiesArray];
116 if ($replace ===
true) {
118 $this->properties[$property][] = [
'content' => $content,
'subProperties' => $subPropertiesArray];
122 if (isset($this->handledProperties[$property][
'allowMultipleOccurrences']) &&
123 (
bool)$this->handledProperties[$property][
'allowMultipleOccurrences']
125 $this->properties[$property][] = [
'content' => $content,
'subProperties' => $subPropertiesArray];
130 foreach ($this->handledProperties as $handledProperty => $handledPropertyConfig) {
131 if (!isset($handledPropertyConfig[
'allowedSubProperties'])) {
134 foreach ((array)$handledPropertyConfig[
'allowedSubProperties'] as $allowedSubProperty => $allowedSubPropertyConfig) {
135 $propertyKey = is_array($allowedSubPropertyConfig) ? $allowedSubProperty : $allowedSubPropertyConfig;
137 if ($property !== $handledProperty . $this->subPropertySeparator . $propertyKey ||
138 !isset($this->properties[$handledProperty])
143 $propertyArrayKeys = array_keys($this->properties[$handledProperty]);
144 $lastIndex = end($propertyArrayKeys);
146 if (!isset($this->properties[$handledProperty][$lastIndex][
'subProperties'][$propertyKey])) {
147 $this->properties[$handledProperty][$lastIndex][
'subProperties'][$propertyKey][] = $content;
149 if ($replace ===
true) {
150 unset($this->properties[$handledProperty][$lastIndex][
'subProperties'][$propertyKey]);
151 $this->properties[$handledProperty][$lastIndex][
'subProperties'][$propertyKey][] = $content;
155 if (is_array($allowedSubPropertyConfig) &&
156 isset($allowedSubPropertyConfig[
'allowMultipleOccurrences']) &&
157 (
bool)$allowedSubPropertyConfig[
'allowMultipleOccurrences']
159 $this->properties[$handledProperty][$lastIndex][
'subProperties'][$propertyKey][] = $content;
167 throw new \UnexpectedValueException(
168 sprintf(
'This MetaTagManager can\'t handle property "%s"', $property),
191 public function getProperty(
string $property,
string $type =
''): array
193 $property = strtolower($property);
195 if (isset($this->properties[$property])) {
196 return $this->properties[$property];
210 $property = strtolower($property);
214 if (isset($this->handledProperties[$property][
'nameAttribute'])
215 && !empty((
string)$this->handledProperties[$property][
'nameAttribute'])) {
216 $nameAttribute = (string)$this->handledProperties[$property][
'nameAttribute'];
220 if (isset($this->handledProperties[$property][
'contentAttribute'])
221 && !empty((
string)$this->handledProperties[$property][
'contentAttribute'])) {
222 $contentAttribute = (string)$this->handledProperties[$property][
'contentAttribute'];
225 if ($nameAttribute && $contentAttribute) {
226 foreach ($this->
getProperty($property) as $propertyItem) {
227 $metaTags[] =
'<meta ' .
228 htmlspecialchars($nameAttribute) .
'="' . htmlspecialchars($property) .
'" ' .
229 htmlspecialchars($contentAttribute) .
'="' . htmlspecialchars($propertyItem[
'content']) .
'" />';
231 if (!count($propertyItem[
'subProperties'])) {
234 foreach ($propertyItem[
'subProperties'] as $subProperty => $subPropertyItems) {
235 foreach ($subPropertyItems as $subPropertyItem) {
236 $metaTags[] =
'<meta ' .
237 htmlspecialchars($nameAttribute) .
'="' . htmlspecialchars($property . $this->subPropertySeparator . $subProperty) .
'" ' .
238 htmlspecialchars($contentAttribute) .
'="' . htmlspecialchars((
string)$subPropertyItem) .
'" />';
244 return implode(PHP_EOL, $metaTags);
255 foreach (array_keys($this->properties) as $property) {
259 return implode(PHP_EOL, $metatags);
271 $property = strtolower($property);
273 unset($this->properties[$property]);
281 $this->properties = [];
292 if (isset($this->handledProperties[$property])) {
296 foreach ($this->handledProperties as $handledProperty => $handledPropertyConfig) {
297 foreach ((array)$handledPropertyConfig[
'allowedSubProperties'] as $allowedSubProperty => $allowedSubPropertyConfig) {
298 $propertyKey = is_array($allowedSubPropertyConfig) ? $allowedSubProperty : $allowedSubPropertyConfig;
299 if ($property === $handledProperty . $this->subPropertySeparator . $propertyKey) {