VersionUpdate.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Grav\Installer;
  3. use Closure;
  4. use Grav\Common\Utils;
  5. /**
  6. * Class VersionUpdate
  7. * @package Grav\Installer
  8. */
  9. final class VersionUpdate
  10. {
  11. /** @var string */
  12. private $revision;
  13. /** @var string */
  14. private $version;
  15. /** @var string */
  16. private $date;
  17. /** @var string */
  18. private $patch;
  19. /** @var VersionUpdater */
  20. private $updater;
  21. /** @var callable[] */
  22. private $methods;
  23. public function __construct(string $file, VersionUpdater $updater)
  24. {
  25. $name = basename($file, '.php');
  26. $this->revision = $name;
  27. [$this->version, $this->date, $this->patch] = explode('_', $name);
  28. $this->updater = $updater;
  29. $this->methods = require $file;
  30. }
  31. public function getRevision(): string
  32. {
  33. return $this->revision;
  34. }
  35. public function getVersion(): string
  36. {
  37. return $this->version;
  38. }
  39. public function getDate(): string
  40. {
  41. return $this->date;
  42. }
  43. public function getPatch(): string
  44. {
  45. return $this->patch;
  46. }
  47. public function getUpdater(): VersionUpdater
  48. {
  49. return $this->updater;
  50. }
  51. /**
  52. * Run right before installation.
  53. */
  54. public function preflight(VersionUpdater $updater): void
  55. {
  56. $method = $this->methods['preflight'] ?? null;
  57. if ($method instanceof Closure) {
  58. $method->call($this);
  59. }
  60. }
  61. /**
  62. * Runs right after installation.
  63. */
  64. public function postflight(VersionUpdater $updater): void
  65. {
  66. $method = $this->methods['postflight'] ?? null;
  67. if ($method instanceof Closure) {
  68. $method->call($this);
  69. }
  70. }
  71. }