Skip to content

Commit dc76117

Browse files
committed
Merge branch '0.x'
2 parents dd4a1fe + c23f61e commit dc76117

27 files changed

Lines changed: 860 additions & 59 deletions

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.idea
2+
.git
3+
.gitignore
4+
.github
5+
config/parameters.yml
6+
node_modules
7+
tests
8+
vendor
9+
LICENSE
10+
*.md
11+
*.yml
12+
*.yml.dist
13+
*.xml
14+
*.xml.dist

.env.dev.dist

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
COMPOSE_PROJECT_NAME=reactphp_foundation
1212

13+
# developer's uid on the host machine
14+
# id -u
15+
HOST_UID=1000
16+
1317
TIMEZONE=Europe/Moscow
1418
SOURCE_PATH=.
1519
DEPLOYMENT_PATH=/var/www/foundation
@@ -21,9 +25,9 @@ PHP_VERSION=7.4
2125
APP_ENV=dev
2226
APP_SERVER_PORT=6636
2327
# prebuilt image for stack
24-
# see Dockerfile-stack from the 'docker' directory
25-
APP_STACK_IMAGE_NAME=
26-
APP_STACK_IMAGE_VERSION=
28+
# see Dockerfile-standalone from the 'docker' directory
29+
APP_STACK_IMAGE_NAME=127.0.0.1:5000/app
30+
APP_STACK_IMAGE_VERSION=latest
2731

2832
# haproxy
2933
HAPROXY_VERSION=2.2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ docker-compose.stack.yml
77
vendor/
88

99
config/parameters.yml
10+
11+
phpunit.xml

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- No changes yet.
1212

