/** * {@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::makeAbsolute($path ?: $this->config->get(Config::FACTORY_OUT_FILE), $this->rootDir); $className = $className ?: $this->config->get(Config::FACTORY_OUT_CLASS); $dispatcher = $this->context->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); $this->addGetModuleOrderMethod($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(); $context = new ProjectContext(null, __DIR__, $config, $rootPackageFile, null, $dispatcher); $this->assertSame($dispatcher, $context->getEventDispatcher()); }
/** * Starts the service container. */ public function start() { if ($this->started) { throw new LogicException('Puli is already started'); } if (null !== $this->rootDir) { $this->context = $this->createProjectContext($this->rootDir, $this->env); $bootstrapFile = $this->context->getConfig()->get(Config::BOOTSTRAP_FILE); // Run the project's bootstrap file to enable project-specific // autoloading if (null !== $bootstrapFile) { // Backup autoload functions of the PHAR $autoloadFunctions = spl_autoload_functions(); foreach ($autoloadFunctions as $autoloadFunction) { spl_autoload_unregister($autoloadFunction); } // Add project-specific autoload functions require_once Path::makeAbsolute($bootstrapFile, $this->rootDir); // Prepend autoload functions of the PHAR again // This is needed if the user specific autoload functions were // added with $prepend=true (as done by Composer) // Classes in the PHAR should always take precedence for ($i = count($autoloadFunctions) - 1; $i >= 0; --$i) { spl_autoload_register($autoloadFunctions[$i], true, true); } } } else { $this->context = $this->createGlobalContext(); } $this->dispatcher = $this->context->getEventDispatcher(); $this->started = true; // Start plugins once the container is running if ($this->rootDir && $this->pluginsEnabled) { $this->activatePlugins(); } }
/** * Creates a repository manager. * * @param ProjectContext $context * @param EditableRepository $repo * @param ModuleList $modules * @param JsonStorage $jsonStorage */ public function __construct(ProjectContext $context, EditableRepository $repo, ModuleList $modules, JsonStorage $jsonStorage) { $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); $this->repo = $repo; $this->config = $context->getConfig(); $this->rootDir = $context->getRootDirectory(); $this->rootModule = $modules->getRootModule(); $this->rootModuleFile = $context->getRootModuleFile(); $this->modules = $modules; $this->jsonStorage = $jsonStorage; }
/** * Starts the service container. */ public function start() { if ($this->started) { throw new LogicException('Puli is already started'); } if ($this->rootDir) { $this->context = $this->createProjectContext($this->rootDir, $this->env); $bootstrapFile = $this->context->getConfig()->get(Config::BOOTSTRAP_FILE); // Run the project's bootstrap file to enable project-specific // autoloading if (null !== $bootstrapFile) { require_once Path::makeAbsolute($bootstrapFile, $this->rootDir); } } else { $this->context = $this->createGlobalContext(); } $this->dispatcher = $this->context->getEventDispatcher(); $this->started = true; // Start plugins once the container is running if ($this->rootDir && $this->pluginsEnabled) { $this->activatePlugins(); } }
/** * 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; }