Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ APP_VERSION=1.0.0

# Environment
# -----------
# Development and debug environment.
# Development environment.
APP_ENV=development
APP_DEBUG=true

# URL
# ---
Expand Down Expand Up @@ -39,4 +38,4 @@ FALLBACK_LOCALE=en
# LOG_CHANNEL: name usually used in Monolog, see file config/container.php, at the ErrorHandlerMiddleware definition.
# LOG_LEVEL: the minimum logging level at which the handler will be triggered, MUST be one of Level::class constant from Monolog.
LOG_CHANNEL=app
LOG_LEVEL=Debug
LOG_LEVEL=Debug
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ composer.phar
### Cache ###
/storage/cache/views/*.php
/storage/cache/logs/*.log
/storage/database.sqlite

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Sometimes, you don't need an overkill solution like [Laravel](https://laravel.com/) or [Symfony](https://symfony.com/).

Borsch is a simple and efficient [PSR-15](https://www.php-fig.org/psr/psr-15/) micro framework made to kick start your
Borsch is a simple, real fast and efficient [PSR-15](https://www.php-fig.org/psr/psr-15/) micro framework made to kick-start your
web app or API development by using the tools you prefer, and provides minimal structure and facilities to ease your
development.

Expand All @@ -22,8 +22,7 @@ It natively features :
* [Router](https://github.com/borschphp/borsch-router)
* [Request Handlers and Middlewares](https://github.com/borschphp/borsch-requesthandler)
* [Environment Variables](https://github.com/vlucas/phpdotenv)
* [Error Handling](https://github.com/borschphp/borsch-skeleton/blob/master/src/Middleware/ErrorHandlerMiddleware.php)
* [Listeners](https://github.com/borschphp/borsch-skeleton/blob/master/src/Listener/MonologListener.php)
* [Error Handling](https://github.com/borschphp/borsch-middlewares/blob/main/src/Middleware/ErrorHandlerMiddleware.php)

Can be enriched with :

Expand All @@ -41,7 +40,7 @@ Via [composer](https://getcomposer.org/) :

## Web servers

Instructions below will start a server on http://0.0.0.0:8080.
Instructions below will start a server on http://0.0.0.0:8080 (or https://localhost if you use FrankenPHP).

### PHP Built-in web server

Expand Down Expand Up @@ -74,6 +73,8 @@ docker run \
-v $PWD:/app \
-p 80:8080 -p 443:443 -p 443:443/udp \
dunglas/frankenphp
# or use the shortcut
composer franken
```

## Documentation
Expand All @@ -89,4 +90,4 @@ Do not hesitate to check [Mezzio](https://docs.mezzio.dev/mezzio/) and [Laravel]

## License

The package is licensed under the MIT license. See [License File](https://github.com/borschphp/borsch-skeleton/blob/master/LICENSE.md) for more information.
The package is licensed under the MIT license. See [License File](https://github.com/borschphp/borsch-skeleton/blob/master/LICENSE.md) for more information.
20 changes: 10 additions & 10 deletions Skeletorfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@

if ($installation_type === 'MINIMAL') {
$skeletor->spin('Removing front handlers', function () use ($skeletor) {
$skeletor->removeFile('src/Handler/HomeHandler.php');
$skeletor->pregReplaceInFile(
'/\s\$app->[\s\S].+/',
'',
'config/routes.php'
);

$skeletor->removeFile('src/Application/Handler/HomeHandler.php');
return true;
}, 'Removed front handlers', 'Unable to completely remove front handlers');


/* // For now, it only removes the handlers, not the templates (because used in other container definitions).
$skeletor->spin('Removing template files and configuration', function () use ($skeletor) {
$skeletor->removeFile('config/containers/template.container.php');
$skeletor->pregReplaceInFile(
'/\n[\s\S].+template[\s\S].+;/',
'/\n[\s\S].+TemplateRendererInterface[\s\S].+;/',
'',
'config/container.php'
);
$skeletor->pregReplaceInFile(
'/\$engine->render(\'500.tpl\')/',
'',
'config/container.php'
);
$skeletor->removeFile('storage/views/404.tpl');
$skeletor->removeFile('storage/views/500.tpl');
$skeletor->removeFile('storage/views/home.tpl');
$skeletor->removeFile('storage/views/layout.tpl');
// There is an issue with `Skeletor::removeDirectory(string $filename);` because it internally uses `rmdir`
// which has a parameter named `$path` and not `$filename`.
// Because of the use of `get_defined_vars()`, `rmdir` receives a parameter named `$filename` instead of
Expand All @@ -56,6 +55,7 @@

return true;
}, 'Removing Latte template engine from composer.json', 'Unable to completely remove Latte template engine from composer.json');
*/

