This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (41 loc) · 1.45 KB
/
index.php
File metadata and controls
50 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @author: Tolga CESUR
* @website: tolgacesur.com
* @website : api.eczanapp.space
*
*/
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\PhpRenderer;
require 'vendor/autoload.php';
require_once("Eczane.php");
header('Access-Control-Allow-Origin: * ');
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
/* 404 ERROR*/
$c = new \Slim\Container();
$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
return $c['response']
->withStatus(404)
->withHeader('Content-Type', 'text/html')
->write('Endpoint not found');
};
};
$app = new \Slim\App($c);
$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./");
$app->get('/', function(Request $request, Response $response){
return $this->renderer->render($response, "/index.html");
});
$app->get('/pharmacy/{city}', function (Request $request, Response $response) {
$city = $request->getAttribute('city'); // get url parameter
$pharmacy = new Eczane($city);
$pharmacy = $pharmacy->getPharmacy(); // turn json
$response->getBody()->write($pharmacy);
return $response;
});
$app->run();