<?php

use yii\base\BaseObject;

class Microdata extends BaseObject
{
    public function toJSON(): string
    {
       return '';
    }
}

class MircodataFabric
{
    public static function createFromProduct($product): Microdata
    {
        return new ProductMicrodata();
    }

    public static function createFromArticle($article): Microdata
    {
        /*
        * Generate array for config
                             */

            return new ArticleMicrodata(array_merge(['title' => 'article',], self::getCommonConfig()));
        }

        protected static function getCommonConfig():array
        {
            return require('config.php');
        }
}

class ArticleMicrodata extends Microdata
{
    public $title;

    public function toJSON(): string
    {
        return 'article json';
    }
}

class ProductMicrodata extends Microdata
{
    public $price;

    public function toJSON(): string
    {
        return 'product json';
    }
}


/*
* Implementation
*
     * MircodataFabric::createFromProduct($product)->toJSON();
* MircodataFabric::createFromArticle($article)->toJSON();
*/