First draw

This commit is contained in:
Jérémy Munsch 2021-01-29 12:54:43 +01:00
commit f5fdef3755
13 changed files with 1411 additions and 0 deletions

9
.editorconfig Normal file
View file

@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

3
.envDefault Normal file
View file

@ -0,0 +1,3 @@
displayError=true
logErrors=true
logErrorDetails=true

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
vendor
.vscode

24
.htaccess Normal file
View file

@ -0,0 +1,24 @@
# Disable directory browsing
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
# absolute physical path to the directory that contains this htaccess file.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [QSA,L]
</IfModule>

2
app/.htaccess Normal file
View file

@ -0,0 +1,2 @@
Order Allow,Deny
Deny from all

105
app/Kernel.php Normal file
View file

@ -0,0 +1,105 @@
<?php
namespace App;
use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use Slim\Factory\AppFactory;
require_once __DIR__ . '/helpers.php';
class Kernel
{
private static $app;
private static $env;
private static function _build()
{
self::$app = AppFactory::create();
self::loadEnv();
self::loadRoutes();
self::loadMiddlewares();
}
private static function loadRoutes()
{
require_once __DIR__ . '/Routes/web.php';
}
private static function loadMiddlewares()
{
// Add Routing Middleware
self::$app->addRoutingMiddleware();
/**
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = self::$app->addErrorMiddleware(
env('displayError', false),
env('logErrors', false),
env('logErrorDetails', false)
);
}
private static function loadEnv()
{
try {
self::$env = Dotenv::createImmutable(__DIR__ . '/..')->load();
} catch (InvalidPathException $e) {
// no env file present
}
}
public static function app()
{
return self::$app;
}
public static function env(string $key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return $default;
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
// if (Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
// return substr($value, 1, -1);
// }
return $value;
}
public static function run()
{
self::_build();
self::$app->run();
}
}

17
app/Routes/web.php Normal file
View file

@ -0,0 +1,17 @@
<?php
use App\Kernel;
use jucksearm\barcode\Datamatrix;
Kernel::app()->get('/{code}', function ($request, $response, $args) {
$image = @Datamatrix::factory()
->setSize(300)
->setMargin(6)
->setCode($args['code'])->getDatamatrixPngData();
$body = $response->getBody();
$body->write($image);
$response = $response->withHeader("Content-type", 'image/png');
$response = $response->withHeader("Cache-Control", 'no-cache');
$response = $response->withHeader("Last-Modified", gmdate('D, d M Y H:i:s') . ' GMT');
return $response;
});

8
app/helpers.php Normal file
View file

@ -0,0 +1,8 @@
<?php
use App\Kernel;
function env(string $envString, $default = null)
{
return Kernel::env($envString, $default);
}

14
composer.json Normal file
View file

@ -0,0 +1,14 @@
{
"require": {
"slim/slim": "4.*",
"guzzlehttp/psr7": "^1.7",
"http-interop/http-factory-guzzle": "^1.0",
"vlucas/phpdotenv": "^5.3",
"jucksearm/php-barcode": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "app"
}
}
}

1190
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

21
public/.htaccess Normal file
View file

@ -0,0 +1,21 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>

7
public/index.php Normal file
View file

@ -0,0 +1,7 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
use App\Kernel;
Kernel::run();

9
workspace.code-workspace Normal file
View file

@ -0,0 +1,9 @@
{
"name": "PFC Data Matrix Generator",
"folders": [
{
"path": "."
}
],
"settings": {}
}