VcsCheckerMethods.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace YahnisElsts\PluginUpdateChecker\v5p1\Vcs;
  3. if ( !trait_exists(VcsCheckerMethods::class, false) ) :
  4. trait VcsCheckerMethods {
  5. /**
  6. * @var string The branch where to look for updates. Defaults to "master".
  7. */
  8. protected $branch = 'master';
  9. /**
  10. * @var Api Repository API client.
  11. */
  12. protected $api = null;
  13. public function setBranch($branch) {
  14. $this->branch = $branch;
  15. return $this;
  16. }
  17. /**
  18. * Set authentication credentials.
  19. *
  20. * @param array|string $credentials
  21. * @return $this
  22. */
  23. public function setAuthentication($credentials) {
  24. $this->api->setAuthentication($credentials);
  25. return $this;
  26. }
  27. /**
  28. * @return Api
  29. */
  30. public function getVcsApi() {
  31. return $this->api;
  32. }
  33. public function getUpdate() {
  34. $update = parent::getUpdate();
  35. if ( isset($update) && !empty($update->download_url) ) {
  36. $update->download_url = $this->api->signDownloadUrl($update->download_url);
  37. }
  38. return $update;
  39. }
  40. public function onDisplayConfiguration($panel) {
  41. parent::onDisplayConfiguration($panel);
  42. $panel->row('Branch', $this->branch);
  43. $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
  44. $panel->row('API client', get_class($this->api));
  45. }
  46. }
  47. endif;