forked from mevdschee/php-crud-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
raml.php
58 lines (52 loc) · 1.9 KB
/
raml.php
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
51
52
53
54
55
56
57
58
<?php
require "Inflector.php";
$url = "http://localhost/api.php";
$hostname = "localhost";
$username = "root";
$password = "root";
$database = "mysql_crud_api";
$mysqli = new mysqli($hostname,$username,$password,$database);
if ($mysqli->connect_errno) {
throw new \Exception('Connect failed: '.$mysqli->connect_error);
}
$tables = array();
if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA` = '$database'")) {
while ($row = $result->fetch_row()) $tables[] = $row[0];
}
$result->close();
echo "#%RAML 0.8\n";
echo "title: $database\n";
echo "version: 1\n";
echo "baseUri: $url\n";
foreach ($tables as $object_table) {
$objects = Inflector::humanize($object_table);
$object = Inflector::humanize(Inflector::singularize($object_table));
echo "/$object_table:\n";
echo " displayName: $objects\n";
echo " description: A collection of $objects\n";
echo " get:\n";
echo " description: Get a list of $objects\n";
echo " queryParameters:\n";
echo " page:\n";
echo " description: Specify the page that you want to retrieve\n";
echo " required: false\n";
echo " filter:\n";
echo " description: Set to filter the list on a specific field\n";
echo " required: false\n";
echo " match:\n";
echo " description: Adjust the way the filter matches the value to the field\n";
echo " required: false\n";
echo " order:\n";
echo " description: Specify to change the sorting of the list\n";
echo " required: false\n";
echo " post:\n";
echo " description: Create a $object\n";
echo " /{id}:\n";
echo " description: A specific $object, a member of the $objects collection\n";
echo " get:\n";
echo " description: Get a specific $object\n";
echo " put:\n";
echo " description: Update a $object\n";
echo " delete:\n";
echo " description: Delete a $object\n";
}