<?php

namespace Drupal\restaurant\Call;

use Drupal\restaurant\Registry\Registry;
/**
* central place to add __call requests so as not to copy paste from AppController to Helper
*/
class Call
{
  /*public function get($func, $args)
  {
    $func = str_replace('Helper', '', $func);

    $registry = Registry::getInstance();
    $modulePath = $registry->modulePath;

    require_once $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helper.php';
    //require_once $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helpers' . DIRECTORY_SEPARATOR . ucfirst($func) . '.php';

    $helper = $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helpers' . DIRECTORY_SEPARATOR . ucfirst($func) . '.php';

    if (! file_exists($helper)) {
      throw new \Exception ("Helper class " . ucfirst($func) . " does not exist");
    }
    require_once $helper;

    $name = ucfirst($func) . 'Helper';
    $method = strtolower($func);
    $obj = new $name;
    return $obj->$method($args);
  } */
  
  public function get($func, $args)
  {
      $func = str_replace('Helper', '', $func);
      
      $registry = Registry::getInstance();
      $modulePath = $registry->modulePath;
      
      require_once $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helper.php';
      //require_once $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helpers' . DIRECTORY_SEPARATOR . ucfirst($func) . '.php';
      
      $helper = $modulePath . 'restaurant' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helpers' . DIRECTORY_SEPARATOR . ucfirst($func) . '.php';
      
      if (file_exists($helper)) {
          require_once $helper;
          $name = ucfirst($func) . 'Helper';
          $method = strtolower($func);
          $obj = new $name;
          return $obj->$method($args);     
      }
      
  }


}
