Skip to content

Commit 3d72ce1

Browse files
committed
Added composer files for github workflow and adjust README
1 parent 46c8883 commit 3d72ce1

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
public/
1+
public/
2+
/vendor/

Diff for: README.md

+63-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,62 @@ This framework can be easily integrated into any PHP project using Composer.
1515
- **Meta Data**: The response includes metadata such as response code, server host, number of results, and script execution time.
1616
- **Data Type Management**: Support for defining and managing data types for each parameter.
1717

18+
## Installation via Composer
19+
20+
To use the **PHP-Api Framework** in your project, follow these steps:
21+
22+
### 1. Install Composer
23+
24+
Ensure that [Composer](https://getcomposer.org/) is installed on your system. If it's not installed yet, you can install it using the following command:
25+
26+
```bash
27+
curl -sS https://getcomposer.org/installer | php
28+
```
29+
30+
### 2. Add the Framework to Your Project
31+
32+
To install the framework from GitHub, specify the `develop` branch. You can do this by running the following command:
33+
34+
```bash
35+
composer require devt045t/php-api:develop
36+
```
37+
38+
Alternatively, if the package is not listed on Packagist, you can add the GitHub repository manually in your `composer.json` under the `"repositories"` section:
39+
40+
```json
41+
{
42+
"repositories": [
43+
{
44+
"type": "git",
45+
"url": "https://github.com/DevT045T/php-api.git"
46+
}
47+
],
48+
"require": {
49+
"devt045t/php-api": "develop"
50+
}
51+
}
52+
```
53+
54+
Then run:
55+
56+
```bash
57+
composer install
58+
```
59+
60+
This will install the framework from the `develop` branch and download all necessary files.
61+
62+
### 3. Enable Autoloading
63+
64+
Ensure that Composer's autoloader is included in your project. Add this line at the beginning of your PHP file:
65+
66+
```php
67+
require 'vendor/autoload.php';
68+
```
69+
70+
### 4. Use the Framework
71+
72+
You can now use the framework in your project. For more information on how to use it, refer to the [Usage](#Usage) section of this documentation.
73+
1874
## Usage
1975

2076
### Example: Define Allowed Parameters and Handle API Request
@@ -24,19 +80,20 @@ use devt045t\Api;
2480
use devt045t\ApiParameter;
2581
use devt045t\DataTypes;
2682
use devt045t\HttpStatusCodes;
83+
use devt045t\HttpMethods;
2784

2885
$api = new Api();
2986

3087
// Define allowed parameters
3188
$param1 = new ApiParameter();
3289
$param1
33-
->setName('username')
90+
->name('username')
3491
->required(true)
3592
->type(DataTypes::STRING);
3693

3794
$param2 = new ApiParameter();
3895
$param2
39-
->setName('password')
96+
->name('password')
4097
->required(true)
4198
->type(DataTypes::INT);
4299

@@ -45,6 +102,9 @@ $api
45102
->addParameter($param1)
46103
->addParameter($param2);
47104

105+
// Set the allowed request methods
106+
$api->setAllowedRequestMethod([HttpMethods::OPTIONS, HttpMethods::POST]);
107+
48108
// Validate parameters
49109
$api->validate();
50110

@@ -151,7 +211,7 @@ use devt045t\ApiParameter;
151211
use devt045t\DataTypes;
152212

153213
$param = new ApiParameter();
154-
$param->setName('username')->required(true)->type(DataTypes::STRING);
214+
$param->name('username')->required(true)->type(DataTypes::STRING);
155215
```
156216

157217
### Supported Data Types

Diff for: composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "t045t/php-api",
3+
"type": "library",
4+
"license": "MIT",
5+
"autoload": {
6+
"psr-4": {
7+
"devt045t\\": "src/"
8+
}
9+
},
10+
"authors": [
11+
{
12+
"name": "DevT045T",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"require": {}
17+
}

Diff for: src/Api.php

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public function __construct()
147147

148148
$this->scriptStartTime = microtime(true);
149149
$this->requestMethod = $_SERVER["REQUEST_METHOD"];
150+
$this->allowedRequestMethods = [];
150151
}
151152

152153
/**

0 commit comments

Comments
 (0)