<?php

namespace classes;

class FunctionsGateway
{
    /**
     * Executes a specified callback function with provided data.
     *
     * @param string $callback The name of the callback function to be executed.
     * @param array $dataArray An array of data to be passed to the callback function.
     * @return void Exits with an appropriate failure message if validations are not met, otherwise executes the callback.
     */
    public static function call(string $callback, array $dataArray): void
    {
        if (empty($callback))
        {
            exit('FAIL- Missing action');
        }

        if (!function_exists($callback))
        {
            exit('FAIL- Action does not exist');
        }

        if (empty($dataArray))
        {
            exit('FAIL- Missing data');
        }

        $callback($dataArray);
    }
}
