File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -57,14 +57,15 @@ public function __destruct()
5757 protected function execute ()
5858 {
5959 try {
60- return $ this ->function ->invoke ($ this ->params );
60+ $ result = $ this ->function ->invoke ($ this ->params );
6161 } catch (\Exception $ exception ) {
6262 throw new FunctionCallException (sprintf (
6363 'Function call %s failed: %s ' ,
6464 $ this ->getName (),
6565 $ exception ->getMessage ()
6666 ), 0 , $ exception );
6767 }
68+ return $ this ->trimStrings ($ result );
6869 }
6970
7071 /**
@@ -84,4 +85,28 @@ protected function getFunction()
8485 ), 0 , $ exception );
8586 }
8687 }
88+
89+ /**
90+ * Trim the strings of a given data structure.
91+ * @param mixed $return
92+ * @return mixed
93+ */
94+ protected function trimStrings ($ return )
95+ {
96+ if (is_string ($ return )) {
97+ /**
98+ * Do not trim strings containing line breaks.
99+ */
100+ if (strtr ($ return , "\n" ) || strtr ($ return , "\r\n" )) {
101+ return $ return ;
102+ }
103+ return rtrim ($ return );
104+ }
105+ if (is_array ($ return )) {
106+ foreach ($ return as $ key => $ value ) {
107+ $ return [$ key ] = $ this ->trimStrings ($ value );
108+ }
109+ }
110+ return $ return ;
111+ }
87112}
You can’t perform that action at this time.
0 commit comments