Install
1 day ago
Setup
1 day ago
SetupFactory
1 day ago
Update
1 day ago
Install.php
1 day ago
InstallCollection.php
1 day ago
Setup.php
1 day ago
SetupFactory.php
1 day ago
Update.php
1 day ago
UpdateCollection.php
1 day ago
Version.php
1 day ago
SetupFactory.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Plugin; |
| 6 | |
| 7 | use AC\Storage\Option; |
| 8 | use AC\Storage\SiteOption; |
| 9 | use InvalidArgumentException; |
| 10 | |
| 11 | class SetupFactory |
| 12 | { |
| 13 | public const SITE = 'site'; |
| 14 | public const NETWORK = 'network'; |
| 15 | |
| 16 | private string $version_key; |
| 17 | |
| 18 | private Version $version; |
| 19 | |
| 20 | protected ?InstallCollection $installers; |
| 21 | |
| 22 | protected ?UpdateCollection $updates; |
| 23 | |
| 24 | public function __construct( |
| 25 | string $version_key, |
| 26 | Version $version, |
| 27 | ?InstallCollection $installers = null, |
| 28 | ?UpdateCollection $updates = null |
| 29 | ) { |
| 30 | $this->version_key = $version_key; |
| 31 | $this->version = $version; |
| 32 | $this->installers = $installers; |
| 33 | $this->updates = $updates; |
| 34 | } |
| 35 | |
| 36 | public function create(string $type): Setup |
| 37 | { |
| 38 | switch ($type) { |
| 39 | case self::NETWORK: |
| 40 | return new Setup\Network( |
| 41 | new SiteOption($this->version_key), |
| 42 | $this->version, |
| 43 | $this->installers, |
| 44 | $this->updates |
| 45 | ); |
| 46 | |
| 47 | case self::SITE: |
| 48 | return new Setup\Site( |
| 49 | new Option($this->version_key), |
| 50 | $this->version, |
| 51 | $this->installers, |
| 52 | $this->updates |
| 53 | ); |
| 54 | |
| 55 | default: |
| 56 | throw new InvalidArgumentException('Expected valid setup type.'); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | } |
| 61 |