<?php

namespace domain\_;

use yii\base\ErrorException;

abstract class AbstractModule extends AbstractSingleton implements ModuleInterface
{
    public function getEntityFqcn(): string
    {
        return $this->getDefinition()->getEntityFqcn();
    }

    public function __call($method, $args)
    {
        foreach($this->getServices() as $serviceClass) {
            if(method_exists($serviceClass, $method)) {
                return call_user_func_array(
                    [$serviceClass::getInstance(), $method],
                    $args
                );
            }
        }

        throw new ErrorException('La méthode '.$method.' est introuvable dans les services du module '.get_class($this));
    }
}