public function refreshFactoryClass($path = null, $className = null)
{
Assert::nullOrStringNotEmpty($path, 'The path to the generated factory file must be a non-empty string or null. Got: %s');
Assert::nullOrStringNotEmpty($className, 'The class name of the generated factory must be a non-empty string or null. Got: %s');
$path = Path::makeAbsolute($path ?: $this->config->get(Config::FACTORY_OUT_FILE), $this->rootDir);
$className = $className ?: $this->config->get(Config::FACTORY_OUT_CLASS);
if (!$this->config->get(Config::FACTORY_AUTO_GENERATE)) {
return;
}
if (!file_exists($path)) {
$this->generateFactoryClass($path, $className);
return;
}
$rootModuleFile = $this->context->getRootModuleFile()->getPath();
if (!file_exists($rootModuleFile)) {
return;
}
// Regenerate file if the configuration has changed and
// auto-generation is enabled
clearstatcache(true, $rootModuleFile);
$lastConfigChange = filemtime($rootModuleFile);
$configFile = $this->context->getConfigFile() ? $this->context->getConfigFile()->getPath() : '';
if (file_exists($configFile)) {
clearstatcache(true, $configFile);
$lastConfigChange = max(filemtime($configFile), $lastConfigChange);
}
clearstatcache(true, $path);
$lastFactoryUpdate = filemtime($path);
if ($lastConfigChange > $lastFactoryUpdate) {
$this->generateFactoryClass($path, $className);
}
}