本文整理匯總了PHP中Valid::max_length方法的典型用法代碼示例。如果您正苦於以下問題:PHP Valid::max_length方法的具體用法?PHP Valid::max_length怎麽用?PHP Valid::max_length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Valid
的用法示例。
在下文中一共展示了Valid::max_length方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validate
protected function validate($value)
{
if (!is_scalar($value)) {
return 'scalar';
}
if (!Valid::max_length($value, 255)) {
return 'max_length';
}
}
示例2: set_loc
/**
* URL of the page. This URL must begin with the protocol (such as http) and end
* with a trailing slash, if your web server requires it. This value must be
* less than 2,048 characters.
* @see http://www.sitemaps.org/protocol.php
* @param string $location
*/
public function set_loc($location)
{
if (!Valid::max_length($location, 2048)) {
throw new LengthException('The location was too long, maximum length of 2,048 characters.');
}
$location = Sitemap::encode($location);
if (!Valid::url($location)) {
throw new InvalidArgumentException('The location was not a valid URL');
}
$this->attributes['loc'] = $location;
return $this;
}
示例3: test_max_length
/**
* Tests Valid::max_length()
*
* Checks that a field is short enough.
*
* @test
* @dataProvider provider_max_length
* @param string $string String to test
* @param integer $maxlength Max length for this string
* @param boolean $correct Is $string <= $maxlength
*/
public function test_max_length($string, $maxlength, $correct)
{
$this->assertSame($correct, Valid::max_length($string, $maxlength));
}