web/lib/Zend/Tool/Framework/System/Provider/Version.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Version.php 22763 2010-08-02 02:59:36Z ramon $
       
    20  */
       
    21 
       
    22 require_once 'Zend/Tool/Framework/Registry.php';
       
    23 require_once 'Zend/Tool/Framework/Provider/Interface.php';
       
    24 require_once 'Zend/Version.php';
       
    25 
       
    26 /**
       
    27  * Version Provider
       
    28  *
       
    29  * @category   Zend
       
    30  * @package    Zend_Tool
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  */
       
    34 class Zend_Tool_Framework_System_Provider_Version
       
    35     implements Zend_Tool_Framework_Provider_Interface, Zend_Tool_Framework_Registry_EnabledInterface
       
    36 {
       
    37 
       
    38     /**
       
    39      * @var Zend_Tool_Framework_Registry_Interface
       
    40      */
       
    41     protected $_registry = null;
       
    42 
       
    43     const MODE_MAJOR = 'major';
       
    44     const MODE_MINOR = 'minor';
       
    45     const MODE_MINI  = 'mini';
       
    46 
       
    47     protected $_specialties = array('MajorPart', 'MinorPart', 'MiniPart');
       
    48 
       
    49     public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
       
    50     {
       
    51         $this->_registry = $registry;
       
    52         return $this;
       
    53     }
       
    54 
       
    55     /**
       
    56      * Show Action
       
    57      *
       
    58      * @param string $mode The mode switch can be one of: major, minor, or mini (default)
       
    59      * @param bool $nameIncluded
       
    60      */
       
    61     public function show($mode = self::MODE_MINI, $nameIncluded = true)
       
    62     {
       
    63 
       
    64         $versionInfo = $this->_splitVersion();
       
    65 
       
    66         switch($mode) {
       
    67             case self::MODE_MINOR:
       
    68                 unset($versionInfo['mini']);
       
    69                 break;
       
    70             case self::MODE_MAJOR:
       
    71                 unset($versionInfo['mini'], $versionInfo['minor']);
       
    72                 break;
       
    73         }
       
    74 
       
    75         $output = implode('.', $versionInfo);
       
    76 
       
    77         if ($nameIncluded) {
       
    78             $output = 'Zend Framework Version: ' . $output;
       
    79         }
       
    80 
       
    81         $this->_registry->response->appendContent($output);
       
    82     }
       
    83 
       
    84     public function showMajorPart($nameIncluded = true)
       
    85     {
       
    86         $versionNumbers = $this->_splitVersion();
       
    87         $output = (($nameIncluded == true) ? 'ZF Major Version: ' : null) . $versionNumbers['major'];
       
    88         $this->_registry->response->appendContent($output);
       
    89     }
       
    90 
       
    91     public function showMinorPart($nameIncluded = true)
       
    92     {
       
    93         $versionNumbers = $this->_splitVersion();
       
    94         $output = (($nameIncluded == true) ? 'ZF Minor Version: ' : null) . $versionNumbers['minor'];
       
    95         $this->_registry->response->appendContent($output);
       
    96     }
       
    97 
       
    98     public function showMiniPart($nameIncluded = true)
       
    99     {
       
   100         $versionNumbers = $this->_splitVersion();
       
   101         $output = (($nameIncluded == true) ? 'ZF Mini Version: ' : null)  . $versionNumbers['mini'];
       
   102         $this->_registry->response->appendContent($output);
       
   103     }
       
   104 
       
   105     protected function _splitVersion()
       
   106     {
       
   107         list($major, $minor, $mini) = explode('.', Zend_Version::VERSION);
       
   108         return array('major' => $major, 'minor' => $minor, 'mini' => $mini);
       
   109     }
       
   110 
       
   111 }