Use this class to access the managers provided by this module: php $puli = new Puli(getcwd()); $puli->start(); $moduleManager = $puli->getModuleManager(); The Puli class either operates in the global or a project context: * The "global context" is not tied to a specific root module. A global context only loads the settings of the "config.json" file in the home directory. The Puli class operates in the global context if no project root directory is passed to the constructor. In the global context, only the global config file manager is available. * The "project context" is tied to a specific Puli project. You need to pass the path to the project's root directory to the constructor or to {@link setRootDirectory()}. The configuration of the "puli.json" file in the root directory is used to configure the managers. The Puli class creates four kinds of managers: * The "config file manager" allows you to modify entries of the "config.json" file in the home directory. * The "module file manager" manages modifications to the "puli.json" file of a Puli project. * The "module manager" manages the module repository of a Puli project. * The "repository manager" manages the resource repository of a Puli project. * The "discovery manager" manages the resource discovery of a Puli project. The home directory is read from the context variable "PULI_HOME". If this variable is not set, the home directory defaults to: * $HOME/.puli on Linux, where $HOME is the context variable "HOME". * $APPDATA/Puli on Windows, where $APPDATA is the context variable "APPDATA". If none of these variables can be found, an exception is thrown. A .htaccess file is put into the home directory to protect it from web access.
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Ejemplo n.º 1
0
 /**
  * @param string $className The name of the class to convert.
  *
  * @return JsonConverter The JSON converter.
  */
 public function getJsonConverter($className)
 {
     switch ($className) {
         case 'Puli\\Manager\\Api\\Config\\ConfigFile':
             return $this->container->getConfigFileConverter();
         case 'Puli\\Manager\\Api\\Module\\ModuleFile':
             return $this->container->getLegacyModuleFileConverter();
         case 'Puli\\Manager\\Api\\Module\\RootModuleFile':
             return $this->container->getLegacyRootModuleFileConverter();
         default:
             throw new InvalidArgumentException(sprintf('Could not find converter for class "%s".', $className));
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function clearDiscovery()
 {
     $this->puli->getDiscoveryManager()->clearDiscovery();
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function clearRepository()
 {
     $this->puli->getRepositoryManager()->clearRepository();
 }
Ejemplo n.º 4
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;
     $context = $this->puli->getContext();
     $this->setName('puli')->setDisplayName('Puli')->setVersion(self::VERSION)->setDebug('@pack' . 'age_version@' === self::VERSION)->addStyle(Style::tag('good')->fgGreen())->addStyle(Style::tag('bad')->fgRed());
     if ($context instanceof ProjectContext) {
         // Don't do a version check in the global context (if not in a project)
         $this->addEventListener(ConsoleEvents::PRE_HANDLE, function (PreHandleEvent $event) use($context) {
             $io = $event->getIO();
             $moduleFile = $context->getRootModuleFile();
             // Don't show warning for "upgrade" command
             if ('upgrade' === $event->getCommand()->getName()) {
                 return;
             }
             if (version_compare($moduleFile->getVersion(), ModuleFileConverter::VERSION, '<')) {
                 $io->errorLine(sprintf('<warn>Warning: Your puli.json file has version %s, ' . 'but the latest version is %s. Run "puli upgrade" to ' . 'upgrade to %s.</warn>', $moduleFile->getVersion(), ModuleFileConverter::VERSION, ModuleFileConverter::VERSION));
             }
         });
     }
     $this->beginCommand('bind')->setDescription('Bind resources to binding types')->setHandler(function () use($puli) {
         return new BindCommandHandler($puli->getDiscoveryManager(), $puli->getModuleManager()->getModules());
     })->beginOptionCommand('add')->markAnonymous()->addArgument('artifact', Argument::REQUIRED, 'A class name or 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('class', null, Option::NO_VALUE, 'Force adding of a class binding')->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 module')->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show bindings of a module', null, 'module')->addOption('all', 'a', Option::NO_VALUE, 'Show bindings of all modules')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled bindings')->addOption('disabled', null, Option::NO_VALUE, 'Show disabled bindings')->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('class', null, Option::REQUIRED_VALUE, 'A class name')->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(new RepositoryManagerProxy($puli), new DiscoveryManagerProxy($puli), $puli->getFactoryManager());
     })->end();
     $this->beginCommand('cat')->setDescription('Concatenate a file resource in the repository')->addArgument('path', Argument::REQUIRED, 'The path of a resource')->setHandler(function () use($puli) {
         return new CatCommandHandler($puli->getRepository());
     })->end();
     $this->beginCommand('config')->setDescription('Display and modify configuration values')->setHandler(function () use($puli) {
         return new ConfigCommandHandler($puli->getRootModuleFileManager());
     })->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->getModuleManager()->getModules());
     })->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 module')->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show mappings of a module', null, 'module')->addOption('all', 'a', Option::NO_VALUE, 'Show mappings of all modules')->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('module')->setDescription('Display the installed modules')->setHandler(function () use($puli) {
         return new ModuleCommandHandler($puli->getModuleManager());
     })->beginOptionCommand('install', 'i')->addArgument('path', Argument::REQUIRED, 'The path to the module')->addArgument('name', Argument::OPTIONAL, 'The name of the module. Taken from puli.json if not passed.')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the installer', InstallInfo::DEFAULT_INSTALLER_NAME)->addOption('dev', null, Option::NO_VALUE, 'Install the module in the development environment')->setHandlerMethod('handleInstall')->end()->beginOptionCommand('list')->markDefault()->addOption('installer', null, Option::REQUIRED_VALUE, 'Show modules installed by a specific installer')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled modules')->addOption('not-found', null, Option::NO_VALUE, 'Show modules that could not be found')->addOption('not-loadable', null, Option::NO_VALUE, 'Show modules that could not be loaded')->addOption('dev', null, Option::NO_VALUE, 'Show modules of the development environment')->addOption('prod', null, Option::NO_VALUE, 'Show modules of the production environment')->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 module')->addArgument('new-name', Argument::REQUIRED, 'The new name of the module')->setHandlerMethod('handleRename')->end()->beginOptionCommand('delete', 'd')->addArgument('name', Argument::REQUIRED, 'The name of the module')->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->getRootModuleFileManager());
     })->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->getModuleManager()->getModules());
     })->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 module')->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show types of a module', null, 'module')->addOption('all', 'a', Option::NO_VALUE, 'Show types of all modules')->addOption('enabled', null, Option::NO_VALUE, 'Show enabled types')->addOption('duplicate', null, Option::NO_VALUE, 'Show duplicate types')->setHandlerMethod('handleList')->end()->beginOptionCommand('update', 'u')->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();
     $this->beginCommand('upgrade')->setDescription('Upgrades puli.json to the newest version')->addArgument('version', Argument::OPTIONAL, 'The version to upgrade/downgrade to', ModuleFileConverter::VERSION)->setHandler(function () use($puli) {
         return new UpgradeCommandHandler($puli->getRootModuleFileManager());
     })->end();
     $this->beginCommand('url')->setDescription('Generate the URL of a public resource')->addArgument('path', Argument::REQUIRED | Argument::MULTI_VALUED, 'The path of a resource')->setHandler(function () use($puli) {
         return new UrlCommandHandler($puli->getUrlGenerator(), $puli->getRepository());
     })->end();
 }