You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
4 years ago
|
<?php
|
||
|
|
||
|
namespace App\Console\Commands;
|
||
|
|
||
|
use App\Services\ModelFinder;
|
||
|
use Illuminate\Console\Command;
|
||
|
|
||
|
class CacheMorphMap extends Command
|
||
|
{
|
||
|
/**
|
||
|
* The name and signature of the console command.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $signature = 'morphmap:cache';
|
||
|
|
||
|
/**
|
||
|
* The console command description.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $description = 'Create a cache file for faster morph mapping';
|
||
|
|
||
|
/**
|
||
|
* @var ModelFinder
|
||
|
*/
|
||
|
private $modelFinder;
|
||
|
|
||
|
/**
|
||
|
* Create a new command instance.
|
||
|
*
|
||
|
* @param ModelFinder $modelFinder
|
||
|
*/
|
||
|
public function __construct(ModelFinder $modelFinder)
|
||
|
{
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->modelFinder = $modelFinder;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Execute the console command.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function handle(): void
|
||
|
{
|
||
|
$cache = $this->modelFinder->getCachePath();
|
||
|
|
||
|
$models = $this->modelFinder->getModels();
|
||
|
$map = $this->modelFinder->getModelMap($models);
|
||
|
|
||
|
file_put_contents(
|
||
|
$cache,
|
||
|
'<?php return ' . var_export($map, true) . ';'
|
||
|
);
|
||
|
|
||
|
$this->info('Morph map models cached!');
|
||
|
}
|
||
|
}
|