Browscap.ini parsing class with caching and update capabilities. More...
Public Member Functions | |
__construct ($cache_dir) | |
getBrowser ($user_agent=null, $return_array=false) | |
updateCache () | |
Data Fields | |
const | VERSION = '0.7' |
const | UPDATE_FOPEN = 'URL-wrapper' |
const | UPDATE_FSOCKOPEN = 'socket' |
const | UPDATE_CURL = 'cURL' |
const | UPDATE_LOCAL = 'local' |
const | REGEX_DELIMITER = '@' |
const | REGEX_MODIFIERS = 'i' |
const | VALUES_TO_QUOTE = 'Browser|Parent' |
const | ORDER_FUNC_ARGS = '$a, $b' |
const | ORDER_FUNC_LOGIC = '$a=strlen($a);$b=strlen($b);return$a==$b?0:($a<$b?1:-1);' |
const | REQUEST_HEADERS = "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: Close\r\n\r\n" |
$remoteIniUrl = 'http://browsers.garykeith.com/stream.asp?BrowsCapINI' | |
$remoteVerUrl = 'http://updates.browserproject.com/version-date.asp' | |
$timeout = 5 | |
$updateInterval = 432000 | |
$errorInterval = 7200 | |
$doAutoUpdate = true | |
$updateMethod = null | |
$localFile = null | |
$userAgent = 'Browser Capabilities Project - PHP Browscap/%v %m' | |
$lowercase = false | |
$silent = false | |
$cacheFilename = 'cache.php' | |
$iniFilename = 'browscap.ini' | |
$cacheDir = null | |
Private Member Functions | |
_loadCache ($cache_file) | |
_buildCache () | |
_getRemoteIniFile ($url, $path) | |
_getRemoteMTime () | |
_getLocalMTime () | |
_array2string ($array) | |
_getUpdateMethod () | |
_getRemoteData ($url) | |
_getUserAgent () | |
Private Attributes | |
$_cacheLoaded = false | |
$_userAgents = array() | |
$_browsers = array() | |
$_patterns = array() | |
$_properties = array() |
Browscap.ini parsing class with caching and update capabilities.
Definition at line 14 of file Browscap.class.php.
Browscap::__construct | ( | $ | cache_dir | ) |
Constructor class, checks for the existence of (and loads) the cache and if needed updated the definitions
string | $cache_dir |
Definition at line 163 of file Browscap.class.php.
Browscap::_array2string | ( | $ | array | ) | [private] |
Converts the given array to the PHP string which represent it. This method optimizes the PHP code and the output differs form the var_export one as the internal PHP function does not strip whitespace or convert strings to numbers.
array | $array | the array to parse and convert |
Definition at line 501 of file Browscap.class.php.
Browscap::_buildCache | ( | ) | [private] |
Parses the array to cache and creates the PHP string to write to disk
Definition at line 386 of file Browscap.class.php.
Browscap::_getLocalMTime | ( | ) | [private] |
Gets the local ini file update timestamp
RuntimeException |
Definition at line 483 of file Browscap.class.php.
Browscap::_getRemoteData | ( | $ | url | ) | [private] |
Retrieve the data identified by the URL
string | $url | the url of the data |
RuntimeException |
Definition at line 561 of file Browscap.class.php.
Browscap::_getRemoteIniFile | ( | $ | url, |
$ | path | ||
) | [private] |
Updates the local copy of the ini file (by version checking) and adapts his syntax to the PHP ini parser
string | $url | the url of the remote server |
string | $path | the path of the ini file to update |
RuntimeException |
Definition at line 413 of file Browscap.class.php.
Browscap::_getRemoteMTime | ( | ) | [private] |
Gets the remote ini file update timestamp
RuntimeException |
Definition at line 465 of file Browscap.class.php.
Browscap::_getUpdateMethod | ( | ) | [private] |
Checks for the various possibilities offered by the current configuration of PHP to retrieve external HTTP data
Definition at line 534 of file Browscap.class.php.
Browscap::_getUserAgent | ( | ) | [private] |
Format the useragent string to be used in the remote requests made by the class during the update process.
Definition at line 643 of file Browscap.class.php.
Browscap::_loadCache | ( | $ | cache_file | ) | [private] |
Loads the cache into object's properties
Definition at line 369 of file Browscap.class.php.
Browscap::getBrowser | ( | $ | user_agent = null , |
$ | return_array = false |
||
) |
Gets the information about the browser by User Agent
string | $user_agent | the user agent string |
bool | $return_array | whether return an array or an object |
RuntimeException |
Definition at line 194 of file Browscap.class.php.
Parses the ini file and updates the cache files
Definition at line 286 of file Browscap.class.php.
Browscap::$_browsers = array() [private] |
Definition at line 153 of file Browscap.class.php.
Browscap::$_cacheLoaded = false [private] |
Definition at line 145 of file Browscap.class.php.
Browscap::$_patterns = array() [private] |
Definition at line 154 of file Browscap.class.php.
Browscap::$_properties = array() [private] |
Definition at line 155 of file Browscap.class.php.
Browscap::$_userAgents = array() [private] |
Definition at line 152 of file Browscap.class.php.
Browscap::$cacheDir = null |
Definition at line 138 of file Browscap.class.php.
Browscap::$cacheFilename = 'cache.php' |
Definition at line 124 of file Browscap.class.php.
Browscap::$doAutoUpdate = true |
Definition at line 82 of file Browscap.class.php.
Browscap::$errorInterval = 7200 |
Definition at line 81 of file Browscap.class.php.
Browscap::$iniFilename = 'browscap.ini' |
Definition at line 131 of file Browscap.class.php.
Browscap::$localFile = null |
Definition at line 91 of file Browscap.class.php.
Browscap::$lowercase = false |
Definition at line 107 of file Browscap.class.php.
Browscap::$remoteIniUrl = 'http://browsers.garykeith.com/stream.asp?BrowsCapINI' |
Options for auto update capabilities
$remoteVerUrl: The location to use to check out if a new version of the browscap.ini file is available. $remoteIniUrl: The location from which download the ini file. The placeholder for the file should be represented by a s. $timeout: The timeout for the requests. $updateInterval: The update interval in seconds. $errorInterval: The next update interval in seconds in case of an error. $doAutoUpdate: Flag to disable the automatic interval based update. $updateMethod: The method to use to update the file, has to be a value of an UPDATE_* constant, null or false.
Definition at line 77 of file Browscap.class.php.
Browscap::$remoteVerUrl = 'http://updates.browserproject.com/version-date.asp' |
Definition at line 78 of file Browscap.class.php.
Browscap::$silent = false |
Definition at line 117 of file Browscap.class.php.
Browscap::$timeout = 5 |
Definition at line 79 of file Browscap.class.php.
Browscap::$updateInterval = 432000 |
Definition at line 80 of file Browscap.class.php.
Browscap::$updateMethod = null |
Definition at line 83 of file Browscap.class.php.
Browscap::$userAgent = 'Browser Capabilities Project - PHP Browscap/%v %m' |
Definition at line 99 of file Browscap.class.php.
const Browscap::ORDER_FUNC_ARGS = '$a, $b' |
Definitions of the function used by the uasort() function to order the userAgents array.
ORDER_FUNC_ARGS: Arguments that the function will take. ORDER_FUNC_LOGIC: Internal logic of the function.
Definition at line 55 of file Browscap.class.php.
const Browscap::ORDER_FUNC_LOGIC = '$a=strlen($a);$b=strlen($b);return$a==$b?0:($a<$b?1:-1);' |
Definition at line 56 of file Browscap.class.php.
const Browscap::REGEX_DELIMITER = '@' |
Options for regex patterns.
REGEX_DELIMITER: Delimiter of all the regex patterns in the whole class. REGEX_MODIFIERS: Regex modifiers.
Definition at line 40 of file Browscap.class.php.
const Browscap::REGEX_MODIFIERS = 'i' |
Definition at line 41 of file Browscap.class.php.
const Browscap::REQUEST_HEADERS = "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: Close\r\n\r\n" |
The headers to be sent for checking the version and requesting the file.
Definition at line 61 of file Browscap.class.php.
const Browscap::UPDATE_CURL = 'cURL' |
Definition at line 31 of file Browscap.class.php.
const Browscap::UPDATE_FOPEN = 'URL-wrapper' |
Different ways to access remote and local files.
UPDATE_FOPEN: Uses the fopen url wrapper (use file_get_contents). UPDATE_FSOCKOPEN: Uses the socket functions (fsockopen). UPDATE_CURL: Uses the cURL extension. UPDATE_LOCAL: Updates from a local file (file_get_contents).
Definition at line 29 of file Browscap.class.php.
const Browscap::UPDATE_FSOCKOPEN = 'socket' |
Definition at line 30 of file Browscap.class.php.
const Browscap::UPDATE_LOCAL = 'local' |
Definition at line 32 of file Browscap.class.php.
const Browscap::VALUES_TO_QUOTE = 'Browser|Parent' |
The values to quote in the ini file
Definition at line 46 of file Browscap.class.php.
const Browscap::VERSION = '0.7' |
Current version of the class.
Definition at line 19 of file Browscap.class.php.