You've already forked Php-Template
Compare commits
3 Commits
v1.8.0
...
18a182f3cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
18a182f3cd
|
|||
|
373035d2cc
|
|||
|
92623941af
|
@@ -1,83 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEFzCCA52gAwIBAgIURfvF11Q9R3Ue38Tr0BzIoUe0TKQwCgYIKoZIzj0EAwMw
|
||||
MDEuMCwGA1UEAxMlU2l0ZXdvcnggSW50ZXJtZWRpYXRlIEVDMzg0IEF1dGhvcml0
|
||||
eTAeFw0yNTEyMDQxNjM1NTFaFw0yNjEyMDQxNjM2MjFaMHExCzAJBgNVBAYTAlVT
|
||||
MREwDwYDVQQIEwhWaXJnaW5pYTEVMBMGA1UEBxMMUHVyY2VsbHZpbGxlMSQwIgYD
|
||||
VQQKExtTaXRld29yeCBQcm9mZXNzaW9uYWxzLCBMTEMxEjAQBgNVBAMTCWxvY2Fs
|
||||
aG9zdDB2MBAGByqGSM49AgEGBSuBBAAiA2IABM+jXangYCOi01IMblAXJ6iFZE4v
|
||||
SBBOZKNQCwGz8kKi5jyXtVwz6U26DMlBSK+InhhOFQlCRcP9ow8LtlQdaY2XnGKr
|
||||
3X3zxdUZJVhLi/wog+I4igU3+xuyn1E/BgEZx6OCAjUwggIxMA4GA1UdDwEB/wQE
|
||||
AwIHgDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQW
|
||||
BBRAtanjiWMYAdpCCz0rEkyqf691bzAfBgNVHSMEGDAWgBQYBC15lPoGGGxbmwqY
|
||||
MWL7jjI6azBJBggrBgEFBQcBAQQ9MDswOQYIKwYBBQUHMAGGLWh0dHBzOi8vdmF1
|
||||
bHQuc2l0ZXdvcnhwcm8uY29tL3YxL3N3eF9pbnQvb2NzcDAaBgNVHREEEzARggls
|
||||
b2NhbGhvc3SHBH8AAAEwHAYDVR0gBBUwEzAIBgZngQwBAgIwBwYFZ4EMAQEwggE1
|
||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SmMJIx
|
||||
B+dgJDh7ql7ruZqjMj+kePjM9Mm+M5pDZ6vrEtgiR2yQj/IE+LoQh/bxFHpFkIK8
|
||||
I6AWoxABAvLZB+KHl1ufR5yOauJG2+SQRuzHNZvkAcdjmwpgfxcsB2mY7o0RbGmZ
|
||||
VWm97P4P9iJhje/W4C0cGwVY5wRAMAg6SI1BpcW7YghB14UrKaxpEzHCdZIeeT94
|
||||
GYzN2XNSSGW3s1anFedd5PQyRM7PlJIcloLYrqyWW6M7OwWnMXA=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,6 +0,0 @@
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MIGkAgEBBDBrpJYaCMqgu490fpZoIphGVspE33v3JwyD9B55HwSX/jykySs9NTOv
|
||||
68YndzE9LNCgBwYFK4EEACKhZANiAATPo12p4GAjotNSDG5QFyeohWROL0gQTmSj
|
||||
UAsBs/JCouY8l7VcM+lNugzJQUiviJ4YThUJQkXD/aMPC7ZUHWmNl5xiq91988XV
|
||||
GSVYS4v8KIPiOIoFN/sbsp9RPwYBGcc=
|
||||
-----END EC PRIVATE KEY-----
|
||||
@@ -1,14 +0,0 @@
|
||||
tls:
|
||||
stores:
|
||||
default:
|
||||
defaultCertificate:
|
||||
certFile: /etc/ssl/localhost.crt
|
||||
keyFile: /etc/ssl/localhost.key
|
||||
|
||||
options:
|
||||
default:
|
||||
minVersion: VersionTLS13
|
||||
preferServerCipherSuites: true
|
||||
|
||||
mintls13:
|
||||
minVersion: VersionTLS13
|
||||
7
.rr.yaml
7
.rr.yaml
@@ -11,9 +11,12 @@ grpc:
|
||||
pool:
|
||||
command: "php grpc-worker.php"
|
||||
num_workers: ${GRPC_WORKERS:-4}
|
||||
debug: ${DEBUG:-false}
|
||||
reflection: ${GRPC_REFLECTION:-true}
|
||||
allocate_timeout: 5s
|
||||
reset_timeout: 5s
|
||||
destroy_timeout: 5s
|
||||
stream_timeout: 5s
|
||||
reflection: ${GRPC_REFLECTION:-true}
|
||||
health_check: ${GRPC_HEALTH_CHECK:-true}
|
||||
proto:
|
||||
- "protos/example.proto"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name=".dev: Compose Deployment" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
|
||||
<configuration default="false" name=" Compose Deployment" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
|
||||
<deployment type="docker-compose.yml">
|
||||
<settings>
|
||||
<option name="sourceFilePath" value=".dev/docker-compose.yml" />
|
||||
<option name="sourceFilePath" value="docker-compose.yml" />
|
||||
</settings>
|
||||
</deployment>
|
||||
<method v="2" />
|
||||
|
||||
17
Dockerfile
17
Dockerfile
@@ -26,7 +26,6 @@ RUN if [ "$KAFKA_ENABLED" -eq 1 ] ; then \
|
||||
echo "Kafka support enabled" ; \
|
||||
apk add autoconf g++ librdkafka-dev make --no-cache ; \
|
||||
pecl install rdkafka && docker-php-ext-enable rdkafka ; \
|
||||
apk del autoconf g++ make ; \
|
||||
else \
|
||||
echo "Kafka support disabled" ; \
|
||||
exit 0 ; \
|
||||
@@ -44,17 +43,11 @@ COPY --from=library /app/vendor /app/vendor
|
||||
# Copy the RoadRunner configuration file and source
|
||||
ADD src src/
|
||||
ADD generated generated/
|
||||
ADD protos protos/
|
||||
ADD server.php cli.php grpc-worker.php .rr.yaml config.php ./
|
||||
ADD server.php .
|
||||
ADD .rr.yaml .
|
||||
ADD config.php .
|
||||
|
||||
EXPOSE 9501 9001
|
||||
|
||||
RUN addgroup -g 1000 appuser && adduser -D -u 1000 -G appuser appuser && chown -R appuser:appuser /app
|
||||
USER appuser
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
|
||||
CMD curl -f http://localhost:9501/healthz || exit 1
|
||||
EXPOSE 9501
|
||||
|
||||
# Entrypoint command to run the RoadRunner server with the specified configuration
|
||||
ENTRYPOINT ["rr", "serve"]
|
||||
CMD ["-c", ".rr.yaml", "-s"]
|
||||
ENTRYPOINT ["rr", "serve", "-c", ".rr.yaml", "-s"]
|
||||
139
README.md
139
README.md
@@ -2,132 +2,55 @@
|
||||
|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
This is a PHP project template that provides a structured development environment using Docker Compose and Make.
|
||||
It includes tools for code quality, testing, dependency management, and gRPC support.
|
||||
|
||||
## Dev Environment
|
||||
|
||||
This project uses Docker Compose and Make to manage the development environment. The `makefile` provides convenient
|
||||
commands for common development tasks.
|
||||
### Prerequisites
|
||||
- Docker
|
||||
- Docker Compose
|
||||
|
||||
## Prerequisites
|
||||
### migrations
|
||||
|
||||
- Docker and Docker Compose
|
||||
- Make
|
||||
- protoc (Protocol Buffers compiler) - for gRPC code generation
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Install PHP dependencies
|
||||
make composer-install
|
||||
|
||||
# Start the development container
|
||||
make start
|
||||
|
||||
# Run the application server
|
||||
make run
|
||||
create a new migration
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/migrate:v4.18.3 create -ext sql -dir /app/db/migrations -seq create_users_table
|
||||
```
|
||||
|
||||
## Available Commands
|
||||
|
||||
### Container Management
|
||||
|
||||
- `make start` - Start the development runtime container
|
||||
- `make stop` - Stop and remove all containers
|
||||
- `make restart` - Restart the development container
|
||||
- `make rebuild` - Rebuild containers (use after Dockerfile changes)
|
||||
- `make sh` - Open a shell in the development container
|
||||
- `make ps` - Show running containers
|
||||
|
||||
### Application
|
||||
|
||||
- `make run` - Run the application server (RoadRunner)
|
||||
- `make migrate` - Run database migrations
|
||||
|
||||
### Composer & Dependencies
|
||||
|
||||
- `make composer-install` - Install PHP dependencies
|
||||
- `make composer-update` - Update PHP dependencies
|
||||
- `make composer-require package=vendor/package` - Add a new dependency
|
||||
- `make composer-require-dev package=vendor/package` - Add a new dev dependency
|
||||
|
||||
### Code Quality
|
||||
|
||||
- `make lint` - Run linters (phpcs and phpstan)
|
||||
- `make fmt` - Format code with php-cs-fixer
|
||||
- `make test` - Run the test suite (phpunit)
|
||||
- `make license-check` - Check license headers in source files
|
||||
|
||||
### Debugging & Coverage
|
||||
|
||||
- `make enable-debug` - Enable Xdebug for debugging
|
||||
- `make enable-coverage` - Enable PCOV for code coverage
|
||||
|
||||
### gRPC
|
||||
|
||||
- `make protoc` - Generate PHP gRPC code from `.proto` files
|
||||
|
||||
### CI Workflow
|
||||
|
||||
- `make ci` - Run the full CI pipeline locally (install, license check, lint, test)
|
||||
|
||||
### Help
|
||||
|
||||
- `make help` - Show all available commands with descriptions
|
||||
|
||||
## Common Workflows
|
||||
|
||||
### Starting Development
|
||||
|
||||
```bash
|
||||
make composer-install
|
||||
make start
|
||||
make run
|
||||
```text
|
||||
postgres://siteworxpro:password@localhost:5432/siteworxpro?sslmode=disable
|
||||
```
|
||||
|
||||
### Adding a New Package
|
||||
|
||||
```bash
|
||||
make composer-require package=vendor/package-name
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/migrate:v4.18.3 -database "postgres://siteworxpro:password@localhost:5432/siteworxpro?sslmode=disable" -path /app/db/migrations up
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
make test
|
||||
### Starting the Runtime
|
||||
```shell
|
||||
docker-compose up -d
|
||||
```
|
||||
### Start the server
|
||||
```shell
|
||||
docker exec -it template-dev-runtime-1 rr serve
|
||||
```
|
||||
|
||||
### Code Quality Check
|
||||
You can access the api at `http://localhost:9501/`
|
||||
|
||||
```bash
|
||||
make lint
|
||||
make fmt
|
||||
### Xdebug
|
||||
|
||||
xdebug needs to be built into the container before it will work
|
||||
```shell
|
||||
docker exec -it php-template-composer-runtime-1 bin/xdebug.sh
|
||||
```
|
||||
|
||||
### Debugging
|
||||
|
||||
```bash
|
||||
make enable-debug
|
||||
make run
|
||||
### Install the dependencies
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/composer install --ignore-platform-reqs
|
||||
```
|
||||
|
||||
## Notes
|
||||
### Running all tests
|
||||
```shell
|
||||
docker run --rm -v $(PWD):/app siteworxpro/composer run tests:all
|
||||
```
|
||||
|
||||
- All commands run inside Docker containers, ensuring a consistent environment
|
||||
- The development runtime uses RoadRunner as the application server
|
||||
- Composer commands run in a separate `composer-runtime` container
|
||||
- Database migrations run in a dedicated `migration-container`
|
||||
|
||||
## Additional Information
|
||||
|
||||
### Accessing Services
|
||||
|
||||
- You can access the api at [https://localhost](https://localhost)
|
||||
- Traefik dashboard is at [https://127.0.0.1/dashboard/](https://127.0.0.1/dashboard/)
|
||||
- the grpc server is at [tcp://localhost:9001](tcp://localhost:9001)
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ return [
|
||||
*/
|
||||
'server' => [
|
||||
'port' => Env::get('HTTP_PORT', 9501, 'int'),
|
||||
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
|
||||
],
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,6 @@ volumes:
|
||||
services:
|
||||
|
||||
traefik:
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.traefik.entrypoints=web-secure"
|
||||
- "traefik.http.routers.traefik.rule=Host(`127.0.0.1`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
|
||||
- "traefik.http.routers.traefik.tls=true"
|
||||
- "traefik.http.routers.traefik.service=api@internal"
|
||||
image: traefik:latest
|
||||
container_name: traefik
|
||||
healthcheck:
|
||||
@@ -21,20 +15,15 @@ services:
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- "9001:9001"
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
- "./ssl:/etc/ssl"
|
||||
restart: always
|
||||
command:
|
||||
- "--providers.docker=true"
|
||||
- "--api.insecure=true"
|
||||
- "--ping"
|
||||
- "--providers.file.filename=/etc/ssl/traefik.yml"
|
||||
- "--providers.docker.exposedByDefault=false"
|
||||
- "--entrypoints.web.address=:80"
|
||||
- "--entrypoints.web-secure.address=:443"
|
||||
- "--entrypoints.grpc.address=:9001"
|
||||
- "--accesslog=true"
|
||||
- "--entrypoints.web.http.redirections.entryPoint.to=web-secure"
|
||||
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
|
||||
@@ -42,7 +31,7 @@ services:
|
||||
|
||||
composer-runtime:
|
||||
volumes:
|
||||
- ..:/app
|
||||
- .:/app
|
||||
image: siteworxpro/composer
|
||||
entrypoint: "/bin/sh -c 'while true; do sleep 30; done;'"
|
||||
environment:
|
||||
@@ -64,8 +53,8 @@ services:
|
||||
|
||||
migration-container:
|
||||
volumes:
|
||||
- ../db/migrations:/app/db/migrations
|
||||
- ../bin:/app/bin
|
||||
- ./db/migrations:/app/db/migrations
|
||||
- ./bin:/app/bin
|
||||
image: siteworxpro/migrate:v4.18.3
|
||||
working_dir: /app
|
||||
# entrypoint: "/bin/sh -c 'while true; do sleep 30; done;'"
|
||||
@@ -90,19 +79,12 @@ services:
|
||||
- "traefik.http.services.api.loadbalancer.healthcheck.path=/healthz"
|
||||
- "traefik.http.services.api.loadbalancer.healthcheck.interval=5s"
|
||||
- "traefik.http.services.api.loadbalancer.healthcheck.timeout=60s"
|
||||
- "traefik.tcp.services.api.loadbalancer.server.port=9001"
|
||||
- "traefik.http.services.api.loadbalancer.server.port=9501"
|
||||
- "traefik.tcp.routers.grpc.entrypoints=grpc"
|
||||
- "traefik.tcp.routers.grpc.rule=HostSNI(`localhost`) || HostSNI(`127.0.0.1`)"
|
||||
- "traefik.tcp.routers.grpc.tls=true"
|
||||
- "traefik.tcp.routers.grpc.service=api"
|
||||
container_name: dev-runtime
|
||||
volumes:
|
||||
- ..:/app
|
||||
- .:/app
|
||||
build:
|
||||
args:
|
||||
KAFKA_ENABLED: "1"
|
||||
context: ..
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
entrypoint: "/bin/sh -c 'while true; do sleep 30; done;'"
|
||||
depends_on:
|
||||
@@ -121,7 +103,6 @@ services:
|
||||
QUEUE_BROKER: redis
|
||||
PHP_IDE_CONFIG: serverName=localhost
|
||||
WORKERS: 1
|
||||
GRPC_WORKERS: 1
|
||||
DEBUG: 1
|
||||
REDIS_HOST: redis
|
||||
DB_HOST: postgres
|
||||
@@ -6,7 +6,7 @@ require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
try {
|
||||
$server = new Grpc();
|
||||
exit($server->start());
|
||||
$server->start();
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
|
||||
|
||||
76
makefile
76
makefile
@@ -2,11 +2,8 @@
|
||||
SHELL := /bin/sh
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
# Docker Compose file
|
||||
COMPOSE_FILE := -f .dev/docker-compose.yml
|
||||
|
||||
# Reusable vars
|
||||
DOCKER := docker compose $(COMPOSE_FILE)
|
||||
DOCKER := docker compose
|
||||
COMPOSER_RUNTIME := composer-runtime
|
||||
DEV_RUNTIME := dev-runtime
|
||||
MIGRATION_CONTAINER := migration-container
|
||||
@@ -15,37 +12,25 @@ PROTOC_GEN_DIR := ./protoc-gen-php-grpc-2025.1.5-darwin-arm64
|
||||
PROTOC_GEN := $(PROTOC_GEN_DIR)/protoc-gen-php-grpc
|
||||
PROTOC_URL := https://github.com/roadrunner-server/roadrunner/releases/download/v2025.1.5/protoc-gen-php-grpc-2025.1.5-darwin-arm64.tar.gz
|
||||
|
||||
DEV := $(DOCKER) exec $(DEV_RUNTIME) sh -c
|
||||
COMPOSER := $(DOCKER) exec $(COMPOSER_RUNTIME) sh -c
|
||||
DEV := $(DOCKER) exec $(DEV_RUNTIME) sh -c
|
||||
|
||||
# Colors
|
||||
GREEN := \033[32m
|
||||
YELLOW := \033[33m
|
||||
RESET := \033[0m
|
||||
|
||||
# Fancy emoji
|
||||
SPARK := ✨
|
||||
ROCKET := 🚀
|
||||
WARN := ⚠️
|
||||
MAGNIFY := 🔍
|
||||
BUG := 🐞
|
||||
COMPOSE := 🐳
|
||||
TRASH := 🧹
|
||||
PROTO := 🧩
|
||||
CHECK := ✅
|
||||
CROSS := ❌
|
||||
|
||||
# Align width for help display
|
||||
HELP_COL_WIDTH := 26
|
||||
|
||||
# Help: auto-generate from targets with "##" comments
|
||||
help: ## Show this help
|
||||
@echo "$(SPARK) Available commands:"
|
||||
@echo "Available commands:"
|
||||
@awk -F':|##' '/^[a-zA-Z0-9._-]+:.*##/ {printf " %-$(HELP_COL_WIDTH)s - %s\n", $$1, $$3}' $(MAKEFILE_LIST) | sort
|
||||
|
||||
start: ## Start the development runtime container
|
||||
@printf "$(GREEN)$(ROCKET) Starting $(DEV_RUNTIME)$(RESET)\n"
|
||||
$(DOCKER) up $(DEV_RUNTIME) -d --no-recreate
|
||||
@printf "$(GREEN)Starting $(DEV_RUNTIME)$(RESET)\n"
|
||||
$(DOCKER) up $(DEV_RUNTIME) -d --no-recreate
|
||||
|
||||
sh: ## Open a shell in the development runtime container
|
||||
@$(MAKE) start
|
||||
@@ -56,7 +41,7 @@ run: ## Run the application server in the development runtime container
|
||||
$(DEV) "rr serve"
|
||||
|
||||
stop: ## Stop and remove the development runtime container
|
||||
@printf "$(YELLOW)$(WARN) Stopping all containers$(RESET)\n"
|
||||
@printf "$(YELLOW)Stopping all containers$(RESET)\n"
|
||||
$(DOCKER) down
|
||||
|
||||
restart: ## Restart dev container (stop + start)
|
||||
@@ -64,11 +49,9 @@ restart: ## Restart dev container (stop + start)
|
||||
@$(MAKE) start
|
||||
|
||||
rebuild: ## Rebuild containers (useful after Dockerfile changes)
|
||||
@printf "$(YELLOW)$(SPARK) Rebuilding containers$(RESET)\n"
|
||||
@$(MAKE) stop
|
||||
@printf "$(YELLOW)$(TRASH) Deleting all Docker resources$(RESET)\n"
|
||||
docker system prune --all --volumes --force
|
||||
@$(MAKE) start
|
||||
@printf "$(YELLOW)Rebuilding containers$(RESET)\n"
|
||||
$(DOCKER) build
|
||||
$(DOCKER) up --force-recreate --build -d
|
||||
|
||||
ps: ## Show docker compose ps
|
||||
$(DOCKER) ps
|
||||
@@ -78,85 +61,60 @@ migrate: ## Run database migrations in the migration container
|
||||
|
||||
# Composer helpers
|
||||
composer-install: ## Install PHP dependencies in the composer runtime container
|
||||
@printf "$(COMPOSE) $(GREEN)Installing PHP dependencies in $(COMPOSER_RUNTIME)$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer install --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs"
|
||||
|
||||
composer-require: ## Require a PHP package in the composer runtime container (usage: make composer-require package=vendor/package)
|
||||
ifndef package
|
||||
$(error package variable is required: make composer-require package=vendor/package)
|
||||
endif
|
||||
@printf "$(COMPOSE) $(MAGNIFY) Requiring package $(package) in $(COMPOSER_RUNTIME)$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer require $(package) --ignore-platform-reqs"
|
||||
|
||||
composer-require-dev: ## Require a PHP package as dev in the composer runtime container (usage: make composer-require-dev package=vendor/package)
|
||||
ifndef package
|
||||
$(error package variable is required: make composer-require-dev package=vendor/package)
|
||||
endif
|
||||
@printf "$(COMPOSE) $(MAGNIFY) Requiring dev package $(package) in $(COMPOSER_RUNTIME)$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer require --dev $(package) --ignore-platform-reqs"
|
||||
|
||||
composer-update: ## Update PHP dependencies in the composer runtime container
|
||||
@printf "$(COMPOSE) $(MAGNIFY) Updating PHP dependencies$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer update --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs"
|
||||
|
||||
enable-debug: ## Enable Xdebug in the development runtime container
|
||||
@$(DOCKER) up $(DEV_RUNTIME) -d --no-recreate
|
||||
@printf "$(GREEN)$(BUG) Enabling Xdebug in $(DEV_RUNTIME)$(RESET)\n"
|
||||
@$(MAKE) start
|
||||
$(DEV) "bin/xdebug.sh"
|
||||
|
||||
enable-coverage: ## Enable PCOV code coverage in the composer runtime container
|
||||
@printf "$(GREEN)$(MAGNIFY) Enabling PCOV in $(COMPOSER_RUNTIME)$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
@$(MAKE) start
|
||||
$(COMPOSER) "bin/pcov.sh"
|
||||
|
||||
protoc: ## Generate PHP gRPC code from .proto files
|
||||
@printf "$(PROTO) $(GREEN)Setting up protoc-gen-php-grpc plugin$(RESET)\n"
|
||||
@printf "$(GREEN)Setting up protoc-gen-php-grpc plugin$(RESET)\n"
|
||||
@curl -LOs $(PROTOC_URL)
|
||||
@tar -xzf protoc-gen-php-grpc-2025.1.5-darwin-arm64.tar.gz
|
||||
@printf "$(PROTO) $(GREEN)Generating PHP gRPC code from .proto files$(RESET)\n"
|
||||
@printf "$(GREEN)Generating PHP gRPC code from .proto files$(RESET)\n"
|
||||
@protoc --plugin=./protoc-gen-php-grpc-2025.1.5-darwin-arm64/protoc-gen-php-grpc \
|
||||
--php_out=./generated \
|
||||
--php-grpc_out=./generated \
|
||||
protos/example.proto
|
||||
@printf "$(TRASH) $(GREEN)Cleaning up protoc-gen-php-grpc plugin files$(RESET)\n"
|
||||
@printf "$(GREEN)Cleaning up protoc-gen-php-grpc plugin files$(RESET)\n"
|
||||
@rm -rf $(PROTOC_GEN_DIR) protoc-gen-php-grpc-2025.1.5-darwin-arm64.tar.gz
|
||||
|
||||
license-check: ## Check license headers in source files
|
||||
@printf "$(MAGNIFY) $(GREEN)Checking license headers$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer run-script tests:license || true"
|
||||
|
||||
# Developer tasks
|
||||
lint: ## Run linting (phpcs/phpstan) in composer runtime
|
||||
@printf "$(MAGNIFY) $(GREEN)Running linters$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer run-script tests:lint || true"
|
||||
$(COMPOSER) "composer run-script tests:phpstan || true"
|
||||
|
||||
fmt: ## Format code (php-cs-fixer)
|
||||
@printf "$(MAGNIFY) $(GREEN)Formatting code$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d --no-recreate
|
||||
$(COMPOSER) "composer run-script tests:lint:fix"
|
||||
|
||||
test: ## Run test suite (phpunit)
|
||||
@printf "$(CHECK) $(GREEN)Running unit tests$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d
|
||||
$(COMPOSER) "composer run-script tests:unit || true"
|
||||
|
||||
test-coverage: ## Run test suite with coverage report
|
||||
@printf "$(CHECK) $(GREEN)Running unit tests with coverage report$(RESET)\n"
|
||||
@$(DOCKER) up $(COMPOSER_RUNTIME) -d
|
||||
@$(MAKE) enable-coverage
|
||||
$(COMPOSER) "composer run-script tests:unit:coverage || true"
|
||||
|
||||
# Convenience aliases
|
||||
dev: run ## Alias for start
|
||||
ci: composer-install migrate license-check lint test ## CI-like local flow
|
||||
ci: composer-install test ## CI-like local flow
|
||||
down: stop ## Alias for stop
|
||||
up: start ## Alias for start
|
||||
|
||||
.PONY: help start sh run stop restart rebuild ps migrate composer-install composer-require composer-require-dev composer-update enable-debug enable-coverage protoc license-check lint fmt test test-coverage dev ci down up
|
||||
.PHONY: help start sh run stop restart rebuild ps logs migrate composer-install composer-require composer-require-dev composer-update enable-debug enable-coverage protoc lint fmt test check-lock dev ci
|
||||
11
src/Grpc.php
11
src/Grpc.php
@@ -20,10 +20,6 @@ use Spiral\RoadRunner\Worker;
|
||||
*/
|
||||
class Grpc
|
||||
{
|
||||
private const array SERVICES = [
|
||||
GreeterInterface::class => GreeterHandler::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
@@ -40,13 +36,10 @@ class Grpc
|
||||
public function start(): int
|
||||
{
|
||||
$server = new Server(new Invoker(), [
|
||||
'debug' => Config::get('app.dev_mode'),
|
||||
'debug' => (bool) Config::get('app.debug'),
|
||||
]);
|
||||
|
||||
foreach (self::SERVICES as $interface => $handler) {
|
||||
$server->registerService($interface, new $handler());
|
||||
}
|
||||
|
||||
$server->registerService(GreeterInterface::class, new GreeterHandler());
|
||||
$server->serve(Worker::create());
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user