From 24c41a45ba5c80eaf136c8b11a1f8b9c4fd95ab4 Mon Sep 17 00:00:00 2001 From: "Perez-Silva, Davian S" Date: Mon, 3 Sep 2018 14:15:17 -0400 Subject: [PATCH 1/4] Created my index.php file --- index.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..d5e4f52 --- /dev/null +++ b/index.php @@ -0,0 +1,6 @@ + Date: Mon, 3 Sep 2018 14:18:15 -0400 Subject: [PATCH 2/4] Writing out code comments to make sure i understand whats going on --- index.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.php b/index.php index d5e4f52..f5f7ac0 100644 --- a/index.php +++ b/index.php @@ -4,3 +4,10 @@ require './vendor/autoload.php'; //It allows you to automatically pull in scripts and classes without having to do it manually $app = new \Slim\App; //$app is our instance of slim. +$app->get('/hello/{name}', function (Request $request, Response $response, array $args) { + $name = $args['name']; + $response->getBody()->write("Hello, $name"); + return $response; +}); +//{name} in the url indicates what the argument will be called +//Line 9; adds the text "Hello, $name" to the response From 53b82342acc37c14823af36c0889f0320f46c763 Mon Sep 17 00:00:00 2001 From: "Perez-Silva, Davian S" Date: Mon, 3 Sep 2018 14:20:30 -0400 Subject: [PATCH 3/4] Added the last part of the app --- index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index f5f7ac0..fd3ac6d 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ use \Psr\Http\Message\ResponseInterface as Response; //This allows us to use the Request and Response objects in our code require './vendor/autoload.php'; //It allows you to automatically pull in scripts and classes without having to do it manually -$app = new \Slim\App; //$app is our instance of slim. +$app = new \Slim\App; //$app is our instance of slim $app->get('/hello/{name}', function (Request $request, Response $response, array $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); @@ -11,3 +11,4 @@ }); //{name} in the url indicates what the argument will be called //Line 9; adds the text "Hello, $name" to the response +$app->run(); //This tells PHP to run the slim app From 6d5cd6ce260f20e5fa2ee1ecaf0f07330d37b18f Mon Sep 17 00:00:00 2001 From: "Perez-Silva, Davian S" Date: Mon, 3 Sep 2018 22:03:12 -0400 Subject: [PATCH 4/4] This code creates and writes to app.log file in that directory --- api/composer.json | 2 +- index.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/composer.json b/api/composer.json index 8666ffb..a4bb9eb 100644 --- a/api/composer.json +++ b/api/composer.json @@ -8,7 +8,7 @@ }, "autoload": { "psr-4": { - "my\\namespace\\" : "src" + "Davian\\apilabtemplate\\" : "src" } } } diff --git a/index.php b/index.php index fd3ac6d..dc8a012 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ use \Psr\Http\Message\ResponseInterface as Response; //This allows us to use the Request and Response objects in our code require './vendor/autoload.php'; //It allows you to automatically pull in scripts and classes without having to do it manually -$app = new \Slim\App; //$app is our instance of slim +$app = new \apilabtemplate\App; //$app is our instance of slim $app->get('/hello/{name}', function (Request $request, Response $response, array $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); @@ -11,4 +11,13 @@ }); //{name} in the url indicates what the argument will be called //Line 9; adds the text "Hello, $name" to the response + +$container = $app->getContainer(); +$container['logger'] = function($c) { + $logger = new \Monolog\Logger('my_logger'); + $file_handler = new \Monolog\Handler\StreamHandler('../logs/app.log'); + $logger->pushHandler($file_handler); + return $logger; +}; //This creates a new directory 'logs' in the firstSlim directory +//Creates and writes to app.log file in that directory. $app->run(); //This tells PHP to run the slim app