| 53 | | return $this->render(); |
|---|
| | 56 | try |
|---|
| | 57 | { |
|---|
| | 58 | return $this->render(); |
|---|
| | 59 | } |
|---|
| | 60 | catch (Exception $e) |
|---|
| | 61 | { |
|---|
| | 62 | self::setToStringException($e); |
|---|
| | 63 | |
|---|
| | 64 | // we return a simple Exception message in case the form framework is used out of symfony. |
|---|
| | 65 | return 'Exception: '.$e->getMessage(); |
|---|
| | 66 | } |
|---|
| | 67 | } |
|---|
| | 68 | |
|---|
| | 69 | /** |
|---|
| | 70 | * Returns true if a form thrown an exception in the __toString() method |
|---|
| | 71 | * |
|---|
| | 72 | * This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method. |
|---|
| | 73 | * |
|---|
| | 74 | * @return boolean |
|---|
| | 75 | */ |
|---|
| | 76 | static public function hasToStringException() |
|---|
| | 77 | { |
|---|
| | 78 | return !is_null(self::$toStringException); |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | /** |
|---|
| | 82 | * Gets the exception if one was thrown in the __toString() method. |
|---|
| | 83 | * |
|---|
| | 84 | * This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method. |
|---|
| | 85 | * |
|---|
| | 86 | * @return Exception |
|---|
| | 87 | */ |
|---|
| | 88 | static public function getToStringException() |
|---|
| | 89 | { |
|---|
| | 90 | return self::$toStringException; |
|---|
| | 91 | } |
|---|
| | 92 | |
|---|
| | 93 | /** |
|---|
| | 94 | * Sets an exception thrown by the __toString() method. |
|---|
| | 95 | * |
|---|
| | 96 | * This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method. |
|---|
| | 97 | * |
|---|
| | 98 | * @param Exception $e The exception thrown by __toString() |
|---|
| | 99 | */ |
|---|
| | 100 | static public function setToStringException(Exception $e) |
|---|
| | 101 | { |
|---|
| | 102 | if (is_null(self::$toStringException)) |
|---|
| | 103 | { |
|---|
| | 104 | self::$toStringException = $e; |
|---|
| | 105 | } |
|---|