Skip to content

Commit 39e9876

Browse files
build: added slim for api framework
1 parent a8ea4cc commit 39e9876

20 files changed

+55
-542
lines changed

.env-simple

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# Database Variables
2-
DATABASE_HOST = ''
3-
DATABASE_NAME = ''
4-
ACCESS_TOKEN = ''
1+
NAME = ''

.gitattributes

-3
This file was deleted.

.gitignore

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

3-
# dependencies
4-
/vendor/
3+
# Composer
4+
/vendor
55
composer.lock
6+
.env
67

7-
# misc
8-
.DS_Store
9-
*.pem
8+
# IDEs and editors
9+
.idea/
10+
.project
11+
.classpath
12+
.c9/
13+
*.launch
14+
.settings/
15+
*.sublime-workspace
16+
17+
# Visual Studio Code
18+
# .vscode/*
19+
# .vscode/settings.json
20+
# .vscode/tasks.json
21+
# .vscode/launch.json
22+
# .vscode/extensions.json
23+
# .history/*
1024

11-
# local env files
12-
.env
25+
# System files
26+
.DS_Store
27+
Thumbs.db

.htaccess

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
RewriteEngine on
2-
RewriteRule ^access_token=([a-z0-9]+)$ index.php?access_token=$1
3-
RewriteRule ^([a-z]+)/([a-z0-9]+)/access_token=([a-z0-9]+)$ index.php?collection=$1&&id=$2&&access_token=$3
4-
RewriteRule ^([a-z]+)/([a-z0-9]+)$ index.php?collection=$1&&id=$2
5-
RewriteRule ^([a-z]+)/access_token=([a-z0-9]+)$ index.php?collection=$1&&access_token=$2
6-
RewriteRule ^([a-z]+)$ index.php?collection=$1
1+
RewriteEngine On
2+
RewriteCond %{REQUEST_FILENAME} !-f
3+
RewriteCond %{REQUEST_FILENAME} !-d
4+
RewriteRule ^ index.php [QSA,L]

.vscode/extensions.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3+
"recommendations": [
4+
"vscode-icons-team.vscode-icons",
5+
"DEVSENSE.phptools-vscode",
6+
"mhutchie.git-graph"
7+
]
8+
}

README.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1 @@
1-
# Php Rest API Application
2-
3-
### Installation
4-
Run the Composer command to install the latest stable version of RestJS:
5-
6-
```
7-
composer required restjs/php-rest-api
8-
```
9-
10-
### Used Feature
11-
> `json`, `headers_authorization`, `upload_file`, `access_token`
12-
13-
## Quick links
14-
1. [**Get API**](http://localhost/php-rest-api/test/access_token=<Access_Token>) for `GET`, `POST`, `PUT`, `DELETE`
15-
2. [**Upload File**](http://localhost/php-rest-api/file/access_token=<Access_Token>) for `POST`, `DELETE`
16-
17-
### API Routes
18-
| HTTP Method | Path | Action | Scope | Desciption |
19-
| ----- | ----- | ----- | ---- |------------- |
20-
| GET | /<collection_name> | index | document:list | Get all document
21-
| POST | /<collection_name> | store | document:create | Create an document
22-
| GET | /<collection_name>/{_id} | show | document:read | Fetch an document by id
23-
| PUT | /<collection_name>/{_id} | update | document:write | Update an document by id
24-
| DELETE | /<collection_name>/{_id} | destroy | document:delete | Delete an document by id
1+
# Php Rest API Application

composer.json

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
{
22
"name": "restjs/php-rest-api",
33
"description": "Create Rest API Application",
4-
"type": "package",
54
"keywords": [
65
"php",
76
"composer",
87
"rest-api",
98
"file-upload",
109
"web-services",
1110
"jwt-authentication",
12-
"my-sql"
11+
"my-sql",
12+
"slim"
1313
],
1414
"homepage": "https://github.com/fullstackondemand/php-rest-api",
1515
"license": "MIT",
1616
"autoload": {
1717
"psr-4": {
18-
"RestJS\\PhpRestApi\\": "src/"
18+
"RestJS\\": "src/"
1919
}
2020
},
21-
"repositories": [
22-
{
23-
"type": "package",
24-
"package": {
25-
"name": "RestJS/php-rest-api",
26-
"version": "v2",
27-
"source": {
28-
"url": "https://github.com/fullstackondemand/php-rest-api.git",
29-
"type": "git",
30-
"reference": "master"
31-
}
32-
}
33-
}
34-
],
3521
"authors": [
3622
{
3723
"name": "Pramod Singh",
@@ -44,8 +30,8 @@
4430
"prefer-stable": true,
4531
"require": {
4632
"php": "7.1.*|7.2.*|7.3.*|7.4.*|8.0.*|8.1.*",
47-
"mongodb/mongodb": "^1.12",
48-
"alcaeus/mongo-php-adapter": "^1.2",
49-
"vlucas/phpdotenv": "^5.6"
33+
"vlucas/phpdotenv": "^5.6",
34+
"slim/slim": "4.*",
35+
"slim/psr7": "^1.7"
5036
}
51-
}
37+
}

index.php

+11-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
11
<?php
2-
use Dotenv\Dotenv;
2+
use Psr\Http\Message\ResponseInterface as Response;
3+
use Psr\Http\Message\ServerRequestInterface as Request;
4+
use Slim\Factory\AppFactory;
35

4-
/* Include Varibles File */
5-
require_once __DIR__ . '/vendor/autoload.php';
6+
require __DIR__ . '/vendor/autoload.php';
67

7-
/* Environment File Config */
8-
$dotenv = Dotenv::createImmutable(__DIR__);
8+
$app = AppFactory::create();
9+
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
910
$dotenv->load();
1011

11-
/* Head Allows Section */
12-
require __DIR__ . '/src/views/header.view.php';
13-
$headers = getallheaders();
12+
$app->get('/api/', function (Request $request, Response $response, $args) {
13+
$response->getBody()->write("Hello {$_ENV['NAME']}!");
14+
return $response;
15+
});
1416

15-
/* Check Database Connection */
16-
require __DIR__ . '/src/controllers/database.controller.php';
17-
$database = (new Database())->connection();
18-
19-
/* Check Authentication */
20-
require __DIR__ . '/src/views/access_token.view.php';
21-
22-
/* Check Collection */
23-
require __DIR__ . '/src/controllers/collection.controller.php';
24-
$collection = (new Collection())->Collection($database);
25-
26-
/* Check ID */
27-
if (!isset($_GET['id'])) {
28-
$id = null;
29-
} else {
30-
$id = $_GET['id'];
31-
}
32-
33-
/* Check Upload File */
34-
if (isset($_GET['collection']) && $_GET['collection'] === "file") {
35-
require __DIR__ . '/src/controllers/file.controller.php';
36-
(new FileController())->FileController($_SERVER['REQUEST_METHOD']);
37-
die();
38-
}
39-
40-
/* Method Controller File */
41-
require __DIR__ . '/src/controllers/method.controller.php';
42-
(new MethodController())->methodController($_SERVER['REQUEST_METHOD'], $collection, $id, __DIR__);
17+
$app->run();

php-rest-api.sql

-73
This file was deleted.

src/controllers/collection.controller.php

-20
This file was deleted.

src/controllers/database.controller.php

-25
This file was deleted.

0 commit comments

Comments
 (0)