AutoloadFileWriter.php
1 year ago
AutoloadGenerator.php
1 year ago
AutoloadProcessor.php
1 year ago
CustomAutoloaderPlugin.php
1 year ago
ManifestGenerator.php
1 year ago
autoload.php
5 years ago
class-autoloader-handler.php
5 years ago
class-autoloader-locator.php
1 year ago
class-autoloader.php
1 year ago
class-container.php
5 years ago
class-hook-manager.php
5 years ago
class-latest-autoloader-guard.php
1 year ago
class-manifest-reader.php
5 years ago
class-path-processor.php
1 year ago
class-php-autoloader.php
1 year ago
class-plugin-locator.php
1 year ago
class-plugins-handler.php
5 years ago
class-shutdown-handler.php
5 years ago
class-version-loader.php
1 year ago
class-version-selector.php
3 years ago
class-version-selector.php
62 lines
| 1 | <?php |
| 2 | /* HEADER */ // phpcs:ignore |
| 3 | |
| 4 | /** |
| 5 | * Used to select package versions. |
| 6 | */ |
| 7 | class Version_Selector { |
| 8 | |
| 9 | /** |
| 10 | * Checks whether the selected package version should be updated. Composer development |
| 11 | * package versions ('9999999-dev' or versions that start with 'dev-') are favored |
| 12 | * when the JETPACK_AUTOLOAD_DEV constant is set to true. |
| 13 | * |
| 14 | * @param String $selected_version The currently selected package version. |
| 15 | * @param String $compare_version The package version that is being evaluated to |
| 16 | * determine if the version needs to be updated. |
| 17 | * |
| 18 | * @return bool Returns true if the selected package version should be updated, |
| 19 | * else false. |
| 20 | */ |
| 21 | public function is_version_update_required( $selected_version, $compare_version ) { |
| 22 | $use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV; |
| 23 | |
| 24 | if ( $selected_version === null ) { |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | if ( $use_dev_versions && $this->is_dev_version( $selected_version ) ) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | if ( $this->is_dev_version( $compare_version ) ) { |
| 33 | if ( $use_dev_versions ) { |
| 34 | return true; |
| 35 | } else { |
| 36 | return false; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if ( version_compare( $selected_version, $compare_version, '<' ) ) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Checks whether the given package version is a development version. |
| 49 | * |
| 50 | * @param String $version The package version. |
| 51 | * |
| 52 | * @return bool True if the version is a dev version, else false. |
| 53 | */ |
| 54 | public function is_dev_version( $version ) { |
| 55 | if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 |