示例#1
0
 /**
  * Rebuild the puli dependencies for symfony container.
  */
 protected function rebuild(InputInterface $input, OutputInterface $output)
 {
     $puli = new Puli(Path::join([getcwd(), NANBANDO_DIR]));
     $puli->start();
     /** @var EmbeddedComposerInterface $embeddedComposer */
     $embeddedComposer = $this->getApplication()->getEmbeddedComposer();
     $packageManager = $puli->getPackageManager();
     $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet());
     $composer = $embeddedComposer->createComposer($io);
     $installationManager = $composer->getInstallationManager();
     $rootPackage = $composer->getPackage();
     $repository = $composer->getRepositoryManager()->getLocalRepository();
     $packages = [];
     foreach ($repository->getPackages() as $package) {
         $packages[$package->getName()] = $package;
     }
     foreach ($rootPackage->getRequires() as $require) {
         if (!array_key_exists($require->getTarget(), $packages)) {
             continue;
         }
         $packageManager->installPackage(Path::normalize($installationManager->getInstallPath($packages[$require->getTarget()])), $require->getTarget(), 'nanbando');
     }
     $filesystem = new Filesystem();
     $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, '.puli']));
     $discoveryManager = $puli->getDiscoveryManager();
     if (!$discoveryManager->hasRootTypeDescriptor('nanbando/bundle')) {
         $discoveryManager->addRootTypeDescriptor(new BindingTypeDescriptor(new BindingType('nanbando/bundle')), 0);
     }
     $discoveryManager->clearDiscovery();
     $discoveryManager->buildDiscovery();
     $filesystem = new Filesystem();
     $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, 'app', 'cache']));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function configure()
 {
     // Make sure the console and Puli use the same event dispatcher so that
     // Puli plugins can listen to the console events.
     // Add the dispatcher before parent::configure() so that the parent
     // listeners don't get overwritten.
     $this->setEventDispatcher($this->puli->getEventDispatcher());
     parent::configure();
     $puli = $this->puli;
     $this->setName('puli')->setDisplayName('Puli')->setVersion(self::VERSION)->setDebug('@pack' . 'age_version@' === self::VERSION)->addStyle(Style::tag('good')->fgGreen())->addStyle(Style::tag('bad')->fgRed());
     $this->beginCommand('bind')->setDescription('Bind resources to binding types')->setHandler(function () use($puli) {
         return new BindCommandHandler($puli->getDiscoveryManager(), $puli->getPackageManager()->getPackages());
     })->beginOptionCommand('add')->markAnonymous()->addArgument('query', Argument::REQUIRED, 'A query for resources')->addArgument('type', Argument::REQUIRED, 'The name of the binding type')->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', 'glob', 'language')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')->addOption('force', 'f', Option::NO_VALUE, 'Add binding even if the binding type does not exist')->setHandlerMethod('handleAdd')->end()->beginOptionCommand('list')->markDefault()->addOption('root', null, Option::NO_VALUE, 'Show bindings of the root package')->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show bindings of a package', null, 'package')->addOption('all', 'a', Option::NO_VALUE, 'Show bindings of all packages')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled bindings')->addOption('disabled', null, Option::NO_VALUE, 'Show disabled bindings')->addOption('undecided', null, Option::NO_VALUE, 'Show bindings that are neither enabled nor disabled')->addOption('type-not-found', null, Option::NO_VALUE, 'Show bindings whose type is not found')->addOption('type-not-enabled', null, Option::NO_VALUE, 'Show bindings whose type is not enabled')->addOption('ignored', null, Option::NO_VALUE, 'Show bindings whose type is disabled')->addOption('invalid', null, Option::NO_VALUE, 'Show bindings with invalid parameters')->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', 'glob', 'language')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')->setHandlerMethod('handleList')->end()->beginOptionCommand('update', 'u')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the updated binding')->addOption('query', null, Option::REQUIRED_VALUE, 'A query for resources')->addOption('type', null, Option::REQUIRED_VALUE, 'The name of the binding type')->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', null, 'language')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Unset a binding parameter', null, 'key')->addOption('force', 'f', Option::NO_VALUE, 'Update binding even if the binding type does not exist')->setHandlerMethod('handleUpdate')->end()->beginOptionCommand('delete', 'd')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the removed binding')->setHandlerMethod('handleDelete')->end()->beginOptionCommand('enable')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the enabled binding')->setHandlerMethod('handleEnable')->end()->beginOptionCommand('disable')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the disabled binding')->setHandlerMethod('handleDisable')->end()->end();
     $this->beginCommand('build')->setDescription('Build the resource repository/discovery')->addArgument('target', Argument::OPTIONAL, 'The build target. One of "repository", "discovery", "factory" and "all"', 'all')->setHandler(function () use($puli) {
         return new BuildCommandHandler($puli->getRepositoryManager(), $puli->getDiscoveryManager(), $puli->getFactoryManager());
     })->end();
     $this->beginCommand('config')->setDescription('Display and modify configuration values')->setHandler(function () use($puli) {
         return new ConfigCommandHandler($puli->getRootPackageFileManager());
     })->beginSubCommand('list')->markDefault()->addOption('parsed', null, Option::NO_VALUE, 'Replace placeholders by their values in the output')->setHandlerMethod('handleList')->end()->beginSubCommand('show')->markAnonymous()->addArgument('key', Argument::REQUIRED, 'The configuration key to show. May contain wildcards ("*")')->addOption('parsed', null, Option::NO_VALUE, 'Replace placeholders by their values in the output')->setHandlerMethod('handleShow')->end()->beginSubCommand('set')->markAnonymous()->addArgument('key', Argument::REQUIRED, 'The modified configuration key')->addArgument('value', Argument::REQUIRED, 'The value to set for the configuration key')->setHandlerMethod('handleSet')->end()->beginOptionCommand('reset', 'r')->addArgument('key', Argument::REQUIRED, 'The configuration key(s) to reset. May contain wildcards ("*")')->setHandlerMethod('handleReset')->end()->end();
     $this->beginCommand('find')->setDescription('Find resources by different criteria')->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path. May contain the wildcard "*"')->addOption('name', null, Option::REQUIRED_VALUE, 'The resource filename. May contain the wildcard "*"')->addOption('class', null, Option::REQUIRED_VALUE, 'The short name of a resource class')->addOption('type', null, Option::REQUIRED_VALUE, 'The name of a binding type')->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the query passed with --path', 'glob')->setHandler(function () use($puli) {
         return new FindCommandHandler($puli->getRepository(), $puli->getDiscovery());
     })->end();
     $this->beginCommand('installer')->setDescription('Manage the installers used to install web resources')->setHandler(function () use($puli) {
         return new InstallerCommandHandler($puli->getInstallerManager());
     })->beginOptionCommand('list')->markDefault()->addOption('long', 'l', Option::NO_VALUE, 'Print the fully-qualified class name')->setHandlerMethod('handleList')->end()->beginOptionCommand('add', 'a')->addArgument('name', Argument::REQUIRED, 'The name of the installer')->addArgument('class', Argument::REQUIRED, 'The fully-qualified class name of the installer')->addOption('description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'The description of the installer')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional installer parameters')->setHandlerMethod('handleAdd')->end()->beginOptionCommand('delete', 'd')->addArgument('name', Argument::REQUIRED, 'The name of the installer to remove')->setHandlerMethod('handleDelete')->end()->end();
     $this->beginCommand('ls')->setDescription('List the children of a resource in the repository')->addArgument('path', Argument::OPTIONAL, 'The path of a resource', '/')->addOption('long', 'l', Option::NO_VALUE, 'Print more information about each child')->setHandler(function () use($puli) {
         return new LsCommandHandler($puli->getRepository());
     })->end();
     $this->beginCommand('map')->setDescription('Display and change path mappings')->setHandler(function () use($puli) {
         return new MapCommandHandler($puli->getRepositoryManager(), $puli->getPackageManager()->getPackages());
     })->beginOptionCommand('add')->markAnonymous()->addArgument('path', Argument::REQUIRED)->addArgument('file', Argument::REQUIRED | Argument::MULTI_VALUED)->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target path does not exist')->setHandlerMethod('handleAdd')->end()->beginOptionCommand('list')->markDefault()->addOption('root', null, Option::NO_VALUE, 'Show mappings of the root package')->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show mappings of a package', null, 'package')->addOption('all', 'a', Option::NO_VALUE, 'Show mappings of all packages')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled mappings')->addOption('not-found', null, Option::NO_VALUE, 'Show mappings whose referenced paths do not exist')->addOption('conflict', null, Option::NO_VALUE, 'Show conflicting mappings')->setHandlerMethod('handleList')->end()->beginOptionCommand('update', 'u')->addArgument('path', Argument::REQUIRED)->addOption('add', 'a', Option::REQUIRED_VALUE | Option::MULTI_VALUED | Option::PREFER_LONG_NAME, 'Add a file to the path mapping', null, 'file')->addOption('remove', 'r', Option::REQUIRED_VALUE | Option::MULTI_VALUED | Option::PREFER_LONG_NAME, 'Remove a file from the path mapping', null, 'file')->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target path does not exist')->setHandlerMethod('handleUpdate')->end()->beginOptionCommand('delete', 'd')->addArgument('path', Argument::REQUIRED)->addArgument('file', Argument::OPTIONAL)->setHandlerMethod('handleDelete')->end()->end();
     $this->beginCommand('package')->setDescription('Display the installed packages')->setHandler(function () use($puli) {
         return new PackageCommandHandler($puli->getPackageManager());
     })->beginOptionCommand('add', 'a')->addArgument('path', Argument::REQUIRED, 'The path to the package')->addArgument('name', Argument::OPTIONAL, 'The name of the package. Taken from puli.json if not passed.')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the installer', InstallInfo::DEFAULT_INSTALLER_NAME)->setHandlerMethod('handleAdd')->end()->beginOptionCommand('list')->markDefault()->addOption('installer', null, Option::REQUIRED_VALUE, 'Show packages installed by a specific installer')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled packages')->addOption('not-found', null, Option::NO_VALUE, 'Show packages that could not be found')->addOption('not-loadable', null, Option::NO_VALUE, 'Show packages that could not be loaded')->addOption('format', null, Option::REQUIRED_VALUE, 'The format of the output. You can use the variables %name%, %install_path%, %installer% and %state% in the format string', null, 'format')->setHandlerMethod('handleList')->end()->beginOptionCommand('rename')->addArgument('name', Argument::REQUIRED, 'The name of the package')->addArgument('new-name', Argument::REQUIRED, 'The new name of the package')->setHandlerMethod('handleRename')->end()->beginOptionCommand('delete', 'd')->addArgument('name', Argument::REQUIRED, 'The name of the package')->setHandlerMethod('handleDelete')->end()->beginOptionCommand('clean')->setHandlerMethod('handleClean')->end()->end();
     $this->beginCommand('plugin')->setDescription('Manage the installed Puli plugins')->setHandler(function () use($puli) {
         return new PluginCommandHandler($puli->getRootPackageFileManager());
     })->beginOptionCommand('install', 'i')->addArgument('class', Argument::REQUIRED, 'The fully-qualified plugin class name')->setHandlerMethod('handleInstall')->end()->beginOptionCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginOptionCommand('delete', 'd')->addArgument('class', Argument::REQUIRED, 'The fully-qualified plugin class name')->setHandlerMethod('handleDelete')->end()->end();
     $this->beginCommand('publish')->setDescription('Manage public resources')->setHandler(function () use($puli) {
         return new PublishCommandHandler($puli->getAssetManager(), $puli->getInstallationManager(), $puli->getServerManager());
     })->beginOptionCommand('add')->markAnonymous()->addArgument('path', Argument::REQUIRED, 'The resource path')->addArgument('server', Argument::REQUIRED, 'The resource path')->addArgument('server-path', Argument::OPTIONAL, 'The path in the document root of the server', '/')->addOption('force', 'f', Option::NO_VALUE, 'Map even if the server does not exist')->setHandlerMethod('handleAdd')->end()->beginOptionCommand('update', 'u')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path')->addOption('server', 's', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the target server')->addOption('server-path', null, Option::REQUIRED_VALUE, 'The path in the document root')->addOption('force', 'f', Option::NO_VALUE, 'Update even if the server does not exist')->setHandlerMethod('handleUpdate')->end()->beginOptionCommand('delete', 'd')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->setHandlerMethod('handleDelete')->end()->beginOptionCommand('list', 'l')->markDefault()->setHandlerMethod('handleList')->end()->beginOptionCommand('install')->addArgument('server', Argument::OPTIONAL, 'The server to install. By default, all servers are installed')->setHandlerMethod('handleInstall')->end()->end();
     $this->beginCommand('self-update')->setDescription('Update Puli to the latest version.')->addOption('stable', null, Option::NO_VALUE, 'Update to the latest stable version')->addOption('unstable', null, Option::NO_VALUE, 'Update to the latest unstable version')->setHandler(function () {
         return new SelfUpdateCommandHandler();
     })->enableIf('phar://' === substr(__DIR__, 0, 7))->end();
     $this->beginCommand('server')->setDescription('Manage your asset servers')->setHandler(function () use($puli) {
         return new ServerCommandHandler($puli->getServerManager());
     })->beginOptionCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginOptionCommand('add', 'a')->addArgument('name', Argument::REQUIRED, 'The name of the added server')->addArgument('document-root', Argument::REQUIRED, 'The document root of the server')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', Server::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters required by the resource installer')->setHandlerMethod('handleAdd')->end()->beginOptionCommand('update', 'u')->addArgument('name', Argument::REQUIRED, 'The name of the updated server')->addOption('document-root', null, Option::REQUIRED_VALUE, 'The document root of the server')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', Server::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters required by the resource installer')->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Parameters to remove from the server')->setHandlerMethod('handleUpdate')->end()->beginOptionCommand('delete', 'd')->addArgument('name', Argument::REQUIRED, 'The name of the server to remove')->setHandlerMethod('handleDelete')->end()->end();
     $this->beginCommand('tree')->setDescription('Print the contents of a resource as tree')->addArgument('path', Argument::OPTIONAL, 'The path of a resource', '/')->setHandler(function () use($puli) {
         return new TreeCommandHandler($puli->getRepository());
     })->end();
     $this->beginCommand('type')->setDescription('Display and change binding types')->setHandler(function () use($puli) {
         return new TypeCommandHandler($puli->getDiscoveryManager(), $puli->getPackageManager()->getPackages());
     })->beginOptionCommand('define')->addArgument('name', Argument::REQUIRED, 'The name of the binding type')->addOption('description', null, Option::REQUIRED_VALUE, 'A human-readable description of the type')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A type parameter in the form <key> or <key>=<value>', null, 'key=value')->addOption('param-description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A human-readable parameter description in the form <key>=<description>', null, 'key=description')->addOption('force', 'f', Option::NO_VALUE, 'Add type even if another type exists with the same name')->setHandlerMethod('handleDefine')->end()->beginSubCommand('list')->markDefault()->addOption('root', null, Option::NO_VALUE, 'Show types of the root package')->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show types of a package', null, 'package')->addOption('all', 'a', Option::NO_VALUE, 'Show types of all packages')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled types')->addOption('duplicate', null, Option::NO_VALUE, 'Show duplicate types')->setHandlerMethod('handleList')->end()->beginOptionCommand('update')->addArgument('name', Argument::REQUIRED, 'The name of the binding type')->addOption('description', null, Option::REQUIRED_VALUE, 'A human-readable description of the type')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A type parameter in the form <key> or <key>=<value>', null, 'key=value')->addOption('param-description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A human-readable parameter description in the form <key>=<description>', null, 'key=description')->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Unset a type parameter', null, 'key')->setHandlerMethod('handleUpdate')->end()->beginOptionCommand('delete', 'd')->addArgument('name', Argument::REQUIRED, 'The name of the binding type')->setHandlerMethod('handleDelete')->end()->end();
 }
 /**
  * Activates the plugin.
  *
  * @param Puli $puli The {@link Puli} instance.
  */
 public function activate(Puli $puli)
 {
     $puli->getEventDispatcher()->addListener(PuliEvents::GENERATE_FACTORY, function () use($puli) {
         // Function called just before the factory class is written.
         // Idea: let's delete the compiled container file. And let's recreate it only when needed!
         $filesystem = new Filesystem();
         $filesystem->remove(YacoFactory::getContainerFilePath());
         $logger = $puli->getLogger();
         if ($logger) {
             $puli->getLogger()->info("Bindings updated. Removing outdated container.");
         }
     });
 }
