Нет описания

ActionScheduler_Versions.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Class ActionScheduler_Versions
  4. */
  5. class ActionScheduler_Versions {
  6. /**
  7. * @var ActionScheduler_Versions
  8. */
  9. private static $instance = NULL;
  10. private $versions = array();
  11. public function register( $version_string, $initialization_callback ) {
  12. if ( isset($this->versions[$version_string]) ) {
  13. return FALSE;
  14. }
  15. $this->versions[$version_string] = $initialization_callback;
  16. return TRUE;
  17. }
  18. public function get_versions() {
  19. return $this->versions;
  20. }
  21. public function latest_version() {
  22. $keys = array_keys($this->versions);
  23. if ( empty($keys) ) {
  24. return false;
  25. }
  26. uasort( $keys, 'version_compare' );
  27. return end($keys);
  28. }
  29. public function latest_version_callback() {
  30. $latest = $this->latest_version();
  31. if ( empty($latest) || !isset($this->versions[$latest]) ) {
  32. return '__return_null';
  33. }
  34. return $this->versions[$latest];
  35. }
  36. /**
  37. * @return ActionScheduler_Versions
  38. * @codeCoverageIgnore
  39. */
  40. public static function instance() {
  41. if ( empty(self::$instance) ) {
  42. self::$instance = new self();
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * @codeCoverageIgnore
  48. */
  49. public static function initialize_latest_version() {
  50. $self = self::instance();
  51. call_user_func($self->latest_version_callback());
  52. }
  53. }