Skip to content

Commit 5b9c4dd

Browse files
authored
Merge pull request #2 from MacPaw/develop
Release
2 parents 7d1f07e + abae0f2 commit 5b9c4dd

13 files changed

+638
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main, develop ]
7+
8+
jobs:
9+
run:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php:
15+
- '8.3'
16+
- '8.4'
17+
coverage: ['none']
18+
symfony-versions:
19+
- '6.4.*'
20+
- '7.0.*'
21+
include:
22+
- description: 'Log Code Coverage'
23+
php: '8.3'
24+
symfony-versions: '^7.0'
25+
doctrine-orm-versions: '^3.0'
26+
coverage: xdebug
27+
28+
name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- uses: actions/cache@v4
34+
with:
35+
path: ~/.composer/cache/files
36+
key: ${{ matrix.php }}-${{ matrix.symfony-versions }}
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ matrix.php }}
42+
coverage: xdebug
43+
44+
- name: Add PHPUnit matcher
45+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
46+
47+
- name: Set composer cache directory
48+
id: composer-cache
49+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
50+
51+
- name: Cache composer
52+
uses: actions/cache@v4
53+
with:
54+
path: ${{ steps.composer-cache.outputs.dir }}
55+
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }}
56+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer
57+
58+
- name: Update Symfony version
59+
if: matrix.symfony-versions != ''
60+
run: |
61+
composer require symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts
62+
composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts
63+
64+
- name: Install dependencies
65+
run: composer install
66+
67+
- name: Run PHPUnit tests
68+
run: vendor/bin/phpunit
69+
if: matrix.coverage == 'none'
70+
71+
- name: PHPUnit tests and Log Code coverage
72+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
73+
if: matrix.coverage == 'xdebug'
74+
75+
- name: Upload coverage reports to Codecov
76+
if: matrix.coverage == 'xdebug'
77+
uses: codecov/[email protected]
78+
with:
79+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/security.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
pull_request:
3+
push:
4+
branches: [ main, develop ]
5+
6+
jobs:
7+
security-checker:
8+
name: Security checker
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
17+
- name: Install dependencies
18+
run: composer install --no-progress --no-interaction --prefer-dist
19+
20+
- name: Download local-php-security-checker
21+
run: curl -s -L -o local-php-security-checker https://github.com/fabpot/local-php-security-checker/releases/download/v1.0.0/local-php-security-checker_1.0.0_linux_amd64
22+
23+
- name: Run local-php-security-checker
24+
run: chmod +x local-php-security-checker && ./local-php-security-checker
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Code style and static analysis
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main, develop ]
7+
8+
jobs:
9+
php-cs-fixer:
10+
name: PHP-CS-Fixer
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
19+
- name: Install dependencies
20+
run: composer install --no-progress --no-interaction --prefer-dist
21+
22+
- name: Run script
23+
run: vendor/bin/phpcs
24+
25+
phpstan:
26+
name: PHPStan
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
- name: Setup PHP
33+
uses: shivammathur/setup-php@v2
34+
35+
- name: Install dependencies
36+
run: composer install --no-progress --no-interaction --prefer-dist
37+
38+
- name: Run script
39+
run: vendor/bin/phpstan analyse
40+
41+
composer-validate:
42+
name: Composer validate
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v2
47+
48+
- name: Setup PHP
49+
uses: shivammathur/setup-php@v2
50+
51+
- name: Install dependencies
52+
run: composer install --no-progress --no-interaction --prefer-dist
53+
54+
- name: Run script
55+
run: composer composer-validate

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.idea
2+
/vendor/
3+
/composer.lock
4+
/.phpcs-cache
5+
6+
###> phpunit/phpunit ###
7+
/phpunit.xml
8+
.phpunit.result.cache
9+
###< phpunit/phpunit ###

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
1-
# redis-schema-bundle
2-
Redis schema bundle
1+
# Redis Schema Bundle
2+
3+
The **Redis Schema Bundle** provides automatic **Redis key namespacing** based on the current schema context, allowing **data isolation** in shared environments (e.g., staging, preview, multi-tenant).
4+
5+
This bundle builds on top of [Schema Context Bundle](https://github.com/macpaw/schema-context-bundle) to propagate the schema context across the app and decorate your Redis cache.
6+
7+
## Features
8+
9+
- Transparent key prefixing for Redis
10+
- Compatible with `Symfony\Component\Cache\Adapter\RedisAdapter`
11+
- Works with Symfony `CacheInterface` and `AdapterInterface`
12+
- Supports schema-based multitenancy
13+
14+
---
15+
16+
## Installation
17+
18+
```bash
19+
composer require macpaw/redis-schema-bundle
20+
```
21+
22+
If you are not using Symfony Flex, register the bundle manually:
23+
24+
```php
25+
// config/bundles.php
26+
return [
27+
Macpaw\SchemaContextBundle\SchemaContextBundle::class => ['all' => true],
28+
Macpaw\RedisSchemaBundle\RedisSchemaBundle::class => ['all' => true],
29+
];
30+
```
31+
## Configuration
32+
Make sure to register the base Redis adapter and decorate it with the schema-aware implementation:
33+
34+
```yaml
35+
# config/services.yaml
36+
37+
services:
38+
redis_cache_adapter:
39+
class: Symfony\Component\Cache\Adapter\RedisAdapter
40+
arguments:
41+
- '@SymfonyBundles\RedisBundle\Redis\ClientInterface'
42+
- 'cache_storage'
43+
- '%redis_default_cache_ttl%'
44+
45+
Macpaw\RedisSchemaBundle\Redis\SchemaAwareRedisAdapter:
46+
decorates: Symfony\Component\Cache\Adapter\RedisAdapter
47+
arguments:
48+
- '@.inner'
49+
- '@Macpaw\SchemaContextBundle\Service\SchemaResolver'
50+
```
51+
52+
## Usage
53+
Anywhere you use Symfony cache services (injected via CacheInterface or AdapterInterface), your keys will automatically be prefixed based on the current schema.
54+
For example:
55+
56+
```php
57+
public function __construct(private CacheInterface $cache) {}
58+
59+
public function save(): void
60+
{
61+
$this->cache->get('user.123', function () {
62+
return 'value';
63+
});
64+
}
65+
```
66+
If the schema is client_a, this will store key: client_a.user.123.
67+
68+
## Testing
69+
To run tests:
70+
```bash
71+
vendor/bin/phpunit
72+
```
73+
74+
## Contributing
75+
Feel free to open issues and submit pull requests.
76+
77+
## License
78+
This bundle is released under the MIT license.
79+

SECURITY.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Security Policy
2+
3+
## Reporting Security Issues
4+
If you believe you have found a security vulnerability in any MacPaw-owned repository, please report it to us through coordinated disclosure.
5+
6+
Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.
7+
8+
Instead, please send an email to security[@]macpaw.com.
9+
10+
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
11+
12+
- The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
13+
- Full paths of source file(s) related to the manifestation of the issue
14+
- The location of the affected source code (tag/branch/commit or direct URL)
15+
- Any special configuration required to reproduce the issue
16+
- Step-by-step instructions to reproduce the issue
17+
- Proof-of-concept or exploit code (if possible)
18+
- Impact of the issue, including how an attacker might exploit the issue
19+
20+
This information will help us triage your report more quickly.
21+
22+
## Policy
23+
See MacPaw's [Vulnerability Disclosure Policy](https://macpaw.com/vulnerability-disclosure-policy)

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "macpaw/redis-schema-bundle",
3+
"description": "A Symfony bundle to add schema prefixes for redis keys",
4+
"type": "symfony-bundle",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Macpaw\\RedisSchemaBundle\\": "src/"
9+
}
10+
},
11+
"autoload-dev": {
12+
"psr-4": {
13+
"Macpaw\\RedisSchemaBundle\\Tests\\": "tests/"
14+
}
15+
},
16+
"require": {
17+
"php": ">=8.3",
18+
"macpaw/schema-context-bundle": "^1.0",
19+
"symfony/cache": "^7.3"
20+
},
21+
"require-dev": {
22+
"phpstan/phpstan": "^1.10",
23+
"phpunit/phpunit": "^10.0",
24+
"squizlabs/php_codesniffer": "3.7.*"
25+
},
26+
"config": {
27+
"allow-plugins": {
28+
"dealerdirect/phpcodesniffer-composer-installer": true
29+
}
30+
},
31+
"scripts": {
32+
"composer-validate": [
33+
"composer validate"
34+
],
35+
"cs": [
36+
"vendor/bin/phpcs"
37+
],
38+
"cs-fix": [
39+
"vendor/bin/phpcbf"
40+
],
41+
"phpstan": [
42+
"vendor/bin/phpstan analyse"
43+
],
44+
"phpunit": [
45+
"vendor/bin/phpunit"
46+
]
47+
}
48+
}