示例#4
0
 /**
  * @expectedException \Puli\Manager\Api\InvalidConfigException
  */
 public function testFailIfPluginClassNotInstanceOfPuliPlugin()
 {
     $filesystem = new Filesystem();
     $filesystem->copy($this->tempRoot . '/puli-not-a-plugin.json', $this->tempRoot . '/puli.json', true);
     $this->puli->setRootDirectory($this->tempRoot);
     $this->puli->start();
 }
示例#5
0
 protected function setUp()
 {
     $this->environment = $this->getMockBuilder('Puli\\Manager\\Api\\Environment\\ProjectEnvironment')->disableOriginalConstructor()->getMock();
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->puli = $this->getMock('Puli\\Manager\\Api\\Puli');
     $this->rootPackageFileManager = $this->getMock('Puli\\Manager\\Api\\Package\\RootPackageFileManager');
     $this->repo = $this->getMock('Puli\\Repository\\Api\\ResourceRepository');
     $this->discovery = $this->getMock('Puli\\Discovery\\Api\\ResourceDiscovery');
     $this->discoveryManager = $this->getMock('Puli\\Manager\\Api\\Discovery\\DiscoveryManager');
     $this->packageManager = $this->getMock('Puli\\Manager\\Api\\Package\\PackageManager');
     $this->plugin = new AssetPlugin();
     $this->puli->expects($this->any())->method('getEnvironment')->willReturn($this->environment);
     $this->puli->expects($this->any())->method('getEventDispatcher')->willReturn($this->dispatcher);
     $this->puli->expects($this->any())->method('getRootPackageFileManager')->willReturn($this->rootPackageFileManager);
     $this->puli->expects($this->any())->method('getRepository')->willReturn($this->repo);
     $this->puli->expects($this->any())->method('getDiscovery')->willReturn($this->discovery);
     $this->puli->expects($this->any())->method('getDiscoveryManager')->willReturn($this->discoveryManager);
     $this->puli->expects($this->any())->method('getPackageManager')->willReturn($this->packageManager);
     $this->packageManager->expects($this->any())->method('getPackages')->willReturn(new PackageCollection());
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function clearRepository()
 {
     $this->puli->getRepositoryManager()->clearRepository();
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function clearDiscovery()
 {
     $this->puli->getDiscoveryManager()->clearDiscovery();
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public function activate(Puli $puli)
 {
     $dispatcher = $puli->getEventDispatcher();
     // Add event listeners that generate the JSON file here
     $dispatcher->addListener(PuliEvents::XXX, array($this, 'handleXxx'));
 }
示例#9
0
 public function activate(Puli $puli)
 {
     self::$puli = $puli;
     // Test that Puli is started and the services are accessible
     self::$environment = $puli->getEnvironment();
 }
示例#10
0
 public function activate(Puli $puli)
 {
     self::$puli = $puli;
     // Test that Puli is started and the services are accessible
     self::$context = $puli->getContext();
 }
示例#11
0
 /**
  * Activates the plugin.
  *
  * @param Puli $puli The {@link Puli} instance.
  */
 public function activate(Puli $puli)
 {
     $this->puli = $puli;
     $puli->getEventDispatcher()->addListener(ConsoleEvents::CONFIG, array($this, 'handleConfigEvent'));
     $puli->getEventDispatcher()->addListener(PuliEvents::GENERATE_FACTORY, array($this, 'handleGenerateFactoryEvent'));
 }