Adding BrowserString view helper.
This commit is contained in:
parent
b1a25c7a15
commit
4fbd142ed7
1 changed files with 56 additions and 0 deletions
56
library/Fiktiv/View/Helper/BrowserString.php
Normal file
56
library/Fiktiv/View/Helper/BrowserString.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* View Helper to create a string with browser information from Zend_Http_UserAgent
|
||||
*/
|
||||
class Fiktiv_View_Helper_BrowserString extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Variable to hold the browser string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $_info = "";
|
||||
|
||||
/**
|
||||
* Helper method to format the version part of the string.
|
||||
*
|
||||
* @param Zend_Http_UserAgent $httpAgent
|
||||
* @return string
|
||||
*/
|
||||
private function _getVersion(Zend_Http_UserAgent $httpAgent)
|
||||
{
|
||||
// Trim the version down abit.
|
||||
$parts = explode('.', $httpAgent->getDevice()->getBrowserVersion());
|
||||
return implode('.', array_slice($parts, 0, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Constructs and stores the browser string to
|
||||
* later be retrieved by the helper method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Construct the string.
|
||||
$httpAgent = new Zend_Http_UserAgent();
|
||||
|
||||
$this->_info = $httpAgent->getDevice()->getBrowser() . " "
|
||||
. $this->_getVersion($httpAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Actual helper method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function browserString()
|
||||
{
|
||||
return $this->_info;
|
||||
}
|
||||
}
|
||||
Reference in a new issue