phpcs.xml.dist

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg value="p"/>
9+
<arg name="extensions" value="php"/>
10+
<arg name="tab-width" value="4"/>
11+
<arg name="report-width" value="120"/>
12+
13+
<rule ref="PSR12" />
14+
15+
<file>src/</file>
16+
<file>tests/</file>
17+
18+
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
19+
<rule ref="Generic.PHP.RequireStrictTypes"/>
20+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
21+
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"></rule>
22+
<rule ref="Squiz.Commenting.FunctionComment.SpacingAfterParamType"></rule>
23+
24+
<rule ref="Generic.PHP.ForbiddenFunctions">
25+
<properties>
26+
<property name="forbiddenFunctions" type="array" value="eval=>NULL,dd=>NULL,die=>NULL,var_dump=>NULL,dump=>NULL,sizeof=>count,delete=>unset,print=>echo,echo=>NULL,print_r=>NULL,create_function=>NULL"/>
27+
</properties>
28+
</rule>
29+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
30+
<properties>
31+
<property name="spacing" value="1" />
32+
<property name="spacingBeforeFirst" value="0" />
33+
<property name="spacingAfterLast" value="0" />
34+
</properties>
35+
</rule>
36+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
37+
<properties>
38+
<property name="ignoreBlankLines" value="false" />
39+
</properties>
40+
</rule>
41+
</ruleset>

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src
5+
- tests

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
7+
>
8+
<testsuites>
9+
<testsuite name="Symfony Messenger Bundle Test Suite">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<coverage>
14+
<report>
15+
<clover outputFile="clover.xml"/>
16+
</report>
17+
</coverage>
18+
<source>
19+
<include>
20+
<directory>./src</directory>
21+
</include>
22+
</source>
23+
</phpunit>

0 commit comments

Comments
 (0)