Version.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. require_once 'Zend/Tool/Framework/Registry.php';
  22. require_once 'Zend/Tool/Framework/Provider/Interface.php';
  23. require_once 'Zend/Version.php';
  24. /**
  25. * Version Provider
  26. *
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Framework_System_Provider_Version
  33. implements Zend_Tool_Framework_Provider_Interface, Zend_Tool_Framework_Registry_EnabledInterface
  34. {
  35. /**
  36. * @var Zend_Tool_Framework_Registry_Interface
  37. */
  38. protected $_registry = null;
  39. const MODE_MAJOR = 'major';
  40. const MODE_MINOR = 'minor';
  41. const MODE_MINI = 'mini';
  42. protected $_specialties = array('MajorPart', 'MinorPart', 'MiniPart');
  43. public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
  44. {
  45. $this->_registry = $registry;
  46. return $this;
  47. }
  48. /**
  49. * Show Action
  50. *
  51. * @param string $mode The mode switch can be one of: major, minor, or mini (default)
  52. * @param bool $nameIncluded
  53. */
  54. public function show($mode = self::MODE_MINI, $nameIncluded = true)
  55. {
  56. $versionInfo = $this->_splitVersion();
  57. switch($mode) {
  58. case self::MODE_MINOR:
  59. unset($versionInfo['mini']);
  60. break;
  61. case self::MODE_MAJOR:
  62. unset($versionInfo['mini'], $versionInfo['minor']);
  63. break;
  64. }
  65. $output = implode('.', $versionInfo);
  66. if ($nameIncluded) {
  67. $output = 'Zend Framework Version: ' . $output;
  68. }
  69. $this->_registry->response->appendContent($output);
  70. }
  71. public function showMajorPart($nameIncluded = true)
  72. {
  73. $versionNumbers = $this->_splitVersion();
  74. $output = (($nameIncluded == true) ? 'ZF Major Version: ' : null) . $versionNumbers['major'];
  75. $this->_registry->response->appendContent($output);
  76. }
  77. public function showMinorPart($nameIncluded = true)
  78. {
  79. $versionNumbers = $this->_splitVersion();
  80. $output = (($nameIncluded == true) ? 'ZF Minor Version: ' : null) . $versionNumbers['minor'];
  81. $this->_registry->response->appendContent($output);
  82. }
  83. public function showMiniPart($nameIncluded = true)
  84. {
  85. $versionNumbers = $this->_splitVersion();
  86. $output = (($nameIncluded == true) ? 'ZF Mini Version: ' : null) . $versionNumbers['mini'];
  87. $this->_registry->response->appendContent($output);
  88. }
  89. protected function _splitVersion()
  90. {
  91. list($major, $minor, $mini) = explode('.', Zend_Version::VERSION);
  92. return array('major' => $major, 'minor' => $minor, 'mini' => $mini);
  93. }
  94. }