22
33use Entity \Project ;
44use Entity \Index ;
5+ use Command \ErrorCommand ;
56
67class App {
78 private $ router ;
89 private $ container ;
910 private $ projectsPool = [];
1011 private $ currentProject = null ;
12+ private $ noFsIO = false ;
1113
12- public function __construct (){
14+ public function __construct ($ noFsIO ){
15+ $ this ->noFsIO = $ noFsIO ;
1316 $ this ->router = new Router ;
1417 }
1518 public function handle ($ request , $ response , $ data ){
1619 $ command = $ this ->getRouter ()
1720 ->getCommand (
1821 $ this ->getCommandName ($ request )
1922 );
23+ if ($ command instanceof ErrorCommand){
24+ return $ command ->run ([]);
25+ }
2026 $ this ->container = $ command ->getContainer ();
2127 $ arguments = $ this ->parseQuery ($ request ->getQuery (), $ data );
2228 $ arguments ["project " ] = $ this ->loadProject ($ arguments );
@@ -59,7 +65,9 @@ protected function loadProject($arguments){
5965 $ project = $ this ->projectsPool [$ rootDir ];
6066 }
6167 else {
62- $ project = $ this ->container ->get ("IO\Reader " )->read ($ rootDir );
68+ if (!$ this ->noFsIO ){
69+ $ project = $ this ->container ->get ("IO\Reader " )->read ($ rootDir );
70+ }
6371 if (empty ($ project )){
6472 $ project = $ this ->createEmptyProject ($ rootDir );
6573 }
@@ -73,10 +81,13 @@ protected function createEmptyProject($rootDir){
7381 $ project = new Project (new Index , $ rootDir );
7482 return $ project ;
7583 }
76- protected function setResponseHeaders ($ response ){
84+ public function setResponseHeaders ($ response ){
7785 try {
7886 $ response ->writeHead (200 , [
79- 'content-type ' => 'application/json '
87+ 'Content-Type ' => 'application/json ' ,
88+ 'Access-Control-Allow-Headers ' => 'Origin, Content-Type ' ,
89+ 'Access-Control-Allow-Origin ' => '* ' ,
90+ 'Origin ' => 'http://localhost:10000 '
8091 ]);
8192 }
8293 catch (\Exception $ e ){
0 commit comments