readd implementation folder
This commit is contained in:
parent
7ff078b16f
commit
a4f171b98c
80 changed files with 8471 additions and 0 deletions
46
implementation/05/composer.json
Normal file
46
implementation/05/composer.json
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"name": "lubiana/no-framework",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Lubiana\\NoFramework\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "example",
|
||||
"email": "test@example.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"filp/whoops": "^2.14",
|
||||
"laminas/laminas-diactoros": "^2.11"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.6",
|
||||
"symfony/var-dumper": "^6.0",
|
||||
"slevomat/coding-standard": "^7.2",
|
||||
"symplify/easy-coding-standard": "^10.2",
|
||||
"rector/rector": "^0.12.23",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan-strict-rules": "^1.2",
|
||||
"thecodingmachine/phpstan-strict-rules": "^1.0"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"phpstan/extension-installer": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"serve": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"php -S 0.0.0.0:1235 -t public"
|
||||
],
|
||||
"phpstan": "./vendor/bin/phpstan analyze",
|
||||
"baseline": "./vendor/bin/phpstan analyze --generate-baseline",
|
||||
"check": "./vendor/bin/ecs",
|
||||
"fix": "./vendor/bin/ecs --fix",
|
||||
"rector": "./vendor/bin/rector process"
|
||||
}
|
||||
}
|
1079
implementation/05/composer.lock
generated
Normal file
1079
implementation/05/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
89
implementation/05/ecs.php
Normal file
89
implementation/05/ecs.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
|
||||
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
|
||||
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
|
||||
use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff;
|
||||
use SlevomatCodingStandard\Sniffs\ControlStructures\NewWithoutParenthesesSniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\MultipleUsesPerLineSniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
|
||||
use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff;
|
||||
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
|
||||
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
|
||||
use Symplify\EasyCodingStandard\Config\ECSConfig;
|
||||
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
|
||||
|
||||
return static function (ECSConfig $config): void {
|
||||
$config->parallel();
|
||||
$config->paths([__DIR__ . '/src', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']);
|
||||
$config->skip([BlankLineAfterOpeningTagFixer::class, OrderedImportsFixer::class, NewWithBracesFixer::class]);
|
||||
|
||||
$config->sets([
|
||||
SetList::PSR_12,
|
||||
SetList::STRICT,
|
||||
SetList::ARRAY,
|
||||
SetList::SPACES,
|
||||
SetList::DOCBLOCK,
|
||||
SetList::CLEAN_CODE,
|
||||
SetList::COMMON,
|
||||
SetList::COMMENTS,
|
||||
SetList::NAMESPACES,
|
||||
SetList::SYMPLIFY,
|
||||
SetList::CONTROL_STRUCTURES,
|
||||
]);
|
||||
|
||||
// force visibility declaration on class constants
|
||||
$config->ruleWithConfiguration(ClassConstantVisibilitySniff::class, [
|
||||
'fixable' => true,
|
||||
]);
|
||||
|
||||
// sort all use statements
|
||||
$config->rules([
|
||||
AlphabeticallySortedUsesSniff::class,
|
||||
DisallowGroupUseSniff::class,
|
||||
MultipleUsesPerLineSniff::class,
|
||||
NamespaceSpacingSniff::class,
|
||||
]);
|
||||
|
||||
// import all namespaces, and event php core functions and classes
|
||||
$config->ruleWithConfiguration(
|
||||
ReferenceUsedNamesOnlySniff::class,
|
||||
[
|
||||
'allowFallbackGlobalConstants' => false,
|
||||
'allowFallbackGlobalFunctions' => false,
|
||||
'allowFullyQualifiedGlobalClasses' => false,
|
||||
'allowFullyQualifiedGlobalConstants' => false,
|
||||
'allowFullyQualifiedGlobalFunctions' => false,
|
||||
'allowFullyQualifiedNameForCollidingClasses' => true,
|
||||
'allowFullyQualifiedNameForCollidingConstants' => true,
|
||||
'allowFullyQualifiedNameForCollidingFunctions' => true,
|
||||
'searchAnnotations' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// define newlines between use statements
|
||||
$config->ruleWithConfiguration(UseSpacingSniff::class, [
|
||||
'linesCountBeforeFirstUse' => 1,
|
||||
'linesCountBetweenUseTypes' => 1,
|
||||
'linesCountAfterLastUse' => 1,
|
||||
]);
|
||||
|
||||
// strict types declaration should be on same line as opening tag
|
||||
$config->ruleWithConfiguration(DeclareStrictTypesSniff::class, [
|
||||
'declareOnFirstLine' => true,
|
||||
'spacesCountAroundEqualsSign' => 0,
|
||||
]);
|
||||
|
||||
// disallow ?Foo typehint in favor of Foo|null
|
||||
$config->ruleWithConfiguration(UnionTypeHintFormatSniff::class, [
|
||||
'withSpaces' => 'no',
|
||||
'shortNullable' => 'no',
|
||||
'nullPosition' => 'last',
|
||||
]);
|
||||
|
||||
// Remove useless parentheses in new statements
|
||||
$config->rule(NewWithoutParenthesesSniff::class);
|
||||
};
|
6
implementation/05/phpstan-baseline.neon
Normal file
6
implementation/05/phpstan-baseline.neon
Normal file
|
@ -0,0 +1,6 @@
|
|||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
|
||||
count: 1
|
||||
path: src/Bootstrap.php
|
7
implementation/05/phpstan.neon
Normal file
7
implementation/05/phpstan.neon
Normal file
|
@ -0,0 +1,7 @@
|
|||
includes:
|
||||
- phpstan-baseline.neon
|
||||
|
||||
parameters:
|
||||
level: max
|
||||
paths:
|
||||
- src
|
BIN
implementation/05/public/favicon.ico
Normal file
BIN
implementation/05/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
3
implementation/05/public/index.php
Normal file
3
implementation/05/public/index.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../src/Bootstrap.php';
|
11
implementation/05/rector.php
Normal file
11
implementation/05/rector.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/rector.php', __DIR__ . '/ecs.php']);
|
||||
$rectorConfig->importNames();
|
||||
|
||||
$rectorConfig->sets([LevelSetList::UP_TO_PHP_81]);
|
||||
};
|
63
implementation/05/src/Bootstrap.php
Normal file
63
implementation/05/src/Bootstrap.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework;
|
||||
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Throwable;
|
||||
use Whoops\Handler\PrettyPageHandler;
|
||||
use Whoops\Run;
|
||||
|
||||
use function error_log;
|
||||
use function error_reporting;
|
||||
use function getenv;
|
||||
use function header;
|
||||
use function sprintf;
|
||||
use function strtolower;
|
||||
|
||||
use const E_ALL;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$environment = getenv('ENVIRONMENT') ?: 'dev';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$whoops = new Run;
|
||||
|
||||
if ($environment === 'dev') {
|
||||
$whoops->pushHandler(new PrettyPageHandler);
|
||||
} else {
|
||||
$whoops->pushHandler(function (Throwable $t) {
|
||||
error_log('ERROR: ' . $t->getMessage(), $t->getCode());
|
||||
echo 'Oooopsie';
|
||||
});
|
||||
}
|
||||
|
||||
$whoops->register();
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals();
|
||||
$response = new Response;
|
||||
$response->getBody()
|
||||
->write('Hello World! ');
|
||||
$response->getBody()
|
||||
->write('The Uri is: ' . $request->getUri()->getPath());
|
||||
|
||||
foreach ($response->getHeaders() as $name => $values) {
|
||||
$first = strtolower($name) !== 'set-cookie';
|
||||
foreach ($values as $value) {
|
||||
$header = sprintf('%s: %s', $name, $value);
|
||||
header($header, $first);
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
|
||||
$statusLine = sprintf(
|
||||
'HTTP/%s %s %s',
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase()
|
||||
);
|
||||
header($statusLine, true, $response->getStatusCode());
|
||||
|
||||
echo $response->getBody();
|
Loading…
Add table
Add a link
Reference in a new issue