本文整理汇总了PHP中Vars::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Vars::limit方法的具体用法?PHP Vars::limit怎么用?PHP Vars::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vars
的用法示例。
在下文中一共展示了Vars::limit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGravatarUrl
/**
* Generates an Gravatar URL.
*
* Size of the image:
* * The default size is 32px, and it can be anywhere between 1px up to 2048px.
* * If requested any value above the allowed range, then the maximum is applied.
* * If requested any value bellow the minimum, then the default is applied.
*
* Default image:
* * It can be an URL to an image.
* * Or one of built in options that Gravatar has. See Email::getGravatarBuiltInImages().
* * If none is defined then a built in default is used. See Email::getGravatarBuiltInDefaultImage().
*
* @param string $email
* @param int $size
* @param string $defaultImage
* @return null|string
* @link http://en.gravatar.com/site/implement/images/
*/
public static function getGravatarUrl($email, $size = 32, $defaultImage = 'identicon')
{
if (empty($email) || self::_isValid($email) === false) {
return null;
}
$hash = md5(strtolower(trim($email)));
$parts = array('scheme' => 'http', 'host' => 'www.gravatar.com');
if (Url::isHttps()) {
$parts = array('scheme' => 'https', 'host' => 'secure.gravatar.com');
}
// Get size
$size = Vars::limit(Filter::int($size), 32, 2048);
// Prepare default images
$defaultImage = trim($defaultImage);
if (preg_match('/^(http|https)./', $defaultImage)) {
$defaultImage = urldecode($defaultImage);
} else {
$defaultImage = strtolower($defaultImage);
if (!Arr::in((string) $defaultImage, self::getGravatarBuiltInImages())) {
$defaultImage = self::getGravatarBuiltInDefaultImage();
}
}
// Build full url
$parts['path'] = '/avatar/' . $hash . '/';
$parts['query'] = array('s' => $size, 'd' => $defaultImage);
$url = Url::create($parts);
return $url;
}
示例2: opacity
/**
* Check opacity value
*
* @param $opacity
* @return int
*/
public static function opacity($opacity)
{
if ($opacity <= 1) {
$opacity *= 100;
}
$opacity = Filter::int($opacity);
$opacity = Vars::limit($opacity, 0, 100);
return $opacity;
}