/**
  * {@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);
     }
 }
 /**
  * Loads the package repository for a given project.
  *
  * @param ProjectEnvironment $environment        The project environment.
  * @param PackageFileStorage $packageFileStorage The package file storage.
  *
  * @throws FileNotFoundException If the install path of a package not exist.
  * @throws NoDirectoryException If the install path of a package points to a file.
  * @throws InvalidConfigException If a configuration file contains invalid configuration.
  * @throws NameConflictException If a package has the same name as another loaded package.
  */
 public function __construct(ProjectEnvironment $environment, PackageFileStorage $packageFileStorage)
 {
     $this->environment = $environment;
     $this->rootDir = $environment->getRootDirectory();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->packageFileStorage = $packageFileStorage;
 }
 public function testCreate()
 {
     $config = new Config();
     $rootPackageFile = new RootPackageFile();
     $environment = new ProjectEnvironment(null, __DIR__, $config, $rootPackageFile);
     $this->assertNull($environment->getHomeDirectory());
     $this->assertSame(__DIR__, $environment->getRootDirectory());
     $this->assertSame($config, $environment->getConfig());
     $this->assertSame($rootPackageFile, $environment->getRootPackageFile());
     $this->assertNull($environment->getConfigFile());
     $this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', $environment->getEventDispatcher());
 }
 /**
  * Creates a tag manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableDiscovery  $discovery
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  * @param LoggerInterface    $logger
  */
 public function __construct(ProjectEnvironment $environment, EditableDiscovery $discovery, PackageCollection $packages, PackageFileStorage $packageFileStorage, LoggerInterface $logger = null)
 {
     $this->environment = $environment;
     $this->discovery = $discovery;
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->logger = $logger ?: new NullLogger();
 }
 /**
  * Creates a repository manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableRepository $repo
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  */
 public function __construct(ProjectEnvironment $environment, EditableRepository $repo, PackageCollection $packages, PackageFileStorage $packageFileStorage)
 {
     $this->environment = $environment;
     $this->dispatcher = $environment->getEventDispatcher();
     $this->repo = $repo;
     $this->config = $environment->getConfig();
     $this->rootDir = $environment->getRootDirectory();
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
 }
Esempio n. 6
0
 private function activatePlugins()
 {
     foreach ($this->environment->getRootPackageFile()->getPluginClasses() as $pluginClass) {
         $this->validatePluginClass($pluginClass);
         /** @var PuliPlugin $plugin */
         $plugin = new $pluginClass();
         $plugin->activate($this);
     }
 }