protected function validate($value) { if (!is_scalar($value)) { return 'scalar'; } if (!Valid::max_length($value, 255)) { return 'max_length'; } }
/** * 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; }
/** * 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)); }