Exemplo 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;
     }
     $rootPackageFile = $this->context->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->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);
     }
 }
Exemplo n.º 2
0
 /**
  * Loads the package repository for a given project.
  *
  * @param ProjectContext     $context            The project context.
  * @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(ProjectContext $context, PackageFileStorage $packageFileStorage)
 {
     $this->context = $context;
     $this->rootDir = $context->getRootDirectory();
     $this->rootPackageFile = $context->getRootPackageFile();
     $this->packageFileStorage = $packageFileStorage;
 }
Exemplo n.º 3
0
 public function testCreate()
 {
     $config = new Config();
     $rootPackageFile = new RootPackageFile();
     $context = new ProjectContext(null, __DIR__, $config, $rootPackageFile);
     $this->assertNull($context->getHomeDirectory());
     $this->assertSame(__DIR__, $context->getRootDirectory());
     $this->assertSame($config, $context->getConfig());
     $this->assertSame($rootPackageFile, $context->getRootPackageFile());
     $this->assertNull($context->getConfigFile());
     $this->assertSame(Environment::DEV, $context->getEnvironment());
     $this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', $context->getEventDispatcher());
 }
Exemplo n.º 4
0
 private function activatePlugins()
 {
     foreach ($this->context->getRootPackageFile()->getPluginClasses() as $pluginClass) {
         $this->validatePluginClass($pluginClass);
         /** @var PuliPlugin $plugin */
         $plugin = new $pluginClass();
         $plugin->activate($this);
     }
 }
Exemplo n.º 5
0
 /**
  * Creates a tag manager.
  *
  * @param ProjectContext     $context
  * @param EditableDiscovery  $discovery
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  * @param LoggerInterface    $logger
  */
 public function __construct(ProjectContext $context, EditableDiscovery $discovery, PackageCollection $packages, PackageFileStorage $packageFileStorage, LoggerInterface $logger = null)
 {
     $this->context = $context;
     $this->discovery = $discovery;
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $context->getRootPackageFile();
     $this->logger = $logger ?: new NullLogger();
 }
 /**
  * Creates a repository manager.
  *
  * @param ProjectContext     $context
  * @param EditableRepository $repo
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  */
 public function __construct(ProjectContext $context, EditableRepository $repo, PackageCollection $packages, PackageFileStorage $packageFileStorage)
 {
     $this->context = $context;
     $this->dispatcher = $context->getEventDispatcher();
     $this->repo = $repo;
     $this->config = $context->getConfig();
     $this->rootDir = $context->getRootDirectory();
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $context->getRootPackageFile();
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
 }