setVersion() public method

public setVersion ( string $version ) : Extension
$version string
return Extension
示例#1
0
 /**
  * @return Collection
  */
 public function getExtensions()
 {
     $extensionsDir = $this->getExtensionsDir();
     $dirs = array_diff(scandir($extensionsDir), ['.', '..']);
     $extensions = new Collection();
     $installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
     foreach ($dirs as $dir) {
         if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
             $extension = new Extension($extensionsDir . '/' . $dir, json_decode(file_get_contents($manifest), true));
             if (empty($extension->name)) {
                 continue;
             }
             foreach ($installed as $package) {
                 if ($package['name'] === $extension->name) {
                     $extension->setInstalled(true);
                     $extension->setVersion($package['version']);
                     $extension->setEnabled($this->isEnabled($dir));
                 }
             }
             $extensions->put($dir, $extension);
         }
     }
     return $extensions->sortBy(function ($extension, $name) {
         return $extension->composerJsonAttribute('extra.flarum-extension.title');
     });
 }
示例#2
0
 /**
  * @return Collection
  */
 public function getExtensions()
 {
     if (is_null($this->extensions) && $this->filesystem->exists(public_path('vendor/composer/installed.json'))) {
         $extensions = new Collection();
         // Load all packages installed by composer.
         $installed = json_decode($this->filesystem->get(public_path('vendor/composer/installed.json')), true);
         foreach ($installed as $package) {
             if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) {
                 continue;
             }
             // Instantiates an Extension object using the package path and composer.json file.
             $extension = new Extension($this->getExtensionsDir() . '/' . Arr::get($package, 'name'), $package);
             // Per default all extensions are installed if they are registered in composer.
             $extension->setInstalled(true);
             $extension->setVersion(Arr::get($package, 'version'));
             $extension->setEnabled($this->isEnabled($extension->getId()));
             $extensions->put($extension->getId(), $extension);
         }
         $this->extensions = $extensions->sortBy(function ($extension, $name) {
             return $extension->composerJsonAttribute('extra.flarum-extension.title');
         });
     }
     return $this->extensions;
 }