PHP 中的 Lint 动态 return 类型
Lint dynamic return types in PHP
我希望在使用以下代码时能够自动完成。我一直在寻找解决方案,但似乎找不到任何东西。
这是关于我的模型的样子。在下面的示例中,我希望能够选择 example
和 test
class ExampleModel extends Model {
public function example() {
//Do Something
}
public function test() {
//Do Something
}
}
我检索模型的函数:
/**
* Returns an object of the requested model
* @param string $model Name of the model
* @return Model Object of the model
*/
public function getModel($model) {
$model .= "Model";
$path = "models/$model.php";
if (!isset($this->modelCache[$model])) {
if (file_exists($path)) {
require_once $path;
} else {
throw new Exception("Model: $model does not exist!");
}
$this->modelCache[$model] = new $model($this);
}
return $this->modelCache[$model];
}
我是这样称呼模型的:
$x->getModel("Example")->example();
我期待着您的想法。我很高兴听到您对这个问题的想法!当然,我也愿意接受有关 getModel
函数本身的建议。
虽然我仍然想知道如何在不改变进程本身的情况下实现这一点,但我已经通过简单地使用静态 类 和命名空间解决了这个问题。这样的 linting 很棒。
我希望在使用以下代码时能够自动完成。我一直在寻找解决方案,但似乎找不到任何东西。
这是关于我的模型的样子。在下面的示例中,我希望能够选择 example
和 test
class ExampleModel extends Model {
public function example() {
//Do Something
}
public function test() {
//Do Something
}
}
我检索模型的函数:
/**
* Returns an object of the requested model
* @param string $model Name of the model
* @return Model Object of the model
*/
public function getModel($model) {
$model .= "Model";
$path = "models/$model.php";
if (!isset($this->modelCache[$model])) {
if (file_exists($path)) {
require_once $path;
} else {
throw new Exception("Model: $model does not exist!");
}
$this->modelCache[$model] = new $model($this);
}
return $this->modelCache[$model];
}
我是这样称呼模型的:
$x->getModel("Example")->example();
我期待着您的想法。我很高兴听到您对这个问题的想法!当然,我也愿意接受有关 getModel
函数本身的建议。
虽然我仍然想知道如何在不改变进程本身的情况下实现这一点,但我已经通过简单地使用静态 类 和命名空间解决了这个问题。这样的 linting 很棒。