13+
## [0.3.0] - 2020-08-17
14+
### Added
15+
16+
- `Uri\MatcherInterface` and `ArrayMatcher` to map URI path from requests
17+
to the handler's actions (a simplified version of `UrlMatcher` from
18+
[symfony/routing](https://github.com/symfony/routing/blob/v5.1.0/Matcher/UrlMatcher.php)).
19+
- `.dockerignore` to exclude unnecessary/insecure files from the image building context.
20+
- Test suite configuration for [PHPUnit](https://github.com/sebastianbergmann/phpunit).
21+
- "Tests" block and navigation links for README.md.
22+
23+
### Changed
24+
25+
- Container configuration logic has moved from the application entrypoint
26+
to the `YamlConfigurator` shortcut.
27+
- Using HTTP health checks for HAProxy instance (instead of TCP).
28+
29+
### Fixed
30+
31+
- Definition options from `_defaults` node in the `services.yml` are now properly
32+
picked up by all services, not only ones defined in the same file (works if that node
33+
doesn't already exists in the target definition file; revised
34+
`YamlFileLoader` in the `Bridge\Symfony` scope).
35+
- Explicit UIDs and permissions for users within Dockerfiles
36+
(preventing potential access issues during CI checks and other workflows).
37+
1338
## [0.2.0] - 2020-07-20
1439
### Added
1540

@@ -31,6 +56,7 @@ the async socket server and the event loop.
3156
- `ServerInterface` and the `HandlerInterface`, example handler implementation.
3257
- Non-blocking logger (based on [wyrihaximus/react-psr-3-stdio](https://github.com/WyriHaximus/reactphp-psr-3-stdio)).
3358

34-
[Unreleased]: https://github.com/itnelo/reactphp-foundation/compare/0.2.0...0.x
59+
[Unreleased]: https://github.com/itnelo/reactphp-foundation/compare/0.3.0...0.x
60+
[0.3.0]: https://github.com/itnelo/reactphp-foundation/compare/0.2.0..0.3.0
3561
[0.2.0]: https://github.com/itnelo/reactphp-foundation/compare/0.1.0..0.2.0
3662
[0.1.0]: https://github.com/itnelo/reactphp-foundation/releases/tag/0.1.0

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11

22
# ReactPHP Foundation
33

4+
- [What's inside?](#whats-inside)
5+
- [Installation](#installation)
6+
- [Docker Swarm](#docker-swarm)
7+
- [Tests](#tests)
8+
- [See also](#see-also)
9+
- [Changelog](#changelog)
10+
11+
## What's inside?
12+
413
This skeleton for self-sufficient, asynchronous microservice contains:
514

615
- Interfaces
@@ -21,11 +30,16 @@ This skeleton for self-sufficient, asynchronous microservice contains:
2130
It follows strong SOLID design and fully PSR-compatible, built
2231
with PHP 7.4+ features in mind (starting with typed properties).
2332

24-
It is also relatively lightweight and takes benefits
33+
It is also _relatively_ lightweight and takes benefits
2534
from both [Symfony](https://github.com/symfony/symfony) components
2635
and [ReactPHP](https://github.com/reactphp/reactphp)
2736
without raising up a heavy artillery setup.
2837

38+
There are a few deployment configurations
39+
([Docker Compose](https://docs.docker.com/compose) project and
40+
stack for [Docker Swarm](https://docs.docker.com/engine/swarm/key-concepts),
41+
featuring [HAProxy](https://www.haproxy.com) as a load balancer for your code).
42+
2943
## Installation
3044

3145
### Docker Swarm
@@ -130,9 +144,21 @@ use your manager node IP) a rendered page with backend statistics should be avai
130144
To rebalance app replicas between nodes, after one is added or removed, use:
131145

132146
```
147+
# our pc
133148
$ docker service update --force my-service_app
134149
```
135150

151+
## Tests
152+
153+
Apply test suite configuration and run [phpunit](https://github.com/sebastianbergmann/phpunit):
154+
155+
```
156+
$ cp phpunit.xml.dist phpunit.xml
157+
158+
# for docker-compose installation
159+
$ docker-compose run --rm app bin/phpunit
160+
```
161+
136162
## See also
137163

138164
- [driftphp/driftphp](https://github.com/driftphp/driftphp)

bin/app

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,35 @@
1515
declare(strict_types=1);
1616

1717
use Foundation\Application;
18+
use Foundation\Bridge\Symfony\Component\DependencyInjection\Configurator\YamlConfigurator;
1819
use Symfony\Component\Config\FileLocator;
19-
use Symfony\Component\DependencyInjection\ContainerBuilder;
20-
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
21-
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
22-
use Symfony\Component\Dotenv\Dotenv;
23-
use Symfony\Component\Yaml\Yaml;
2420

2521
require_once __DIR__ . '/../vendor/autoload.php';
2622

27-
$envFilePath = __DIR__ . '/../.env';
23+
$parameterFilePath = __DIR__ . '/../config/parameters.yml';
2824

29-
// will populate env variables from env-type files (only if they're not already set).
30-
if (file_exists($envFilePath)) {
31-
(new Dotenv())->loadEnv($envFilePath);
32-
}
33-
34-
$configFilePath = __DIR__ . '/../config/parameters.yml';
35-
36-
if (!file_exists($configFilePath)) {
25+
if (!file_exists($parameterFilePath)) {
3726
throw new RuntimeException("File 'parameters.yml' is missing. Please, put it into the 'config' directory.");
3827
}
3928

40-
$config = Yaml::parseFile($configFilePath);
41-
$parameterBag = new EnvPlaceholderParameterBag($config['parameters']);
42-
43-
$container = new ContainerBuilder($parameterBag);
44-
45-
// loading service definitions.
46-
$definitionLoader = new YamlFileLoader($container, new FileLocator());
47-
$definitionFilePaths = [
48-
__DIR__ . '/../config/services/request_handlers.yml',
49-
__DIR__ . '/../config/services/loggers.yml',
50-
__DIR__ . '/../config/services/shutdown.yml',
51-
__DIR__ . '/../config/services/async/streams.yml',
52-
__DIR__ . '/../config/services/async/server.yml',
53-
__DIR__ . '/../config/services/async/event_loop.yml',
54-
__DIR__ . '/../config/services.yml',
55-
];
56-
57-
foreach ($definitionFilePaths as $definitionFilePath) {
58-
$definitionLoader->load($definitionFilePath);
59-
}
60-
29+
$containerConfigurator = new YamlConfigurator(new FileLocator());
30+
$containerConfigurator->setEnvironmentFilePath(__DIR__ . '/../.env');
31+
$containerConfigurator->setParameterFilePath($parameterFilePath);
32+
$containerConfigurator->setDefinitionFilePaths(
33+
[
34+
__DIR__ . '/../config/services.yml',
35+
__DIR__ . '/../config/services/loggers.yml',
36+
__DIR__ . '/../config/services/async/event_loop.yml',
37+
__DIR__ . '/../config/services/async/server.yml',
38+
__DIR__ . '/../config/services/async/streams.yml',
39+
__DIR__ . '/../config/services/shutdown.yml',
40+
__DIR__ . '/../config/services/request/uri_matcher.yml',
41+
__DIR__ . '/../config/services/request/handler.yml',
42+
]
43+
);
44+
$containerConfigurator->setDefinitionDefaultsFilePath(__DIR__ . '/../config/services.yml');
45+
46+
$container = $containerConfigurator->getContainerBuilder();
6147
// we are starting an async web server with some concurrent code
6248
// so we don't need any container caching logic for this case.
6349
$container->compile(true);

bin/phpunit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../vendor/bin/phpunit

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
],
1515
"autoload": {
1616
"psr-4": {
17-
"Foundation\\": ["src/"]
17+
"Foundation\\": [
18+
"src/"
19+
]
1820
}
1921
},
2022
"autoload-dev": {
2123
"psr-4": {
22-
"Foundation\\Tests\\": "tests/"
24+
"Foundation\\Tests\\": [
25+
"tests/unit"
26+
]
2327
}
2428
},
2529
"minimum-stability": "stable",
@@ -38,6 +42,9 @@
3842
"symfony/yaml": "^5.1",
3943
"wyrihaximus/react-psr-3-stdio": "^2.1"
4044
},
45+
"require-dev": {
46+
"phpunit/phpunit": "^9.2"
47+
},
4148
"config": {
4249
"sort-packages": true
4350
},

config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
services:
3-
# default configuration for services in *this* file
3+
# default configuration will be applied for ALL SERVICES (if not explicitly specified in the target file)
4+
# this behavior is a result of Symfony DI logic revision, see YamlFileLoader from the "Bridge\Symfony" scope.
45
_defaults:
56
# automatically injects dependencies in your services
67
autowire: false

0 commit comments

Comments
 (0)