-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from adrianfalleiro/slim-4
Refactor for Slim 4
- Loading branch information
Showing
57 changed files
with
4,231 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json_path: coveralls-upload.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
/coverage/ | ||
/vendor/ | ||
/logs/* | ||
!/logs/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: php | ||
|
||
dist: trusty | ||
|
||
matrix: | ||
include: | ||
- php: 7.1 | ||
- php: 7.2 | ||
- php: 7.3 | ||
env: ANALYSIS='true' | ||
- php: nightly | ||
|
||
allow_failures: | ||
- php: nightly | ||
|
||
before_script: | ||
- composer require php-coveralls/php-coveralls:^2.1.0 | ||
- composer install -n | ||
|
||
script: | ||
- if [[ "$ANALYSIS" == 'true' ]]; then vendor/bin/phpunit --coverage-clover clover.xml ; fi | ||
|
||
after_success: | ||
- if [[ "$ANALYSIS" == 'true' ]]; then vendor/bin/php-coveralls --coverage_clover=clover.xml -v ; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# How to Contribute | ||
|
||
## Pull Requests | ||
|
||
1. Fork the Slim Skeleton repository | ||
2. Create a new branch for each feature or improvement | ||
3. Send a pull request from each feature branch to the **4.x** branch | ||
|
||
It is very important to separate new features or improvements into separate feature branches, and to send a | ||
pull request for each branch. This allows us to review and pull in new features or improvements individually. | ||
|
||
## Style Guide | ||
|
||
All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Slim Framework 4 Skeleton Application | ||
|
||
[![Coverage Status](https://coveralls.io/repos/github/slimphp/Slim-Skeleton/badge.svg?branch=master)](https://coveralls.io/github/slimphp/Slim-Skeleton?branch=master) | ||
|
||
Use this skeleton application to quickly setup and start working on a new Slim Framework 4 application. This application uses the latest Slim 4 with Slim PSR-7 implementation and PHP-DI container implementation. It also uses the Monolog logger. | ||
|
||
This skeleton application was built for Composer. This makes setting up a new Slim Framework application quick and easy. | ||
|
||
## Install the Application | ||
|
||
Run this command from the directory in which you want to install your new Slim Framework application. | ||
|
||
```bash | ||
composer create-project slim/slim-skeleton [my-app-name] | ||
``` | ||
|
||
Replace `[my-app-name]` with the desired directory name for your new application. You'll want to: | ||
|
||
* Point your virtual host document root to your new application's `public/` directory. | ||
* Ensure `logs/` is web writable. | ||
|
||
To run the application in development, you can run these commands | ||
|
||
```bash | ||
cd [my-app-name] | ||
composer start | ||
``` | ||
|
||
Or you can use `docker-compose` to run the app with `docker`, so you can run these commands: | ||
```bash | ||
cd [my-app-name] | ||
docker-compose up -d | ||
``` | ||
After that, open `http://localhost:8080` in your browser. | ||
|
||
Run this command in the application directory to run the test suite | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
That's it! Now go build something cool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use DI\ContainerBuilder; | ||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
use Monolog\Processor\UidProcessor; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
return function (ContainerBuilder $containerBuilder) { | ||
$containerBuilder->addDefinitions([ | ||
LoggerInterface::class => function (ContainerInterface $c) { | ||
$settings = $c->get('settings'); | ||
|
||
$loggerSettings = $settings['logger']; | ||
$logger = new Logger($loggerSettings['name']); | ||
|
||
$processor = new UidProcessor(); | ||
$logger->pushProcessor($processor); | ||
|
||
$handler = new StreamHandler($loggerSettings['path'], $loggerSettings['level']); | ||
$logger->pushHandler($handler); | ||
|
||
return $logger; | ||
}, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use App\Application\Middleware\SessionMiddleware; | ||
use Slim\App; | ||
|
||
use adrianfalleiro\SlimCliRunner\CliRunner; | ||
|
||
return function (App $app) { | ||
$app->add(SessionMiddleware::class); | ||
$app->add(CliRunner::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use App\Domain\User\UserRepository; | ||
use App\Infrastructure\Persistence\User\InMemoryUserRepository; | ||
use DI\ContainerBuilder; | ||
|
||
return function (ContainerBuilder $containerBuilder) { | ||
// Here we map our UserRepository interface to its in memory implementation | ||
$containerBuilder->addDefinitions([ | ||
UserRepository::class => \DI\autowire(InMemoryUserRepository::class), | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use App\Application\Actions\User\ListUsersAction; | ||
use App\Application\Actions\User\ViewUserAction; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Slim\App; | ||
use Slim\Interfaces\RouteCollectorProxyInterface as Group; | ||
|
||
return function (App $app) { | ||
$app->get('/', function (Request $request, Response $response) { | ||
$response->getBody()->write('Hello world!'); | ||
return $response; | ||
}); | ||
|
||
$app->group('/users', function (Group $group) { | ||
$group->get('', ListUsersAction::class); | ||
$group->get('/{id}', ViewUserAction::class); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use DI\ContainerBuilder; | ||
use Monolog\Logger; | ||
|
||
return function (ContainerBuilder $containerBuilder) { | ||
// Global Settings Object | ||
$containerBuilder->addDefinitions([ | ||
'settings' => [ | ||
'displayErrorDetails' => true, // Should be set to false in production | ||
'logger' => [ | ||
'name' => 'slim-app', | ||
'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log', | ||
'level' => Logger::DEBUG, | ||
], | ||
], | ||
'commands' => [ | ||
'Example' => \App\Application\Actions\Cli\ExampleCliAction::class, | ||
'ExampleWithoutConstructor' => \App\Application\Actions\Cli\ExampleWithoutConstructorCliAction::class | ||
] | ||
]); | ||
}; |
Oops, something went wrong.