-
Notifications
You must be signed in to change notification settings - Fork 1
feat: schema-context-bundle #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [ main, develop ] | ||
|
|
||
| jobs: | ||
| run: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| php: | ||
| - '8.3' | ||
| - '8.4' | ||
| coverage: ['none'] | ||
| symfony-versions: | ||
| - '6.4.*' | ||
| - '7.0.*' | ||
| include: | ||
| - description: 'Log Code Coverage' | ||
| php: '8.3' | ||
| symfony-versions: '^7.0' | ||
| doctrine-orm-versions: '^3.0' | ||
| coverage: xdebug | ||
|
|
||
| name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.composer/cache/files | ||
| key: ${{ matrix.php }}-${{ matrix.symfony-versions }} | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php }} | ||
| coverage: xdebug | ||
|
|
||
| - name: Add PHPUnit matcher | ||
| run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
|
|
||
| - name: Set composer cache directory | ||
| id: composer-cache | ||
| run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
|
||
| - name: Cache composer | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{ steps.composer-cache.outputs.dir }} | ||
| key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }} | ||
| restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer | ||
|
|
||
| - name: Update Symfony version | ||
| if: matrix.symfony-versions != '' | ||
| run: | | ||
| composer require symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
| composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install | ||
|
|
||
| - name: Run PHPUnit tests | ||
| run: vendor/bin/phpunit | ||
| if: matrix.coverage == 'none' | ||
|
|
||
| - name: PHPUnit tests and Log Code coverage | ||
| run: vendor/bin/phpunit --coverage-clover=coverage.xml | ||
| if: matrix.coverage == 'xdebug' | ||
|
|
||
| - name: Upload coverage reports to Codecov | ||
| if: matrix.coverage == 'xdebug' | ||
| uses: codecov/codecov-action@v4.0.1 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [ main, develop ] | ||
|
|
||
| jobs: | ||
| security-checker: | ||
| name: Security checker | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --no-progress --no-interaction --prefer-dist | ||
|
|
||
| - name: Download local-php-security-checker | ||
| 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 | ||
|
|
||
| - name: Run local-php-security-checker | ||
| run: chmod +x local-php-security-checker && ./local-php-security-checker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: Code style and static analysis | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [ main, develop ] | ||
|
|
||
| jobs: | ||
| php-cs-fixer: | ||
| name: PHP-CS-Fixer | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --no-progress --no-interaction --prefer-dist | ||
|
|
||
| - name: Run script | ||
| run: vendor/bin/phpcs | ||
|
|
||
| phpstan: | ||
| name: PHPStan | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --no-progress --no-interaction --prefer-dist | ||
|
|
||
| - name: Run script | ||
| run: vendor/bin/phpstan analyse | ||
|
|
||
| composer-validate: | ||
| name: Composer validate | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --no-progress --no-interaction --prefer-dist | ||
|
|
||
| - name: Run script | ||
| run: composer composer-validate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .idea | ||
| /vendor/ | ||
| /composer.lock | ||
| /.phpcs-cache | ||
|
|
||
| ###> phpunit/phpunit ### | ||
| /phpunit.xml | ||
| .phpunit.result.cache | ||
| ###< phpunit/phpunit ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,89 @@ | ||
| # schema-context-bundle | ||
| Schema context bundle | ||
| # Schema Context Bundle | ||
|
|
||
| The **SchemaContextBundle** provides a lightweight way to manage dynamic schema context across your Symfony application, especially useful for multi-tenant setups. It allows schema resolution based on request headers and propagates schema information through Symfony Messenger. | ||
|
|
||
| --- | ||
|
|
||
| ## Features | ||
|
|
||
| - Extracts tenant schema from request headers. | ||
| - Stores schema context in a global `SchemaResolver`. | ||
| - Injects schema info into Messenger messages via a middleware. | ||
| - Rehydrates schema on message consumption via a middleware. | ||
|
|
||
| --- | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| composer require macpaw/schema-context-bundle | ||
| ``` | ||
|
|
||
| If you are not using Symfony Flex, register the bundle manually: | ||
|
|
||
| ```php | ||
| // config/bundles.php | ||
| return [ | ||
| Macpaw\SchemaContextBundle\SchemaContextBundle::class => ['all' => true], | ||
| ]; | ||
| ``` | ||
| ## Configuration | ||
| ### 1. Bundle Configuration | ||
| Add this config to `config/packages/schema_context.yaml`: | ||
|
|
||
| ```yaml | ||
| schema_context: | ||
| app_name: '%env(APP_NAME)%' # Application name | ||
| header_name: 'X-Tenant' # Request header to extract schema name | ||
| default_schema: 'public' # Default schema to fallback to | ||
| allowed_app_names: ['develop', 'staging', 'test'] # App names where schema context is allowed to change | ||
| ``` | ||
| ### 2. Set Environment Parameters | ||
| If you're using .env, define the app name: | ||
|
|
||
| ```env | ||
| APP_NAME=develop | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```php | ||
| use Macpaw\SchemaContextBundle\Service\SchemaResolver; | ||
|
|
||
| public function index(SchemaResolver $schemaResolver) | ||
| { | ||
| $schema = $schemaResolver->getSchema(); | ||
| // Use schema in logic | ||
| } | ||
| ``` | ||
|
|
||
| ## Messenger Integration | ||
| The bundle provides a middleware that automatically: | ||
|
|
||
| * Adds a SchemaStamp to dispatched messages | ||
|
|
||
| * Restores the schema context on message handling | ||
|
|
||
| Enable the middleware in your `messenger.yaml`: | ||
|
|
||
| ```yaml | ||
| framework: | ||
| messenger: | ||
| buses: | ||
| messenger.bus.default: | ||
| middleware: | ||
| - Macpaw\SchemaContextBundle\Messenger\Middleware\SchemaMiddleware | ||
| ``` | ||
|
|
||
| ## Testing | ||
| To run tests: | ||
| ```bash | ||
| vendor/bin/phpunit | ||
| ``` | ||
|
|
||
| ## Contributing | ||
| Feel free to open issues and submit pull requests. | ||
|
|
||
| ## License | ||
| This bundle is released under the MIT license. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Security Policy | ||
|
|
||
| ## Reporting Security Issues | ||
| If you believe you have found a security vulnerability in any MacPaw-owned repository, please report it to us through coordinated disclosure. | ||
|
|
||
| Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests. | ||
|
|
||
| Instead, please send an email to security[@]macpaw.com. | ||
|
|
||
| Please include as much of the information listed below as you can to help us better understand and resolve the issue: | ||
|
|
||
| - The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting) | ||
| - Full paths of source file(s) related to the manifestation of the issue | ||
| - The location of the affected source code (tag/branch/commit or direct URL) | ||
| - Any special configuration required to reproduce the issue | ||
| - Step-by-step instructions to reproduce the issue | ||
| - Proof-of-concept or exploit code (if possible) | ||
| - Impact of the issue, including how an attacker might exploit the issue | ||
|
|
||
| This information will help us triage your report more quickly. | ||
|
|
||
| ## Policy | ||
| See MacPaw's [Vulnerability Disclosure Policy](https://macpaw.com/vulnerability-disclosure-policy) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| { | ||
| "name": "macpaw/schema-context-bundle", | ||
| "description": "A Symfony bundle to provide schema context", | ||
| "type": "symfony-bundle", | ||
| "autoload": { | ||
| "psr-4": { | ||
| "Macpaw\\SchemaContextBundle\\": "src/" | ||
| } | ||
| }, | ||
| "autoload-dev": { | ||
| "psr-4": { | ||
| "Macpaw\\SchemaContextBundle\\Tests\\": "tests/" | ||
| } | ||
| }, | ||
| "require": { | ||
| "php": ">=8.3", | ||
| "symfony/messenger": "^6.4 || ^7.0", | ||
| "symfony/http-kernel": "^6.4 || ^7.0", | ||
| "symfony/dependency-injection": "^6.4 || ^7.0", | ||
| "symfony/config": "^6.4 || ^7.0" | ||
| }, | ||
| "require-dev": { | ||
| "phpstan/phpstan": "^1.10", | ||
| "phpunit/phpunit": "^10.0", | ||
| "squizlabs/php_codesniffer": "3.7.*" | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "dealerdirect/phpcodesniffer-composer-installer": true | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "composer-validate": [ | ||
| "composer validate" | ||
| ], | ||
| "cs": [ | ||
| "vendor/bin/phpcs" | ||
| ], | ||
| "cs-fix": [ | ||
| "vendor/bin/phpcbf" | ||
| ], | ||
| "phpstan": [ | ||
| "vendor/bin/phpstan analyse" | ||
| ], | ||
| "phpunit": [ | ||
| "vendor/bin/phpunit" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| services: | ||
| _defaults: | ||
| autowire: true | ||
| autoconfigure: true | ||
| public: false | ||
|
|
||
| Macpaw\SchemaContextBundle\Service\SchemaResolver: | ||
| public: true | ||
| shared: true | ||
|
|
||
| Macpaw\SchemaContextBundle\EventListener\SchemaRequestListener: | ||
| arguments: | ||
| $schemaResolver: '@Macpaw\SchemaContextBundle\Service\SchemaResolver' | ||
| $schemaRequestHeader: '%schema_context.header_name%' | ||
| $defaultSchema: '%schema_context.default_schema%' | ||
| $appName: '%schema_context.app_name%' | ||
| $allowedAppNames: '%schema_context.allowed_app_names%' | ||
| tags: | ||
| - { name: kernel.event_subscriber } | ||
|
|
||
| Macpaw\SchemaContextBundle\Messenger\Middleware\SchemaMiddleware: | ||
| tags: | ||
| - { name: messenger.middleware } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.