Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rastusik committed Feb 1, 2025
0 parents commit 5d5698d
Show file tree
Hide file tree
Showing 95 changed files with 4,947 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .allowed-licenses
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Apache-2.0
- BSD-2-Clause
- BSD-3-Clause
- ISC
- LGPL-3.0-or-later
- MIT
- OSL-3.0
47 changes: 47 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
root=true
[*]
charset=utf-8
indent_style=space
indent_size=4
tab_width=4
end_of_line=lf
trim_trailing_whitespace=true
insert_final_newline=true

[*.{yaml,yml}]
indent_size=2
tab_width=2

[*.{js,ts,jsx,tsx}]
indent_size=2
tab_width=2

[*.hcl]
indent_size=2
tab_width=2

[Makefile]
indent_style=tab

[Jenkinsfile]
indent_size=2
tab_width=2

[*.sh]
end_of_line=lf

[*.md]
trim_trailing_whitespace=false

[*.{xml,xsd}]
max_line_length=off
indent_size=2
tab_width=2

[*.json]
indent_size=2
tab_width=2

[*.neon]
indent_size=2
tab_width=2
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
ignore:
- dependency-name: "*"
update-types: [ "version-update:semver-major" ]
- dependency-name: "symfony/*"
versions: ["6.x"]
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
not-automated:
- '**/**'
- '.github/**'
80 changes: 80 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: PHP Composer

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

permissions:
pull-requests: write
issues: write
repository-projects: write
contents: write

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ '8.2', '8.3' ]
symfony-version: ['6.4.*', '7.0.*' ]
symfony-deprecations-helper: [ 'max[direct]=0&baselineFile=./tests/allowed.json' ]
grumphp-testsuite: [ 'no-analyse' ]
grumphp-flag: [ '-no-analyse' ]

name: "PHP: ${{ matrix.php-version }}, Symfony: ${{ matrix.symfony-version }}, GrumPHP: ${{ matrix.grumphp-testsuite }}, Composer: ${{ matrix.composer-flag }}"

steps:
- uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Check PHP Version
run: php -v

- name: Symfony version # run every time except for dependencies with SF 5.4 (locked in composer)
if: ${{ matrix.grumphp-testsuite == 'no-analyse' }}
run: composer config extra.symfony.require ${{ matrix.symfony-version }}

- name: Composer update # run for everything except php 8.1 or SF 5.4 locked in composer.lock
if: ${{ matrix.grumphp-testsuite == 'no-analyse' }}
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction

- name: Composer install # only run for locked dependencies with php 8.1 or SF 5.4 (locked in composer)
if: ${{ matrix.grumphp-testsuite == 'main' }}
run: composer install --prefer-dist --no-interaction

- name: Run static analysis (GrumPHP)
run: composer run-script grumphp${{ matrix.php-version }}${{ matrix.grumphp-flag }}

# - name: Check vendor licenses
# run: composer run-script lic-check

dependabot:
needs: [ build ]
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Approve a dependabot PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
13 changes: 13 additions & 0 deletions .github/workflows/pr_labeller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pull request labeler
on:
pull_request:
branches: [ master ]
jobs:
label:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/labeler@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
vendor
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache
.phpcs-cache
docker-compose.override.yml
tests/Functional/app/data/*
!tests/Functional/app/data/.gitkeep
mutagen.yml.lock
/.idea/
composer.lock
60 changes: 60 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

$config = new PhpCsFixer\Config();
/**
* @see https://github.com/FriendsOfPHP/PHP-CS-Fixer for rules
*/
return $config->setRules([
'@PER-CS2.0' => true,
'@PHP81Migration' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => true,
'braces_position' => ['classes_opening_brace' => 'next_line_unless_newline_at_signature_end'],
'class_reference_name_casing' => false,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_type_declaration' => true,
'global_namespace_import' => [
'import_classes' => true,
],
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'native_constant_invocation' => [
'fix_built_in' => false,
'scope' => 'all',
],
'native_function_invocation' => [
'include' => [],
'exclude' => ['@all'],
],
'no_blank_lines_after_class_opening' => true,
'no_null_property_initialization' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'nullable_type_declaration_for_default_null_value' => false,
'ordered_class_elements' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'function', 'const']],
'no_unused_imports' => true,
'phpdoc_order' => [
'order' => ['param', 'return', 'throws'],
],
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
],
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
);
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 K911

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Doctrine resettable entity manager bundle

This bundle should be used with workloads where Symfony doesn't get initialized on each request, but stays in memory
and the same instance handles multiple requests, one after another (e.g. when using
[Swoole Bundle](https://github.com/symfony-swoole/swoole-bundle)).
Another use case would be message queue consuming (e.g. Symfony messenger), where it is needed
to clear (and possibly reset) the entity manager after processing a message.

The best feature of this bundle is, that it wraps all configured entity managers
into a `ResettableEntityManager` instance, which
is able to reset the entity manager when it gets stuck on an exception.
After each request the entity manager gets cleared or reset, if an exception occurred during request handling.

Also another feature is, that on each request start the entity manager connection gets pinged, so the connection
won't get closed after some period of time.

## Instalation

`composer require swoole-bundle/resetter-bundle`

## SETUP

```php
// config/bundles.php
return [
//...
\SwooleBundle\ResetterBundle\SwooleBundleResetterBundle::class => ['all' => true]
//...
];
```

```yaml
swoole_bundle_resetter:
exclude_from_processing:
# these entity managers won't be wrapped by the resettable entity manager:
entity_managers:
- readonly
# these dbal connections won't be assigned to the keep alive handler
dbal:
- readonly
# these redis cluster connections won't be assigned to the keep alive handler
redis_cluster:
- default
# default 0 - if set, the connection ping operation will be executed each X seconds
# (instead of at the beginning of each request)
ping_interval: 10
# default false - if set to true, the app will check if there is an active transaction
# in the processed connection, and it will rollback the transaction
check_active_transactions: true
# for reader writer connections, each has to be defined as 'reader' or 'writer' to be able for the symfony
# app to reconnect after db failover. currently only AWS Aurora is supported.
failover_connections:
default: writer
# redis clusters which need to be failed over should be registered here
# it's really important to set default timeouts to a low value, e.g. 2 seconds, so the app won't block for too long
redis_cluster_connections:
default: 'RedisCluster' # connection name (can be literally anything) => redis cluster service id
```
13 changes: 13 additions & 0 deletions bin/grumphp_hooks/environment_spinup
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

export PATH="/usr/local/bin:$PATH"

#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ -z `docker-compose ps -q resetter-bundle-php82` ]] || [[ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q resetter-bundle-php82)` ]]; then
docker-compose up -d
fi
Loading

0 comments on commit 5d5698d

Please sign in to comment.