<?php

namespace Good\Rolemodel\Schema;

use Good\Rolemodel\SchemaVisitor;

class TextMember extends PrimitiveMember
{
    public function acceptSchemaVisitor(SchemaVisitor $visitor)
    {
        // visit this, there are no children to pass visitor on to
        $visitor->visitTextMember($this);
    }
    
    function getValidParameterTypeModifiers()
    {
        return array('minLength', 'maxLength', 'length');;
    }
    
    function getValidNonParameterTypeModifiers()
    {
        return array();
    }
    
    function processTypeModifiers(array $typeModifiers)
    {
        if (array_key_exists('length', $typeModifiers))
        {
            if (array_key_exists('minLength', $typeModifiers) ||
                array_key_exists('maxLength', $typeModifiers))
            {
                throw new \Exception("The 'length' type modifier cannot be defined alongside 'minLength' or 'maxLength'.");
            }
            
            $typeModifiers['minLength'] = $typeModifiers['length'];
            $typeModifiers['maxLength'] = $typeModifiers['length'];
            unset($typeModifiers['length']);
        }
        
        return $typeModifiers;
    }
    
    function getDefaultTypeModifierValues()
    {
        return array();
    }
}

?>
<?php

namespace Good\Rolemodel\Schema;

use Good\Rolemodel\SchemaVisitor;

class TextMember extends PrimitiveMember
{
    public function acceptSchemaVisitor(SchemaVisitor $visitor)
    {
        // visit this, there are no children to pass visitor on to
        $visitor->visitTextMember($this);
    }
    
    function getValidParameterTypeModifiers()
    {
        return array('minLength', 'maxLength', 'length');;
    }
    
    function getValidNonParameterTypeModifiers()
    {
        return array();
    }
    
    function processTypeModifiers(array $typeModifiers)
    {
        if (array_key_exists('length', $typeModifiers))
        {
            if (array_key_exists('minLength', $typeModifiers) ||
                array_key_exists('maxLength', $typeModifiers))
            {
                throw new \Exception("The 'length' type modifier cannot be defined alongside 'minLength' or 'maxLength'.");
            }
            
            if ($typeModifiers['length'] < 0)
            {
                throw new \Exception("The length for a text must be positive");
            }
            
            $typeModifiers['minLength'] = $typeModifiers['length'];
            $typeModifiers['maxLength'] = $typeModifiers['length'];
            unset($typeModifiers['length']);
        }
        
        if (array_key_exists('minLength', $typeModifiers) && 
            array_key_exists('maxLength', $typeModifiers) &&
            $typeModifiers['minLength'] > $typeModifiers['maxLength'])
        {
            throw new \Exception("The minLength for a text cannot be higher than its maxLength");
        }
        
        if ((array_key_exists('minLength', $typeModifiers) && $typeModifiers['minLength'] < 0) || 
            (array_key_exists('maxLength', $typeModifiers) && $typeModifiers['maxLength'] < 0))
        {
            throw new \Exception("The minLength and maxLength for a text must be positive");
        }
        
        return $typeModifiers;
    }
    
    function getDefaultTypeModifierValues()
    {
        return array('minLength' => 0);
    }
}

?>
Add additional processing on text type modifiers
Add additional processing on text type modifiers

- minLength cannot be higher than maxLength

- minLength, maxLength and length cannot be negative

- minLength defaults to 0
