Skip to content

Commit 2a8e287

Browse files
Merge PR #1
Master
2 parents bcd6d2e + b1b66c9 commit 2a8e287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2374
-0
lines changed

.coveralls.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
json_path: coveralls-upload.json

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: monthly
7+
open-pull-requests-limit: 10
8+
versioning-strategy: increase

.github/workflows/tests.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
name: Tests PHP ${{ matrix.php }}
8+
runs-on: ubuntu-latest
9+
continue-on-error: ${{ matrix.experimental }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
php: [7.4, 8.0, 8.1]
14+
experimental: [false]
15+
include:
16+
- php: 8.1
17+
analysis: true
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
23+
- name: Set up PHP ${{ matrix.php }}
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
coverage: xdebug
28+
29+
- name: Install dependencies with Composer
30+
uses: ramsey/composer-install@v2
31+
32+
- name: Coding standards
33+
if: matrix.analysis
34+
run: vendor/bin/phpcs
35+
36+
- name: Static analysis
37+
if: matrix.analysis
38+
run: vendor/bin/phpstan
39+
40+
- name: Tests
41+
run: vendor/bin/phpunit --coverage-clover clover.xml
42+
43+
- name: Upload coverage results to Coveralls
44+
if: matrix.analysis
45+
env:
46+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
run: |
48+
composer require php-coveralls/php-coveralls -n -W
49+
vendor/bin/php-coveralls --coverage_clover=clover.xml -v

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea/
2+
.vscode/
3+
/coverage/
4+
/vendor/
5+
/logs/*
6+
!/logs/README.md
7+
.phpunit.result.cache
8+
.DS_Store

.htaccess

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Options All -Indexes
2+
3+
<Files .htaccess>
4+
order allow,deny
5+
deny from all
6+
</Files>
7+
8+
<IfModule mod_rewrite.c>
9+
# Redirect to the public folder
10+
RewriteEngine On
11+
# RewriteBase /
12+
RewriteRule ^$ public/ [L]
13+
RewriteRule (.*) public/$1 [L]
14+
15+
# Redirect to HTTPS
16+
# RewriteEngine On
17+
# RewriteCond %{HTTPS} off
18+
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
19+
</IfModule>

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# How to Contribute
2+
3+
## Pull Requests
4+
5+
1. Fork the Slim Skeleton repository
6+
2. Create a new branch for each feature or improvement
7+
3. Send a pull request from each feature branch to the **4.x** branch
8+
9+
It is very important to separate new features or improvements into separate feature branches, and to send a
10+
pull request for each branch. This allows us to review and pull in new features or improvements individually.
11+
12+
## Style Guide
13+
14+
All pull requests must adhere to the [PSR-12 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md).

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# MTEX Mock API
2+
3+
Simple REST API providing sample JSON data for testing and prototyping.
4+
5+
## Installation
6+
7+
```bash
8+
composer install
9+
```
10+
11+
## Local Development
12+
13+
```bash
14+
php -S localhost:8000 -t public
15+
```
16+
17+
Visit `http://localhost:8000` to see the API documentation.
18+
19+
## Endpoints
20+
21+
### Documentation
22+
23+
- `GET /` - API documentation
24+
25+
### Users
26+
27+
- `GET /users` - List all users
28+
- `GET /users/{id}` - Get user by ID
29+
30+
### Posts
31+
32+
- `GET /posts` - List all posts
33+
- `GET /posts/{id}` - Get post by ID
34+
35+
### Products
36+
37+
- `GET /products` - List all products
38+
- `GET /products/{id}` - Get product by ID
39+
40+
## Example Requests
41+
42+
```bash
43+
curl https://mock.mtex.dev/users
44+
curl https://mock.mtex.dev/users/1
45+
curl https://mock.mtex.dev/posts
46+
curl https://mock.mtex.dev/products/2
47+
```
48+
49+
## Features
50+
51+
- [x] RESTful API design
52+
- [x] JSON responses
53+
- [x] CORS enabled
54+
- [x] Error handling
55+
- [x] Self-documenting
56+
- [x] No database required
57+
58+
## Tech Stack
59+
60+
- PHP 8.1+
61+
- Slim Framework 4
62+
- PSR-7 HTTP Messages
63+
64+
## License
65+
66+
MIT

app/dependencies.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Application\Settings\SettingsInterface;
6+
use DI\ContainerBuilder;
7+
use Monolog\Handler\StreamHandler;
8+
use Monolog\Logger;
9+
use Monolog\Processor\UidProcessor;
10+
use Psr\Container\ContainerInterface;
11+
use Psr\Log\LoggerInterface;
12+
13+
return function (ContainerBuilder $containerBuilder) {
14+
$containerBuilder->addDefinitions([
15+
LoggerInterface::class => function (ContainerInterface $c) {
16+
$settings = $c->get(SettingsInterface::class);
17+
18+
$loggerSettings = $settings->get('logger');
19+
$logger = new Logger($loggerSettings['name']);
20+
21+
$processor = new UidProcessor();
22+
$logger->pushProcessor($processor);
23+
24+
$handler = new StreamHandler($loggerSettings['path'], $loggerSettings['level']);
25+
$logger->pushHandler($handler);
26+
27+
return $logger;
28+
},
29+
]);
30+
};

app/middleware.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Application\Middleware\SessionMiddleware;
6+
use Slim\App;
7+
8+
return function (App $app) {
9+
$app->add(SessionMiddleware::class);
10+
};

app/repositories.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Domain\User\UserRepository;
6+
use App\Infrastructure\Persistence\User\InMemoryUserRepository;
7+
use DI\ContainerBuilder;
8+
9+
return function (ContainerBuilder $containerBuilder) {
10+
// Here we map our UserRepository interface to its in memory implementation
11+
$containerBuilder->addDefinitions([
12+
UserRepository::class => \DI\autowire(InMemoryUserRepository::class),
13+
]);
14+
};

0 commit comments

Comments
 (0)