Skip to content

Commit

Permalink
initial commit (moved from the swoole bundle)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfris committed Nov 8, 2019
0 parents commit e757802
Show file tree
Hide file tree
Showing 42 changed files with 9,328 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Created by .ignore support plugin (hsz.mobi)
vendor
.php_cs.cache
.phpunit.result.cache
tests/Functional/app/data/*
!tests/Functional/app/data/.gitkeep
22 changes: 22 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'array_syntax' => [
'syntax' => 'short',
],
'no_useless_else' => true,
'no_useless_return' => true,
'strict_comparison' => true,
'strict_param' => true,
'no_unused_imports' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('tests')
->in(__DIR__)
);

return $config;
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.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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/pixelfederation/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 pixelfederation/doctrine-resettable-em-bundle`

## SETUP

```php
// config/bundles.php
//...
PixelFederation\CommandProcessingBundle\PixelFederationDoctrineResettableEmBundle::class => ['all' => true]
//...
```
19 changes: 19 additions & 0 deletions bin/grumphp_hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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 )"

GIT_USER=$(git config user.name)
GIT_EMAIL=$(git config user.email)
COMMIT_MSG_FILE=$1

# Fetch the GIT diff and format it as command input:
DIFF=$(git diff -r -p -m -M --full-index --staged | cat)

# Run GrumPHP
(cd "./" && printf "%s\n" "${DIFF}" | docker run -v `pwd`:/srv/www:delegated -u $(id -u):$(id -g) --rm -e GIT_USER="${GIT_USER}" -e GIT_EMAIL="${GIT_EMAIL}" -e COMMIT_MSG_FILE="${COMMIT_MSG_FILE}" doctrine-em-resetter-bundle bash -c "cd /srv/www && ./vendor/bin/grumphp git:commit-msg --ansi --git-user='${GIT_USER}' --git-email='${GIT_EMAIL}' '${COMMIT_MSG_FILE}'")
17 changes: 17 additions & 0 deletions bin/grumphp_hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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 )"

docker build -t doctrine-em-resetter-bundle docker/php

# Fetch the GIT diff and format it as command input:
DIFF=$(git diff -r -p -m -M --full-index --staged | cat)

# Run GrumPHP
(cd "./" && printf "%s\n" "${DIFF}" | docker run -v `pwd`:/srv/www:delegated -u $(id -u):$(id -g) --rm doctrine-em-resetter-bundle bash -c "cd /srv/www && ./vendor/bin/grumphp git:pre-commit --ansi --skip-success-output")
51 changes: 51 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "pixelfederation/doctrine-resettable-em-bundle",
"homepage": "https://github.com/pixelfederation/doctrine-resettable-em-bundle",
"type": "symfony-bundle",
"description": "Symfony bundle for decorating default entity managers using a resettable decorator.",
"license": "MIT",
"authors": [
{
"name": "Martin Fris",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.2 <7.4",
"doctrine/orm": "^2.6",
"sensio/framework-extra-bundle": "^5.2",
"symfony/config": "^4.1",
"symfony/dependency-injection": "^4.1",
"symfony/orm-pack": "^1.0",
"symfony/yaml": "^4.1"
},
"autoload": {
"psr-4": {
"PixelFederation\\DoctrineResettableEmBundle\\": "src/"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"jakub-onderka/php-parallel-lint": "^1.0",
"nikic/php-parser": "^4.2",
"phpcompatibility/php-compatibility": "^9.1",
"phpmd/phpmd": "^2.6",
"phpro/grumphp": "^0.15",
"phpstan/phpstan": "^0.11",
"phpunit/phpunit": "^8.1",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.4",
"symfony/browser-kit": "^4.1",
"symfony/framework-bundle": "^4.1",
"symfony/http-kernel": "^4.1",
"vimeo/psalm": "^3.2"
},
"autoload-dev": {
"psr-4": {
"PixelFederation\\DoctrineResettableEmBundle\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
}
}
Loading

0 comments on commit e757802

Please sign in to comment.