本文整理汇总了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));
}