77use Neuron \Core \Exceptions \BadRequestMethod ;
88use Neuron \Core \Exceptions \MissingMethod ;
99use Neuron \Core \Exceptions \NotFound ;
10+ use Neuron \Core \Exceptions \Validation ;
1011use Neuron \Data \Setting \Source \ISettingSource ;
1112use Neuron \Log \Log ;
1213use Neuron \Mvc \Controllers \Factory ;
@@ -28,6 +29,8 @@ class Application extends Base
2829 private string $ _RoutesPath ;
2930 private Router $ _Router ;
3031 private array $ _Requests = [];
32+ private bool $ _CaptureOutput = false ;
33+ private ?string $ _Output = '' ;
3134
3235 /**
3336 * Application constructor.
@@ -43,7 +46,7 @@ public function __construct( string $Version, ?ISettingSource $Source = null )
4346
4447 Registry::getInstance ()->set ( 'BasePath ' , $ this ->getBasePath () );
4548
46- $ RoutesPath = $ this ->getSetting ( 'routes_path ' , 'paths ' );
49+ $ RoutesPath = $ this ->getSetting ( 'routes_path ' , 'system ' );
4750 if ( $ RoutesPath )
4851 {
4952 $ this ->setRoutesPath ( $ RoutesPath );
@@ -53,6 +56,32 @@ public function __construct( string $Version, ?ISettingSource $Source = null )
5356 $ this ->loadRoutes ();
5457 }
5558
59+ /**
60+ * @param bool $CaptureOutput
61+ * @return $this
62+ */
63+ public function setCaptureOutput ( bool $ CaptureOutput ): Application
64+ {
65+ $ this ->_CaptureOutput = $ CaptureOutput ;
66+ return $ this ;
67+ }
68+
69+ /**
70+ * @return bool
71+ */
72+ public function getCaptureOutput (): bool
73+ {
74+ return $ this ->_CaptureOutput ;
75+ }
76+
77+ /**
78+ * @return string
79+ */
80+ public function getOutput (): ?string
81+ {
82+ return $ this ->_Output ;
83+ }
84+
5685 /**
5786 * @return string
5887 */
@@ -191,7 +220,16 @@ protected function onStart(): bool
191220 */
192221 protected function onRun () : void
193222 {
194- echo $ this ->_Router ->run ( $ this ->getParameters () );
223+ $ Output = $ this ->_Router ->run ( $ this ->getParameters () );
224+
225+ if ( !$ this ->_CaptureOutput )
226+ {
227+ echo $ Output ;
228+ }
229+ else
230+ {
231+ $ this ->_Output = $ Output ;
232+ }
195233 }
196234
197235 /**
@@ -270,7 +308,7 @@ protected function loadRoutes(): void
270308 catch ( ParseException $ exception )
271309 {
272310 Log::error ( "Failed to load routes: " .$ exception ->getMessage () );
273- return ;
311+ throw new Validation ( $ exception -> getMessage (), [] ) ;
274312 }
275313
276314 foreach ( $ Data [ 'routes ' ] as $ Route )
0 commit comments