Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 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);
     }
 }
Esempio n. 2
0
 public function testGetReturnsFallbackAfterRemove()
 {
     $baseConfig = new Config();
     $baseConfig->set(Config::FACTORY_IN_CLASS, 'Fallback\\ServiceRegistry');
     $config = new Config($baseConfig);
     $config->set(Config::FACTORY_IN_FILE, 'ServiceRegistry.php');
     $config->set(Config::FACTORY_IN_CLASS, 'Puli\\ServiceRegistry');
     $config->remove(Config::FACTORY_IN_CLASS);
     $this->assertSame('ServiceRegistry.php', $config->get(Config::FACTORY_IN_FILE));
     $this->assertSame('Fallback\\ServiceRegistry', $config->get(Config::FACTORY_IN_CLASS));
 }