<?php

function array_property(array $parameters, $property)
{
    return $parameters[$property];
}

namespace RaBotCompilation\Modules
{
    use RaBotCompilation\Types\Local\RaBotTypeConstructor;
    
    final class RaBotQueryTypes
    {
        private static $callbacks = array();
        
        public static function register_function(string $type, callable $callback): void
        {
            self::$callbacks[$type] = $callback;
        }
        
        public static function register_class(string $type, string $name): void
        {
            self::register_function($type, fn (array $parameters) => new $name($parameters));
        }
        
        public static function register_classes(array $parameters): void
        {
            foreach ($parameters as $type => $name)
            {
                self::register_class($type, $name);
            }
        }
        
        public static function runnable(string $type, array $parameters): RaBotTypeConstructor
        {
            return array_property(self::$callbacks, $type)($parameters);
        }
    }
}

namespace RaBotCompilation\Types\Local
{
    class RaBotTypeConstructor
    {
    }
    
    class RaBotTypeMixed extends RaBotTypeConstructor
    {
        protected $type;
        protected $data;
        
        public function __construct(array $parameters)
        {
            $value = array_property($parameters, 'data');
            $check = gettype($value);
            
            if ($this->type === $check)
            {
                return;
            }
            
            exit('line 62, Incorrent datatype');
        }
    }
    
    final class RaBotTypeBoolean extends RaBotTypeMixed
    {
        protected $type = 'boolean';
    }
    
    final class RaBotTypeInteger extends RaBotTypeMixed
    {
        protected $type = 'integer';
    }
    
    final class RaBotTypeDouble extends RaBotTypeMixed
    {
        protected $type = 'double';
    }
    
    final class RaBotTypeString extends RaBotTypeMixed
    {
        protected $type = 'string';
    }
    
    final class RaBotTypeArray extends RaBotTypeMixed
    {
        protected $type = 'array';
    }
    
    final class RaBotTypeNone extends RaBotTypeMixed
    {
        protected $type = 'NULL';
    }
}

namespace RaBotCompilation\Includes
{
    use RaBotCompilation\Types\Local\RaBotTypeBoolean;
    use RaBotCompilation\Types\Local\RaBotTypeInteger;
    use RaBotCompilation\Types\Local\RaBotTypeDouble;
    use RaBotCompilation\Types\Local\RaBotTypeString;
    use RaBotCompilation\Types\Local\RaBotTypeArray;
    use RaBotCompilation\Types\Local\RaBotTypeMixed;
    use RaBotCompilation\Types\Local\RaBotTypeNone;
    
    use RaBotCompilation\Modules\RaBotQueryTypes;
    
    RaBotQueryTypes::register_function('mixed', function (array $parameters): RaBotTypeMixed
    {
        $data = array_property($parameters, 'data');
        $type = gettype($data);
        
        return RaBotQueryTypes::runnable($type, $parameters);
    });
    
    RaBotQueryTypes::register_classes(array(
        'boolean' => RaBotTypeBoolean::class,
        'integer' => RaBotTypeInteger::class,
        'double'  => RaBotTypeDouble::class,
        'string'  => RaBotTypeString::class,
        'array'   => RaBotTypeArray::class,
        'none'    => RaBotTypeNone::class
    ));
}

namespace RaBotCompilation\Runnable
{
    use RaBotCompilation\Modules\RaBotQueryTypes;
    
    $type = 'integer';
    $args = ['data' => 'hello'];
    $data = RaBotQueryTypes::runnable($type, $args);
    
    var_dump($data);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: