-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: Remake updater factory to service locator
- Loading branch information
1 parent
61f0f60
commit 3655a7f
Showing
5 changed files
with
89 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
application/libraries/ExtensionInstaller/ExtensionUpdaterFactory.php
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
application/libraries/ExtensionInstaller/ExtensionUpdaterServiceLocator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* LimeSurvey | ||
* Copyright (C) 2007-2015 The LimeSurvey Project Team / Carsten Schmitz | ||
* All rights reserved. | ||
* License: GNU/GPL License v2 or later, see LICENSE.php | ||
* LimeSurvey is free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
* other free or open source software licenses. | ||
* See COPYRIGHT.php for copyright notices and details. | ||
*/ | ||
|
||
namespace LimeSurvey\ExtensionInstaller; | ||
|
||
/** | ||
* @since 2018-09-26 | ||
* @author Olle Haerstedt | ||
*/ | ||
class ExtensionUpdaterServiceLocator | ||
{ | ||
/** | ||
* @var array<string, callable> | ||
*/ | ||
protected $updaters = []; | ||
|
||
/** | ||
* All Yii components need an init() method. | ||
* @return void | ||
*/ | ||
public function init() : void | ||
{ | ||
$this->addUpdater( | ||
'plugin', | ||
function () { | ||
return PluginUpdater::createUpdaters(); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* @param string $name Updater class name, like 'PluginUpdater', or 'ExtensionUpdater'. | ||
* @param callable $creator Callable that returns an ExtensionUpdater array. | ||
* @return void | ||
*/ | ||
public function addUpdater(string $name, callable $creator) : void | ||
{ | ||
if (isset($this->updaters[$name])) { | ||
throw new \Exception("Extension installer with name $name already exists"); | ||
} | ||
$this->updaters[$name] = $creator; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return ExtensionUpdater | ||
*/ | ||
public function getUpdater(string $name) : ?ExtensionUpdater | ||
{ | ||
if (isset($this->updaters[$name])) { | ||
$updater = $this->updaters[$name](); | ||
return $updater; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* @return ExtensionUpdater[] | ||
*/ | ||
public function getAllUpdaters() | ||
{ | ||
// Get an extension updater for each extension installed. | ||
$updaters = []; | ||
$errors = []; | ||
foreach ($this->updaters as $name => $creator) { | ||
$updaters = array_merge($creator(), $updaters); | ||
} | ||
return $updaters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters