1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24:
25: 26: 27: 28: 29: 30:
31: abstract class AbstractTextComponent extends FormComponent
32: {
33: protected function convertInput()
34: {
35: $primatives = array(self::TYPE_BOOL, self::TYPE_DOUBLE, self::TYPE_FLOAT, self::TYPE_INT);
36: $type = $this->getType();
37:
38: if($type==self::TYPE_STRING)
39: {
40: $this->setConvertedInput($this->getRawInput());
41: }
42: else if(in_array($type, $primatives))
43: {
44: $convertedInput = $this->getRawInput();
45: settype($convertedInput, $type);
46: $this->setConvertedInput($convertedInput);
47: }
48: else
49: {
50: try
51: {
52: $converter = $this->getApplication()->getConverter($type);
53: if($converter==null)
54: {
55: throw new ConversionException(sprintf("A converter for type %s could not be located.", $type));
56: }
57: else
58: {
59: $converted = $converter->convertToObject($string);
60: $this->setConvertedInput($converted);
61: }
62: }
63: catch(ConversionException $ex)
64: {
65: $this->invalid();
66:
67: $this->error('conversion error');
68: }
69: }
70: }
71:
72: protected abstract function getType();
73:
74: protected function validateModel()
75: {
76: $modelObject = $this->getModelObject();
77:
78: if($modelObject!=null)
79: {
80: if(is_object($modelObject) && get_class($modelObject)!=$this->getType())
81: {
82: throw new \IllegalStateException(sprintf("This text component needs a %s model, actual %s", $this->getType(), gettype($this->getModelObject())));
83: }
84: else if(!is_object($modelObject) && gettype($modelObject)!=$this->getType())
85: {
86: throw new \IllegalStateException(sprintf("This text component needs a %s model, actual %s", $this->getType(), gettype($this->getModelObject())));
87: }
88: }
89: }
90: }
91:
92: ?>
93: