Skip to content

Commit e91faa7

Browse files
authored
Adding Laravel runtime (#16)
* Adding Laravel runtime * Updated readme * Normalize composer
0 parents  commit e91faa7

File tree

12 files changed

+258
-0
lines changed

12 files changed

+258
-0
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [nyholm]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Tobias Nyholm
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Laravel Runtime
2+
3+
A runtime for [Laravel](https://laravel.com/).
4+
5+
## Installation
6+
7+
```
8+
composer require runtime/laravel
9+
```
10+
11+
## Usage
12+
13+
The runtime will register automatically. You may "force" the runtime by defining
14+
the environment variable `APP_RUNTIME` for your application.
15+
16+
```
17+
APP_RUNTIME=Runtime\Laravel\Runtime
18+
```
19+
20+
### Front controller
21+
22+
```php
23+
// public/index.php
24+
25+
use Illuminate\Contracts\Http\Kernel;
26+
27+
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
28+
29+
return function () {
30+
define('LARAVEL_START', microtime(true));
31+
$app = require_once __DIR__ . '/../bootstrap/app.php';
32+
33+
return $app->make(Kernel::class);
34+
};
35+
```
36+
37+
### Artisan
38+
39+
```php
40+
// artisan
41+
42+
use Illuminate\Contracts\Console\Kernel;
43+
44+
require_once __DIR__.'/vendor/autoload_runtime.php';
45+
46+
return function () {
47+
define('LARAVEL_START', microtime(true));
48+
$app = require_once __DIR__.'/bootstrap/app.php';
49+
50+
return $app->make(Kernel::class);
51+
};
52+
53+
```

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "runtime/laravel",
3+
"type": "library",
4+
"description": "Laravel runtime",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Tobias Nyholm",
9+
"email": "tobias.nyholm@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"illuminate/contracts": "^8.33",
14+
"symfony/runtime": "5.x-dev"
15+
},
16+
"require-dev": {
17+
"illuminate/http": "^8.33",
18+
"symfony/console": "^4.4 || ^5.2",
19+
"symfony/phpunit-bridge": "^5.2"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Runtime\\Laravel\\": "src/",
24+
"Symfony\\Runtime\\Illuminate\\Contracts\\": "runtime"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Runtime\\Laravel\\Tests\\": "tests/"
30+
}
31+
},
32+
"minimum-stability": "dev",
33+
"prefer-stable": true
34+
}

phpunit.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="vendor/autoload.php"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
>
10+
<php>
11+
<ini name="error_reporting" value="-1"/>
12+
</php>
13+
<testsuites>
14+
<testsuite name="Test Suite">
15+
<directory>./tests</directory>
16+
<directory suffix=".phpt">./tests/phpt</directory>
17+
</testsuite>
18+
</testsuites>
19+
</phpunit>

runtime/Console/KernelRuntime.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Runtime\Illuminate\Contracts\Console;
4+
5+
use Runtime\Laravel\Runtime;
6+
7+
class KernelRuntime extends Runtime
8+
{
9+
}

runtime/Http/KernelRuntime.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Runtime\Illuminate\Contracts\Http;
4+
5+
use Runtime\Laravel\Runtime;
6+
7+
class KernelRuntime extends Runtime
8+
{
9+
}

src/ConsoleApplicationRunner.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Runtime\Laravel;
4+
5+
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Runtime\RunnerInterface;
9+
10+
/**
11+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
12+
*/
13+
class ConsoleApplicationRunner implements RunnerInterface
14+
{
15+
private $application;
16+
private $input;
17+
private $output;
18+
19+
public function __construct(ConsoleKernel $application, InputInterface $input, OutputInterface $output = null)
20+
{
21+
$this->application = $application;
22+
$this->input = $input;
23+
$this->output = $output;
24+
}
25+
26+
public function run(): int
27+
{
28+
return $this->application->handle($this->input, $this->output);
29+
}
30+
}

src/HttpKernelRunner.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Runtime\Laravel;
4+
5+
use Illuminate\Contracts\Http\Kernel;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\Runtime\RunnerInterface;
8+
9+
class HttpKernelRunner implements RunnerInterface
10+
{
11+
private $kernel;
12+
private $request;
13+
14+
public function __construct(Kernel $kernel, Request $request)
15+
{
16+
$this->kernel = $kernel;
17+
$this->request = $request;
18+
}
19+
20+
public function run(): int
21+
{
22+
$response = $this->kernel->handle($this->request);
23+
$response->send();
24+
25+
$this->kernel->terminate($this->request, $response);
26+
27+
return 0;
28+
}
29+
}

0 commit comments

Comments
 (0)