<?php
|
namespace JVBase\managers\SEO\render\Traits\_Properties;
|
|
use JVBase\managers\SEO\render\Thing\Thing;
|
use JVBase\registrar\config\seo\Resolver;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
trait aboutTrait {
|
/**
|
* @var Thing The subject matter of an object.
|
* Inverse property: subjectOf
|
*/
|
protected Thing $about;
|
|
public function getAbout():?Thing
|
{
|
return $this->about??null;
|
}
|
public function setAbout(Thing|array $about):void
|
{
|
if (is_array($about)) {
|
if (!array_key_exists('type', $about)) {
|
error_log('[aboutTrait] Needs to have a type key'.print_r($about, true));
|
return;
|
}
|
if (!class_exists($about['type'])) {
|
error_log('[aboutTrait] Class not found for: '.print_r($about['type'], true));
|
return;
|
}
|
$class = new $about['type']();
|
$className = $about['type'];
|
unset($about['type']);
|
foreach ($about as $key => $value) {
|
$method = 'set'.ucfirst($key);
|
if (method_exists($class, $method)) {
|
if (is_string($value) && str_contains($value, '{{')) {
|
$value = Resolver::resolveForSchema($key, $value, $class);
|
}
|
error_log('Setting '.$key.' to '.print_r($value, true));
|
$class->$method($value);
|
} else {
|
error_log('[aboutTrait] Invalid method: '.$method.', for class: '.$className);
|
}
|
}
|
$about = $class;
|
}
|
$this->about = $about;
|
}
|
}
|