Archived
1
0
Fork 0

Adding BrowserString view helper.

This commit is contained in:
Henrik Hautakoski 2013-02-19 17:24:01 +01:00
parent b1a25c7a15
commit 4fbd142ed7

View 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;
}
}