コード例 #1
0
 /**
  * Installs a template module
  *
  * A template, when installed, becames a project-module.
  *
  * @param string $moduleName If not specified, a list of installable templates will be displayed for the user
  *                           to pick one
  * @param array  $opts
  * @option $keep-repo|k When set, the hidden .git directory is not removed from the module's directory
  * @option $search|s Search for templates having the specified text word or prefix somewhere on the name or
  *                           description
  * @option $stars Sort the list by stars, instead of downloads
  */
 protected function moduleInstallTemplate($moduleName = null, $opts = ['keep-repo|k' => false, 'search|s' => '', 'stars' => false])
 {
     $io = $this->io;
     if (!$moduleName) {
         // Search
         $modules = (new PackagistAPI())->type('electro-template')->query($opts['search'])->search(true);
         if (empty($modules)) {
             $io->error("No matching templates were found");
         }
         $this->formatModules($modules, $opts['stars']);
         // Show menu
         $sel = $io->menu('Select a template module to install:', array_getColumn($modules, 'fname'), -1, array_getColumn($modules, 'description'), function ($i) use($modules) {
             return !$this->modulesRegistry->isInstalled($modules[$i]['name']) ?: "A module with that name already exists on this project";
         });
         if ($sel < 0) {
             $this->io->cancel();
         }
         $module = $modules[$sel];
         $moduleName = $module['name'];
         $moduleUrl = $module['repository'];
     } else {
         // Extract package information from packagist.org
         try {
             $info = (new PackagistAPI())->get($moduleName);
         } catch (HttpException $e) {
             $io->error($e->getCode() == 404 ? "Module '{$moduleName}' was not found" : $e->getMessage());
         }
         /** @noinspection PhpUndefinedVariableInspection */
         $module = $info['package'];
         $moduleUrl = $module['repository'];
     }
     // Clone the repo.
     $path = "{$this->kernelSettings->modulesPath}/{$moduleName}";
     (new GitStack())->cloneRepo($moduleUrl, $path)->printed(false)->run();
     // Remove VCS history
     if (!$opts['keep-repo']) {
         $io->mute();
         $this->fs->remove("{$path}/.git")->run();
         $io->unmute();
     }
     // Install the module's dependencies and register its namespaces
     $this->composerUpdate();
     // Note: this also updates the modules registry.
     $io->done("Template <info>{$moduleName}</info> is now installed on <info>{$path}</info>");
 }
コード例 #2
0
 /**
  * Returns the values from a single column of the array, identified by the column key.
  * This is a simplified implementation of the native array_column function for PHP < 5.5 but it
  * additionally allows fetching properties from an array of objects.
  * Array elements can be objects or arrays.
  * The first element in the array is used to determine the element type for the whole array.
  *
  * @param int|string $key Null value is not supported.
  *
  * @return PowerArray Self, for chaining.
  */
 function getColumn($key)
 {
     $this->A = array_getColumn($this->A, $key);
     return $this;
 }