/** * {@inheritdoc} */ public function generateFactoryClass($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; $dispatcher = $this->environment->getEventDispatcher(); $class = new Clazz($className); $class->setFilePath($path); $class->setDescription(<<<EOF Creates Puli's core services. This class was auto-generated by Puli. IMPORTANT: Before modifying the code below, set the "factory.auto-generate" configuration key to false: \$ puli config factory.auto-generate false Otherwise any modifications will be overwritten! EOF ); $this->addCreateRepositoryMethod($class); $this->addCreateDiscoveryMethod($class); $this->addCreateUrlGeneratorMethod($class); if ($dispatcher->hasListeners(PuliEvents::GENERATE_FACTORY)) { $dispatcher->dispatch(PuliEvents::GENERATE_FACTORY, new GenerateFactoryEvent($class)); } $this->classWriter->writeClass($class); }
public function testCreateWithDispatcher() { $config = new Config(); $rootPackageFile = new RootPackageFile(); $dispatcher = new EventDispatcher(); $environment = new ProjectEnvironment(null, __DIR__, $config, $rootPackageFile, null, $dispatcher); $this->assertSame($dispatcher, $environment->getEventDispatcher()); }
/** * 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; }
/** * Starts the service container. */ public function start() { if ($this->started) { throw new LogicException('Puli is already started'); } if ($this->rootDir) { $this->environment = $this->createProjectEnvironment($this->rootDir); } else { $this->environment = $this->createGlobalEnvironment(); } $this->dispatcher = $this->environment->getEventDispatcher(); $this->started = true; // Start plugins once the container is running if ($this->rootDir && $this->pluginsEnabled) { $this->activatePlugins(); } }