Puli\Manager\Factory\FactoryManagerImpl::refreshFactoryClass PHP Метод

refreshFactoryClass() публичный Метод

public refreshFactoryClass ( $path = null, $className = null )
    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);
        }
    }

Usage Example

Пример #1
0
 public function testRefreshFactoryClassDoesNotGenerateIfAutoGenerateDisabled()
 {
     $manager = new FactoryManagerImpl($this->context, $this->registry, $this->fakeWriter, $this->servers);
     // Older than config file -> would normally be generated
     touch($this->rootDir . '/MyFactory.php');
     sleep(1);
     touch($this->rootPackageFile->getPath());
     $this->fakeWriter->expects($this->never())->method('writeClass');
     $this->context->getConfig()->set(Config::FACTORY_AUTO_GENERATE, false);
     $manager->refreshFactoryClass();
 }