我想使用变量和硬编码文本创建复合词。 例如。将User作为$ model参数传递给下面的函数时:
function compileRepository($model) {
return <<<TEMPLATE
<?php
namespace App\Repositories\Eloquent;
use App\Models\Eloquent\\$model;
use App\Interfaces\\$model as $modelInterface;
class Eloquent$model implements $modelInterface {
};
TEMPLATE;
}
我想得到:
<?php
namespace App\Repositories\Eloquent;
use App\Models\Eloquent\User;
use App\Interfaces\User as UserInterface;
class EloquentUser implements UserInterface {
};
不幸的是,这不起作用,因为$ modelInterface被解释为变量modelInterface而不是与接口连接的变量$ model