I have a tenant-based environment, where standing up each new tenant currently involves manually copying a group of PHP files and hand-replacing values inside them. I’m trying to find a way to automate this process, to speed it up and reduce human error. My current idea is a console command to duplicate template files to a tenant directory, and flatten variables inside into their values.
Copying the template files is trivial – what I can’t figure out is a good way to render the variables inside them down to flat values. Does Laravel (or base PHP) have a preprocessor-like way to grab an external file, and render down variables inside it?
Blade would be perfect for this purpose, but AFAIK Blade can’t handle PHP preprocessing. Currently, the best solution I’ve been able to come up with is embedding the entire doc as a heredoc inside my console command, eg:
return <<<EOD
<?php
class {$this->tenantName}SettingsSeeder extends Seeder
{
...
}
EOD;
this allows me to render down variables easily to flat values, but I want to do this for potentially a couple dozen templates. It becomes cumbersome in a single file very quickly, and I’m not aware of a clean way to put a heredoc in an external file, import it, and execute it.
Note: The files being created either need to contain detached hard-coded values (think configs), or act pre-database (think migrations). I understand the temptation, but please trust me when I say abstracting this structure to the database involves massive foundational changes we’re not willing to make at this time. We’re committed to this approach.