Я пытаюсь использовать отражение PHP для динамической загрузки файлов классов моделей автоматически на основе типа параметра, который находится в методе контроллера. Вот пример метода контроллера.
<?php
class ExampleController
{
public function PostMaterial(SteelSlugModel $model)
{
//etc...
}
}
Вот что я до сих пор.
//Target the first parameter, as an example
$param = new ReflectionParameter(array('ExampleController', 'PostMaterial'), 0);
//Echo the type of the parameter
echo $param->getClass()->name;
Это работает, и выход будет "SteelSlugModel", как и ожидалось. Тем не менее, существует вероятность того, что файл класса модели еще не загружен, а использование getClass() требует определения класса - часть того, почему я делаю это, - это автозагрузка любых моделей, которые могут потребоваться для действия контроллера.
Есть ли способ получить имя типа параметра, не загружая сначала файл класса?