コード例 #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 ? Path::makeAbsolute($path, $this->rootDir) : $this->factoryOutFile;
     $className = $className ?: $this->factoryOutClass;
     if (!$this->environment->getConfig()->get(Config::FACTORY_AUTO_GENERATE)) {
         return;
     }
     if (!file_exists($path)) {
         $this->generateFactoryClass($path, $className);
         return;
     }
     $rootPackageFile = $this->environment->getRootPackageFile()->getPath();
     if (!file_exists($rootPackageFile)) {
         return;
     }
     // Regenerate file if the configuration has changed and
     // auto-generation is enabled
     clearstatcache(true, $rootPackageFile);
     $lastConfigChange = filemtime($rootPackageFile);
     $configFile = $this->environment->getConfigFile() ? $this->environment->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);
     }
 }
コード例 #2
0
 public function testCreateWithConfigFile()
 {
     $config = new Config();
     $rootPackageFile = new RootPackageFile();
     $configFile = new ConfigFile();
     $environment = new ProjectEnvironment(null, __DIR__, $config, $rootPackageFile, $configFile);
     $this->assertSame($configFile, $environment->getConfigFile());
 }