Interval.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /*
  3. * This file is part of composer/semver.
  4. *
  5. * (c) Composer <https://github.com/composer>
  6. *
  7. * For the full copyright and license information, please view
  8. * the LICENSE file that was distributed with this source code.
  9. */
  10. namespace Composer\Semver;
  11. use Composer\Semver\Constraint\Constraint;
  12. class Interval
  13. {
  14. /** @var Constraint */
  15. private $start;
  16. /** @var Constraint */
  17. private $end;
  18. public function __construct(Constraint $start, Constraint $end)
  19. {
  20. $this->start = $start;
  21. $this->end = $end;
  22. }
  23. /**
  24. * @return Constraint
  25. */
  26. public function getStart()
  27. {
  28. return $this->start;
  29. }
  30. /**
  31. * @return Constraint
  32. */
  33. public function getEnd()
  34. {
  35. return $this->end;
  36. }
  37. /**
  38. * @return Constraint
  39. */
  40. public static function fromZero()
  41. {
  42. static $zero;
  43. if (null === $zero) {
  44. $zero = new Constraint('>=', '0.0.0.0-dev');
  45. }
  46. return $zero;
  47. }
  48. /**
  49. * @return Constraint
  50. */
  51. public static function untilPositiveInfinity()
  52. {
  53. static $positiveInfinity;
  54. if (null === $positiveInfinity) {
  55. $positiveInfinity = new Constraint('<', PHP_INT_MAX.'.0.0.0');
  56. }
  57. return $positiveInfinity;
  58. }
  59. /**
  60. * @return self
  61. */
  62. public static function any()
  63. {
  64. return new self(self::fromZero(), self::untilPositiveInfinity());
  65. }
  66. /**
  67. * @return array{'names': string[], 'exclude': bool}
  68. */
  69. public static function anyDev()
  70. {
  71. // any == exclude nothing
  72. return array('names' => array(), 'exclude' => true);
  73. }
  74. /**
  75. * @return array{'names': string[], 'exclude': bool}
  76. */
  77. public static function noDev()
  78. {
  79. // nothing == no names included
  80. return array('names' => array(), 'exclude' => false);
  81. }
  82. }