<?php
require_once 'ValidationHandlerAbstract.php';

class 
MaxLengthValidationHandler extends ValidationHandlerAbstract
{
    private 
$_maxLength;

    public function 
__construct($maxLength 0)
    {
        
parent::__construct();
        if (!
preg_match('/^\d+$/'$maxLength)) {
            throw new 
RuntimeException('Max length is invalid.');
        }
        
$this->_maxLength = (int)$maxLength;
    }

    protected function 
_execValidation($input)
    {
        return (
strlen($input) <= $this->_maxLength);
    }

    protected function 
_getErrorMessage()
    {
        return 
$this->_maxLength 'バイト以内で入力してください。';
    }
}