Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aurimasniekis committed Feb 13, 2019
0 parents commit 0ae071b
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ENV=dev
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/build
/var/
/vendor/
/.php_cs.cache
/.env.local
/.env.local.php
/.env.*.local
.phpunit.result.cache
phpunit.xml
23 changes: 23 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests']);

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(
[
'@Symfony' => true,
'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true],
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
'void_return' => true,
'declare_strict_types' => true,
'yoda_style' => true,
'increment_style' => ['style' => 'post'],
'concat_space' => ['spacing' => 'one'],
]
)
->setFinder($finder)
->setUsingCache(true);

11 changes: 11 additions & 0 deletions .rr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"http": {
"address": "0.0.0.0:8000",
"workers": {
"command": "bin/roadRunnerAgent",
"pool": {
"numWorkers": 4
}
}
}
}
27 changes: 27 additions & 0 deletions bin/roadRunnerAgent
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php

ini_set('display_errors', 'stderr');

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Thruster\RoadRunnerBridge\RoadRunnerBridge;

set_time_limit(0);

require dirname(__DIR__) . '/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

RoadRunnerBridge::createCLI()
->attach($kernel)
->run();
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "thruster/mikro-web-framework",
"type": "project",
"license": "proprietary",
"require": {
"php": ">=7.3",
"thruster/mikro-kernel": "^1.1",
"thruster/road-runner-bridge": "^1.0",
"thruster/sapi-bridge": "^1.0",
"symfony/dotenv": "^4.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2"
},
"autoload": {
"psr-4": {
"App\\": "src"
},
"classmap": [
"src/"
]
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests"
}
},
"scripts": {
"check-style": "php-cs-fixer fix --dry-run --diff --diff-format udiff",
"fix-style": "php-cs-fixer fix"
}
}
20 changes: 20 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

if (false === class_exists(Dotenv::class)) {
throw new RuntimeException(
'Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'
);
}

(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var(
$_SERVER['APP_DEBUG'],
FILTER_VALIDATE_BOOLEAN
) ? '1' : '0';
17 changes: 17 additions & 0 deletions config/container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Psr\Http\Server\RequestHandlerInterface;
use App\RequestHandler;

return function (ContainerConfigurator $container) {
$services = $container->services();

$container = $services
->defaults()
->autoconfigure()
->autowire();

$container->set(RequestHandlerInterface::class, RequestHandler::class)
->alias('request_handler', RequestHandlerInterface::class);
};
20 changes: 20 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Thruster\SapiBridge\SapiBridge;

require dirname(__DIR__) . '/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

Debug::enable();
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

SapiBridge::createFromGlobals()
->attach($kernel)
->run();
16 changes: 16 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App;

use Symfony\Component\Config\Loader\LoaderInterface;
use Thruster\MikroKernel\MikroKernel;

class Kernel extends MikroKernel
{
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$projectDir = $this->getProjectDir();

$loader->load($projectDir . '/config/container.php');
}
}
28 changes: 28 additions & 0 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Thruster\HttpFactory\HttpFactoryInterface;

class RequestHandler implements RequestHandlerInterface
{
/** @var HttpFactoryInterface */
private $httpFactory;

public function __construct(HttpFactoryInterface $httpFactory)
{
$this->httpFactory = $httpFactory;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->httpFactory->response()->createResponse()
->withBody(
$this->httpFactory->stream()->createStream('<h1>Hello World</h1>')
);
}

}
Empty file added tests/.gitkeep
Empty file.

0 comments on commit 0ae071b

Please sign in to comment.