Jake Vanderwerf
9 days ago 47e77f9fac1155c536b2b87fec552c7fcce66fa6
inc/managers/SEO/render/Traits/_Properties/aboutTrait.php
@@ -2,6 +2,7 @@
namespace JVBase\managers\SEO\render\Traits\_Properties;
use JVBase\managers\SEO\render\Thing\Thing;
use JVBase\registrar\config\seo\Resolver;
if (!defined('ABSPATH')) {
   exit;
@@ -17,8 +18,34 @@
   {
      return $this->about??null;
   }
   public function setAbout(Thing $about):void
   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;
   }
}