Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI

on:
push:
branches: [ 1.x ]
pull_request:
branches: [ 1.x ]
workflow_dispatch:

jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
extensions: apcu
ini-values: apc.enable_cli=1

- name: Install dependencies
run: composer install --no-progress

- name: Run PHPUnit
run: ./vendor/bin/phpunit --exclude-group=v8js

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer:v2

- name: Install dependencies
run: composer install --no-progress

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse

coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer:v2

- name: Install dependencies
run: composer install --no-progress

- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs src tests

v8js-test:
name: PHPUnit with V8Js (Docker)
runs-on: ubuntu-latest
container:
image: interposition/8.4.14-fpm-trixie-v8js:v1
steps:
- uses: actions/checkout@v4

- name: Verify V8Js
run: php -m | grep v8js

- name: Install system dependencies
run: |
apt-get update
apt-get install -y unzip git $PHPIZE_DEPS

- name: Install APCu extension
run: |
pecl install apcu
docker-php-ext-enable apcu
php -m | grep apcu

- name: Install Composer
run: |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

- name: Install Composer dependencies
run: composer install --no-progress

- name: Run PHPUnit
run: php -d apc.enable_cli=1 ./vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
phpunit.xml
composer.lock
vendor/
/.phpunit.result.cache
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

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

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER-CS' => true,
'@PHP82Migration' => true,
'declare_strict_types' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']],
])
->setFinder($finder);
131 changes: 0 additions & 131 deletions .php_cs

This file was deleted.

26 changes: 10 additions & 16 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
build:
image: default-jammy
environment:
php: 8.4
nodes:
analysis:
tests:
override:
- php-scrutinizer-run

filter:
paths: ["src/*"]
tools:
external_code_coverage: true
php_code_coverage: true
php_sim: true
php_mess_detector: true
php_pdepend: true
php_analyzer: true
php_cpd: true
php_mess_detector:
enabled: true
config:
ruleset: ./phpmd.xml
php_code_sniffer:
enabled: true
config:
ruleset: ./phpcs.xml
74 changes: 74 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

BEAR.SsrModule is a JavaScript server-side rendering (SSR) module for BEAR.Sunday framework. It uses V8Js PHP extension to execute JavaScript on the server side via the koriym/baracoa library.

## Commands

```bash
# Run all checks (phpcs + phpstan + phpunit)
composer tests

# PHPUnit only (requires APC CLI enabled)
php -d apc.enable_cli=1 vendor/bin/phpunit

# PHPUnit without V8Js (CI environment)
vendor/bin/phpunit --exclude-group=v8js

# Single test
php -d apc.enable_cli=1 vendor/bin/phpunit --filter testInvoke

# Static analysis
composer sa

# Fix coding standards
composer cs-fix
```

## Architecture

### Core Components

The module uses AOP (Aspect-Oriented Programming) via Ray.Aop to intercept methods with `#[Ssr]` attribute:

1. **`SsrModule`** (`src/SsrModule.php`) - Main DI module that:
- Binds `SsrInterceptor` to methods with `#[Ssr]` attribute
- Configures V8Js constructor parameters
- Sets up Baracoa (the V8Js wrapper)

2. **`SsrInterceptor`** (`src/SsrInterceptor.php`) - AOP interceptor that:
- Reads `#[Ssr]` attribute metadata (app name, state keys, meta keys)
- Creates an `Ssr` renderer via `SsrFactoryInterface`
- Attaches the renderer to the ResourceObject

3. **`Ssr`** (`src/Ssr.php`) - RenderInterface implementation that:
- Filters ResourceObject body into `state` (public, sent to client) and `metas` (server-only)
- Calls Baracoa to execute JavaScript rendering

### Attribute Usage

```php
#[Ssr(app: 'app_name', state: ['name', 'age'], metas: ['title'])]
public function onGet(): static
```
- `app`: JS bundle filename (without .bundle.js extension)
- `state`: Keys from body to pass as public state (default: `['*']` = all)
- `metas`: Keys from body for server-side only data

### Cache Modules

- **`CacheSsrModule`** - Base module for cached SSR using `CacheBaracoa`
- **`ApcSsrModule`** - APCu-based cache implementation (requires `$bundleSrcBasePath` constructor parameter)

### Dependencies

- `koriym/baracoa` - V8Js wrapper that executes JavaScript bundles
- `bear/resource` - BEAR.Sunday resource framework
- V8Js PHP extension (optional for development, required for actual SSR execution)

### Testing

Tests requiring V8Js are marked with `#[Group('v8js')]`. CI runs these tests in a Docker container with V8Js pre-installed.
Loading