mako\UserAgent


Description


Class that helps identifying the device or type of device that made the request.


Class methods


Toggle source

protected __construct()


Protected constructor since this is a static class.

Return value

NULL

protected function __construct()
{
	// Nothing here
}

Toggle source

protected static find($what)


Searches for a string in the user agent string.


Parameters

Type Description
array Array of strings to look for
Return value

boolean

protected static function find($what)
{
	if(isset($_SERVER['HTTP_USER_AGENT']))
	{
		foreach($what as $find)
		{
			if(stripos($_SERVER['HTTP_USER_AGENT'], $find) !== false)
			{
				return true;
			}
		}
	}
	
	return false;
}

Toggle source

protected static accept($header, $what = NULL)


Converts the HTTP_ACCEPT headers into an array.


Parameters

Type Description
string Array key
string (optional) String to look for
Return value

mixed

protected static function accept($header, $what = null)
{
	if(isset($_SERVER[$header]))
	{
		$accepts = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER[$header]))));
		
		if($what === null && !empty($accepts))
		{
			return $accepts;
		}
		else
		{
			return in_array(strtolower($what), $accepts);
		}
	}
	
	return false;
}

Toggle source

public static isMobile()


Returns true if the user agent that made the request is identified as a mobile device.

Return value

boolean

public static function isMobile()
{
	return static::find(Config::get('user_agents.mobiles'));
}

Toggle source

public static isRobot()


Returns true if the user agent that made the request is identified as a robot/crawler.

Return value

boolean

public static function isRobot()
{
	return static::find(Config::get('user_agents.robots'));
}

Toggle source

public static is($device)


Returns TRUE if the string you're looking for exists in the user agent string and FALSE if not.Can be used to detect the type of device (UserAgent::is('iphone') or UserAgent::is(array('iphone', 'ipod'))).


Parameters

Type Description
mixed String or array of strings you're looking for
Return value

boolean

public static function is($device)
{
	return static::find((array) $device);
}

Toggle source

public static accepts($content = NULL)


Returns list of accepted content types or boolean value if you are looking for a content type.


Parameters

Type Description
string (optional) Language to look for.
Return value

mixed

public static function accepts($content = null)
{
	return static::accept('HTTP_ACCEPT', $content);
}

Toggle source

public static acceptsLanguage($language = NULL)


Returns list of accepted languages or boolean value if you are looking for a language.


Parameters

Type Description
string (optional) Language to look for.
Return value

mixed

public static function acceptsLanguage($language = null)
{
	return static::accept('HTTP_ACCEPT_LANGUAGE', $language);
}

Toggle source

public static acceptsCharset($charset = NULL)


Returns list of accepted character sets or boolean value if you are looking for a character set.


Parameters

Type Description
string (optional) Character set to look for.
Return value

mixed

public static function acceptsCharset($charset = null)
{
	return static::accept('HTTP_ACCEPT_CHARSET', $charset);
}

Toggle source

public static acceptsEncoding($encoding = NULL)


Returns list of accepted encodings or boolean value if you are looking for an encoding.


Parameters

Type Description
string (optional) Language to look for.
Return value

mixed

public static function acceptsEncoding($encoding = null)
{
	return static::accept('HTTP_ACCEPT_ENCODING', $encoding);
}