[PHP] Introduce spiral (#1793) · attackgithub/web-frameworks@3a35689 · GitHub
Skip to content

Commit 3a35689

Browse files
authored
[PHP] Introduce spiral (the-benchmarker#1793)
1 parent 828173e commit 3a35689

11 files changed

Lines changed: 190 additions & 3 deletions

File tree

‎.dependabot/config.yml‎

Lines changed: 8 additions & 3 deletions

‎.travis.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ jobs:
456456
language: crystal
457457
env: FRAMEWORK=spider-gazelle
458458
services: docker
459+
- stage: test
460+
script: bash .ci/test.sh
461+
language: crystal
462+
env: FRAMEWORK=spiral
463+
services: docker
459464
- stage: test
460465
script: bash .ci/test.sh
461466
language: crystal

‎php/spiral/.rr.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
http:
2+
address: :3000
3+
workers:
4+
command: "php app.php"

‎php/spiral/Dockerfile‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM php:7.3
2+
3+
RUN apt-get -qy update
4+
5+
WORKDIR /usr/src/app
6+
7+
COPY app app
8+
COPY app.php app.php
9+
COPY .rr.yaml .rr.yaml
10+
COPY composer.json composer.json
11+
12+
# install composer
13+
RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
14+
15+
# php/zip extension is required for composer
16+
RUN apt -y update && apt -y install zlib1g-dev libzip-dev
17+
RUN docker-php-ext-install zip
18+
19+
RUN composer install --no-dev --prefer-dist --classmap-authoritative
20+
RUN composer dumpautoload -o
21+
22+
# dumping autoloader require php/opcache
23+
RUN docker-php-ext-install opcache
24+
25+
# install spiral binary file
26+
RUN vendor/bin/spiral get
27+
28+
# configure
29+
RUN php app.php configure
30+
31+
# run roadrunner
32+
CMD php app.php up > /dev/null 2>&1 && ./spiral serve

‎php/spiral/app.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Spiral Framework.
4+
*
5+
* @license MIT
6+
* @author Anton Titov (Wolfy-J)
7+
*/
8+
declare(strict_types=1);
9+
10+
mb_internal_encoding('UTF-8');
11+
error_reporting(E_ALL | E_STRICT);
12+
ini_set('display_errors', 'stderr');
13+
14+
//Composer
15+
require __DIR__ . '/vendor/autoload.php';
16+
17+
//Initiating shared container, bindings, directories and etc
18+
$app = \App\App::init(['root' => __DIR__]);
19+
20+
if ($app != null) {
21+
$app->serve();
22+
}

‎php/spiral/app/src/App.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Spiral Framework.
4+
*
5+
* @license MIT
6+
* @author Anton Titov (Wolfy-J)
7+
*/
8+
declare(strict_types=1);
9+
10+
namespace App;
11+
12+
use App\Bootloader\RoutesBootloader;
13+
use Spiral\Bootloader;
14+
use Spiral\Framework\Kernel;
15+
use Spiral\Nyholm\Bootloader as Nyholm;
16+
17+
class App extends Kernel
18+
{
19+
/*
20+
* List of components and extensions to be automatically registered
21+
* within system container on application start.
22+
*/
23+
protected const LOAD = [
24+
// HTTP
25+
Nyholm\NyholmBootloader::class,
26+
Bootloader\Http\HttpBootloader::class,
27+
Bootloader\Http\RouterBootloader::class,
28+
29+
// Framework commands
30+
Bootloader\CommandBootloader::class
31+
];
32+
33+
/*
34+
* Application specific services and extensions.
35+
*/
36+
protected const APP = [
37+
RoutesBootloader::class,
38+
];
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Spiral Framework.
4+
*
5+
* @license MIT
6+
* @author Anton Titov (Wolfy-J)
7+
*/
8+
declare(strict_types=1);
9+
10+
namespace App\Bootloader;
11+
12+
use App\Controller\BenchmarkController;
13+
use Spiral\Boot\Bootloader\Bootloader;
14+
use Spiral\Router\Route;
15+
use Spiral\Router\RouterInterface;
16+
use Spiral\Router\Target\Action;
17+
18+
class RoutesBootloader extends Bootloader
19+
{
20+
/**
21+
* @param RouterInterface $router
22+
*/
23+
public function boot(RouterInterface $router)
24+
{
25+
$router->addRoute(
26+
'index',
27+
(new Route('/', new Action(BenchmarkController::class, 'index')))->withVerbs('GET')
28+
);
29+
30+
$router->addRoute(
31+
'benchmark',
32+
new Route('/user[/<id>]', new Action(BenchmarkController::class, 'user'))
33+
);
34+
}
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Spiral Framework.
4+
*
5+
* @license MIT
6+
* @author Anton Titov (Wolfy-J)
7+
*/
8+
declare(strict_types=1);
9+
10+
namespace App\Controller;
11+
12+
use Spiral\Core\Container\SingletonInterface;
13+
14+
class BenchmarkController implements SingletonInterface
15+
{
16+
public function index()
17+
{
18+
return '';
19+
}
20+
21+
public function user($id = null)
22+
{
23+
return (string)$id;
24+
}
25+
}

‎php/spiral/composer.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"require": {
3+
"spiral/framework": "~2.0.0",
4+
"spiral/nyholm-bridge": "*",
5+
"spiral/http": "*",
6+
"spiral/router": "*",
7+
"spiral/console": "*",
8+
"spiral/roadrunner": "^1.4"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"App\\": "app/src/"
13+
}
14+
}
15+
}

‎php/spiral/config.yaml‎

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)