protected function bindValue(FormElement $element, ReflectionClass $refl, $instance)
    {
        $name = $element->getName(true);
        if (substr($name, 0, 1) === "_")
            return;

        $value = $element->getValue();
        $method_name = "set" . strtoupper(substr($name, 0, 1)) . substr($name, 1);
        if ($refl->hasMethod($method_name))
        {
            $setter = $refl->getMethod($method_name);
            $params = $setter->getParameters();
            if (count($params) !== 1)
                throw new BinderException("Setter $method_name should take exactly one argument");

            $setter->invoke($instance, $value);
        }
        elseif ($refl->isSubclassOf(Model::class))
        {
            // Model provides a setField method that should be able to set all parameters
            $instance->setField($name, $element->getValue());
        }
        else
        {
            // No known accessors, the property should be settable directly
            if (!$refl->hasProperty($name))
                throw new BinderException("There is no attribute $name on class {$refl->getName()}");

            $property = $refl->getProperty($name);
            if (!$property->isPublic() || $property->isStatic())
                throw new BinderException("Property $name should be public and non-static");

            $property->setValue($instance, $value);
        }
    }
protected function bindValue(FormElement $element, ReflectionClass $refl, $instance)
    {
        $name = $element->getName(true);
        if (substr($name, 0, 1) === "_")
            return;

        $value = $element->getValue();
        $method_name = "set" . strtoupper(substr($name, 0, 1)) . substr($name, 1);
        if ($refl->hasMethod($method_name))
        {
            $setter = $refl->getMethod($method_name);
            $params = $setter->getParameters();
            if (count($params) !== 1)
                throw new BinderException("Setter $method_name should take exactly one argument");

            $setter->invoke($instance, $value);
        }
        elseif ($refl->isSubclassOf(Model::class))
        {
            // Model provides a setField method that should be able to set all parameters
            $instance->setField($name, $element->getValue());
        }
        else
        {
            // No known accessors, the property should be settable directly
            if (!$refl->hasProperty($name))
                throw new BinderException("There is no attribute $name on class {$refl->getName()}");

            $property = $refl->getProperty($name);
            if (!$property->isPublic() || $property->isStatic())
                throw new BinderException("Property $name should be public and non-static");

            $property->setValue($instance, $value);
        }
    }
protected function bindValue ( FormElement $ element , ReflectionClass $ refl , $ instance ) { $ name = $ element -> getName ( true ) ; if ( substr ( $ name , 0 , 1 ) === "_" ) return ; $ value = $ element -> getValue ( ) ; $ method_name = "set" . strtoupper ( substr ( $ name , 0 , 1 ) ) . substr ( $ name , 1 ) ; if ( $ refl -> hasMethod ( $ method_name ) ) { $ setter = $ refl -> getMethod ( $ method_name ) ; $ params = $ setter -> getParameters ( ) ; if ( count ( $ params ) !== 1 ) throw new BinderException ( "Setter $method_name should take exactly one argument" ) ; $ setter -> invoke ( $ instance , $ value ) ; } elseif ( $ refl -> isSubclassOf ( Model :: class ) ) { // Model provides a setField method that should be able to set all parameters $ instance -> setField ( $ name , $ element -> getValue ( ) ) ; } else { // No known accessors, the property should be settable directly if ( ! $ refl -> hasProperty ( $ name ) ) throw new BinderException ( "There is no attribute $name on class {$refl->getName()}" ) ; $ property = $ refl -> getProperty ( $ name ) ; if ( ! $ property -> isPublic ( ) || $ property -> isStatic ( ) ) throw new BinderException ( "Property $name should be public and non-static" ) ; $ property -> setValue ( $ instance , $ value ) ; } }
Set a value from a form to an instance of a class

@param FormElement $element The element containing the value
@param ReflectionClass $refl The ReflectionClass of the object being set
@param object $instance The object being set
Set a value from a form to an instance of a class