$skeletor->spin('Creating environment file', function () use ($skeletor, $app_name) {
if (!$skeletor->exists('.env')) {
Expand Down
9 changes: 0 additions & 9 deletions chef

This file was deleted.

19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
"ext-libxml": "*",
"ext-pdo": "*",
"ext-simplexml": "*",
"borschphp/application": "^2",
"borschphp/middlewares": "^1",
"borschphp/middlewares": "^2",
"borschphp/latte": "^1",
"borschphp/chef": "^1",
"laminas/laminas-diactoros": "^3",
"borschphp/requesthandler": "^2",
"borschphp/container": "^2",
"borschphp/router": "^3.1",
"borschphp/psr7": "^1.0",
"laminas/laminas-db": "^2.20",
"monolog/monolog": "^2 || ^3",
"vlucas/phpdotenv": "^v5.1",
"league/container": "^4",
"zircote/swagger-php": "^5.0",
"laminas/laminas-db": "^2.20",
"debuss-a/problem-details": "^1.0"
},
"require-dev": {
Expand All @@ -43,7 +43,9 @@
},
"autoload": {
"psr-4": {
"App\\": "src/"
"Application\\": "src/Application/",
"Domain\\": "src/Domain/",
"Infrastructure\\": "src/Infrastructure/"
},
"files": [
"bootstrap/defines.inc.php",
Expand All @@ -53,7 +55,7 @@
},
"autoload-dev": {
"psr-4": {
"AppTest\\": "tests/"
"Tests\\": "tests/"
}
},
"config": {
Expand All @@ -62,7 +64,6 @@
}
},
"scripts": {
"pre-install-cmd": "App\\Package\\Installer::install",
"post-create-project-cmd": [
"NiftyCo\\Skeletor\\Runner::execute"
],
Expand Down
24 changes: 0 additions & 24 deletions config/api.php

This file was deleted.

18 changes: 9 additions & 9 deletions config/container.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

use League\Container\{Container, ReflectionContainer};
use Borsch\Container\Container;

$container = new Container();
$container->setCacheByDefault(true);

$container->defaultToShared();
$container->delegate(new ReflectionContainer(true));

(require_once __DIR__.'/containers/app.container.php')($container);
(require_once __DIR__.'/containers/logs.container.php')($container);
(require_once __DIR__.'/containers/pipeline.container.php')($container);
(require_once __DIR__.'/containers/template.container.php')($container);
(require_once __DIR__.'/containers/database.container.php')($container);
(require_once __DIR__ . '/containers/container.handler.php')($container);
(require_once __DIR__ . '/containers/container.middlewares.php')($container);
(require_once __DIR__ . '/containers/container.http.php')($container);
(require_once __DIR__ . '/containers/container.routes.php')($container);
(require_once __DIR__ . '/containers/container.logs.php')($container);
(require_once __DIR__ . '/containers/container.views.php')($container);
(require_once __DIR__ . '/containers/container.database.php')($container);

return $container;
56 changes: 0 additions & 56 deletions config/containers/app.container.php

This file was deleted.

23 changes: 23 additions & 0 deletions config/containers/container.database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Borsch\Container\Container;
use Laminas\Db\Adapter\{Adapter, AdapterInterface};

return static function (Container $container) {

/*
* An adapter for SQLite database.
*
* This adapter uses the `Pdo_Sqlite` driver and connects to an SQLite database file located at
* `storage/database.sqlite`.
*
* It is used by Repositories (in `Infrastructure` namespace) to interact with the SQLite database.
*/
$container
->set(AdapterInterface::class, Adapter::class)
->addParameter([
'driver' => 'Pdo_Sqlite',
'dsn' => 'sqlite:'.storage_path('database.sqlite')
]);

};
76 changes: 76 additions & 0 deletions config/containers/container.handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

use Borsch\Container\Container;
use Borsch\Middleware\{BodyParserMiddleware,
ContentLengthMiddleware,
DispatchMiddleware,
ErrorHandlerMiddleware,
ImplicitHeadMiddleware,
ImplicitOptionsMiddleware,
MethodNotAllowedMiddleware,
NotFoundHandlerMiddleware,
RouteMiddleware,
TrailingSlashMiddleware,
UploadedFilesParserMiddleware};
use Borsch\RequestHandler\{Emitter, RequestHandler, RequestHandlerRunner, RequestHandlerRunnerInterface};
use Borsch\Template\TemplateRendererInterface;
use ProblemDetails\ProblemDetailsMiddleware;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\{ResponseFactoryInterface, ServerRequestInterface};
use Psr\Http\Server\RequestHandlerInterface;

return static function (Container $container) {

/*
* The RequestHandlerRunner is responsible for running the RequestHandler and emit a response.
*
* As parameters, it takes:
* - A RequestHandlerInterface instance that will handle the request
* - An Emitter instance that will emit the response
* - A callable that returns the ServerRequestInterface instance
* - A callable that returns a fallback response in case of an error
*/
$container->set(
RequestHandlerRunnerInterface::class,
static function (
RequestHandlerInterface $handler,
ServerRequestInterface $request,
TemplateRendererInterface $renderer,
ResponseFactoryInterface $factory
) {
return new RequestHandlerRunner(
$handler,
new Emitter(),
static fn() => $request,
static function() use ($renderer, $factory) {
$response = $factory->createResponse(500);
$response->getBody()->write($renderer->render('500.tpl'));

return $response;
}
);
});

/*
* The RequestHandler is responsible for handling the request and returning a response.
*
* It is composed of several middlewares that will be executed in the order they are added (FIFO).
* Predefined middlewares are included to handle common tasks, feel free to add your own.
*/
$container->set(RequestHandlerInterface::class, static function (ContainerInterface $container) {
return (new RequestHandler())
->middleware($container->get(ErrorHandlerMiddleware::class))
->middleware($container->get(ProblemDetailsMiddleware::class))
->middleware($container->get(TrailingSlashMiddleware::class))
->middleware($container->get(ContentLengthMiddleware::class))
->middleware($container->get(RouteMiddleware::class))
->middleware($container->get(ImplicitHeadMiddleware::class))
->middleware($container->get(ImplicitOptionsMiddleware::class))
->middleware($container->get(MethodNotAllowedMiddleware::class))
->middleware($container->get(BodyParserMiddleware::class))
->middleware($container->get(UploadedFilesParserMiddleware::class))
->middleware($container->get(DispatchMiddleware::class))
->middleware($container->get(NotFoundHandlerMiddleware::class));
});

};
Loading