Version.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Gedmo;
  3. use Gedmo\Exception\DependentComponentNotFoundException;
  4. use Gedmo\Exception\IncompatibleComponentVersionException;
  5. /**
  6. * Version class allows to checking the dependencies required
  7. * and the current version of doctrine extensions
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @subpackage Version
  11. * @package Gedmo
  12. * @link http://www.gediminasm.org
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. final class Version
  16. {
  17. /**
  18. * Current version of extensions
  19. */
  20. const VERSION = '2.2.0-DEV';
  21. /**
  22. * Checks the dependent ORM library components
  23. * for compatibility
  24. *
  25. * @throws DependentComponentNotFoundException
  26. * @throws IncompatibleComponentVersionException
  27. */
  28. public static function checkORMDependencies()
  29. {
  30. // doctrine common library
  31. if (!class_exists('Doctrine\\Common\\Version')) {
  32. throw new DependentComponentNotFoundException("Doctrine\\Common library is either not registered by autoloader or not installed");
  33. }
  34. if (\Doctrine\Common\Version::compare(self::VERSION) > 0) {
  35. throw new IncompatibleComponentVersionException("Doctrine\\Common library is older than expected for these extensions");
  36. }
  37. // doctrine dbal library
  38. if (!class_exists('Doctrine\\DBAL\\Version')) {
  39. throw new DependentComponentNotFoundException("Doctrine\\DBAL library is either not registered by autoloader or not installed");
  40. }
  41. if (\Doctrine\DBAL\Version::compare(self::VERSION) > 0) {
  42. throw new IncompatibleComponentVersionException("Doctrine\\DBAL library is older than expected for these extensions");
  43. }
  44. // doctrine ORM library
  45. if (!class_exists('Doctrine\\ORM\\Version')) {
  46. throw new DependentComponentNotFoundException("Doctrine\\ORM library is either not registered by autoloader or not installed");
  47. }
  48. if (\Doctrine\ORM\Version::compare(self::VERSION) > 0) {
  49. throw new IncompatibleComponentVersionException("Doctrine\\ORM library is older than expected for these extensions");
  50. }
  51. }
  52. /**
  53. * Checks the dependent ODM MongoDB library components
  54. * for compatibility
  55. *
  56. * @throws DependentComponentNotFoundException
  57. * @throws IncompatibleComponentVersionException
  58. */
  59. public static function checkODMMongoDBDependencies()
  60. {
  61. // doctrine common library
  62. if (!class_exists('Doctrine\\Common\\Version')) {
  63. throw new DependentComponentNotFoundException("Doctrine\\Common library is either not registered by autoloader or not installed");
  64. }
  65. if (\Doctrine\Common\Version::compare(self::VERSION) > 0) {
  66. throw new IncompatibleComponentVersionException("Doctrine\\Common library is older than expected for these extensions");
  67. }
  68. // doctrine mongodb library
  69. if (!class_exists('Doctrine\\MongoDB\\Database')) {
  70. throw new DependentComponentNotFoundException("Doctrine\\MongoDB library is either not registered by autoloader or not installed");
  71. }
  72. // doctrine ODM MongoDB library
  73. if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) {
  74. throw new DependentComponentNotFoundException("Doctrine\\ODM\\MongoDB library is either not registered by autoloader or not installed");
  75. }
  76. if (\Doctrine\ODM\MongoDB\Version::compare('1.0.0BETA3-DEV') > 0) {
  77. throw new IncompatibleComponentVersionException("Doctrine\\ODM\\MongoDB library is older than expected for these extensions");
  78. }
  79. }
  80. }