diff --git a/bootstrap.php b/bootstrap.php index ba554f7..2abef32 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -2,3 +2,5 @@ require "autoloader.php"; require "error_handler.php"; +require "config/config.php"; +require "dic.php"; diff --git a/config-dev/config.dev.php b/config-dev/config.dev.php new file mode 100644 index 0000000..b212138 --- /dev/null +++ b/config-dev/config.dev.php @@ -0,0 +1,6 @@ + true]); +} diff --git a/config-dev/config.php b/config-dev/config.php new file mode 120000 index 0000000..72705bf --- /dev/null +++ b/config-dev/config.php @@ -0,0 +1 @@ +config.dev.php \ No newline at end of file diff --git a/config-dev/db-connection.php b/config-dev/db-connection.php deleted file mode 100644 index 0ce1428..0000000 --- a/config-dev/db-connection.php +++ /dev/null @@ -1,3 +0,0 @@ - true]); diff --git a/dic.php b/dic.php new file mode 100644 index 0000000..962a50b --- /dev/null +++ b/dic.php @@ -0,0 +1,25 @@ +getBest($_SERVER["HTTP_ACCEPT"], ['text/html', 'application/json']) + ->getValue(); +} + +function getTweetsService() +{ + return new Service\TweetsService( + getDatabase() + ); +} + +function getUsersService() +{ + return new Service\UsersService( + getDatabase() + ); +} diff --git a/dic/negotiated_format.php b/dic/negotiated_format.php deleted file mode 100644 index fd1162f..0000000 --- a/dic/negotiated_format.php +++ /dev/null @@ -1,9 +0,0 @@ -getBest($_SERVER["HTTP_ACCEPT"], ['text/html', 'application/json']) - ->getValue(); diff --git a/dic/tweets.php b/dic/tweets.php deleted file mode 100644 index dbe8c1e..0000000 --- a/dic/tweets.php +++ /dev/null @@ -1,5 +0,0 @@ -getLastJoined(); +$lastJoinedUsers = getUsersService()->getLastJoined(); -switch (require "dic/negotiated_format.php") { +switch (getNegotiatedFormat()) { case "text/html": (new Views\Layout( "Twitter - Newcomers", new Views\Users\Listing($lastJoinedUsers), true diff --git a/web/tweet.php b/web/tweet.php index a3a5c56..6cfe3b0 100644 --- a/web/tweet.php +++ b/web/tweet.php @@ -1,6 +1,6 @@ getById($_GET["id"]); +$tweet = getTweetsService()->getById($_GET["id"]); if ($tweet === null) { http_response_code(404); @@ -14,12 +14,12 @@ exit; } -switch (require "dic/negotiated_format.php") { +switch (getNegotiatedFormat()) { case "text/html": (new Views\Layout( "@$_GET[user] - \"$tweet->message\"", new Views\Tweets\Page( - (require "dic/users.php")->getById($_GET["user"]), + getUsersService()->getById($_GET["user"]), $tweet ) ))(); diff --git a/web/user.php b/web/user.php index f88a31c..760a06c 100644 --- a/web/user.php +++ b/web/user.php @@ -1,18 +1,18 @@ getById($_GET["id"]); +$user = getUsersService()->getById($_GET["id"]); if ($user === null) { http_response_code(404); return; } -$tweetsService = (require "dic/tweets.php"); +$tweetsService = getTweetsService(); $tweets = $tweetsService->getLastByUser($_GET["id"]); $tweetsCount = $tweetsService->getTweetsCount($_GET["id"]); -switch (require "dic/negotiated_format.php") { +switch (getNegotiatedFormat()) { case "text/html": (new Views\Layout( "Tweets from @$_GET[id]",