anzusystems / common-bundle
Anzu common services, utils and helpers
Installs: 6 527
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.3
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-mongodb: *
- ext-pcntl: *
- ext-redis: *
- ext-zend-opcache: *
- anzusystems/contracts: ^4.0
- anzusystems/serializer-bundle: ^4.0
- doctrine/dbal: ^4.0
- doctrine/lexer: ^3.0
- doctrine/orm: ^3.1
- mongodb/mongodb: ^1.9
- monolog/monolog: ^2.0|^3.0
- nelmio/api-doc-bundle: ^4.8
- symfony/cache: ^7.0
- symfony/console: ^6.0|^7.0
- symfony/dependency-injection: ^6.0|^7.0
- symfony/dotenv: ^6.0|^7.0
- symfony/event-dispatcher: ^6.0|^7.0
- symfony/expression-language: ^6.0|^7.0
- symfony/framework-bundle: ^6.0|^7.0
- symfony/http-client-contracts: ^3.1
- symfony/http-kernel: ^6.0|^7.0
- symfony/lock: ^6.0|^7.0
- symfony/messenger: ^6.0|^7.0
- symfony/monolog-bundle: >=3.7
- symfony/polyfill-uuid: ^1.23
- symfony/runtime: ^6.0|^7.0
- symfony/security-bundle: ^6.0|^7.0
- symfony/uid: ^6.0|^7.0
- symfony/validator: ^6.0|^7.0
- symfony/yaml: ^6.0|^7.0
Requires (Dev)
- doctrine/doctrine-bundle: ^2.4
- jetbrains/phpstorm-attributes: ^1.0
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.0
- symfony/test-pack: ^1.0
- symplify/easy-coding-standard: ^11.0
- vimeo/psalm: ^5.4
- dev-main
- 8.10.0
- 8.9.0
- 8.8.0
- 8.7.0
- 8.6.0
- 8.5.0
- 8.4.0
- 8.3.0
- 8.2.0
- 8.1.0
- 8.0.0
- 7.0.0
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.2.1
- 5.2
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.10.0
- 2.9.1
- 2.9.0
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.1
- 1.0.0
- dev-comment_update
- dev-feature_73458_array_string_allow_list
- dev-job
This package is auto-updated.
Last update: 2024-11-09 11:03:05 UTC
README
Provides common functionality among Anzusystems' projects.
Installation
From within container execute the following command to download the latest version of the bundle:
$ composer require anzusystems/common-bundle --no-scripts
Step 3: Use the Bundle
Change your src\Kernel.php
to extend AnzuSystems\CommonBundle\Kernel\AnzuKernel
.
AnzuKernel
requires for constructor some extra parameters:
public function __construct( private string $appSystem, // Specific application/system name, eg. "core". private string $appVersion, // Specific application/system version, eg. "1.0.0". private bool $appReadOnlyMode, // Boolean if application/system should run in read only mode. string $environment, bool $debug, ) { parent::__construct( environment: $environment, debug: $debug ); }
It means, you have to initialize AnzuKernel
on all entry points.
public/index.php
should look like this:
<?php declare(strict_types=1); use App\Kernel; use AnzuSystems\CommonBundle\Kernel\AnzuKernel; require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; return static function (array $context): Kernel { return new Kernel( appNamespace: $context['APP_NAMESPACE'], appSystem: $context['APP_SYSTEM'], appVersion: $context['APP_VERSION'], appReadOnlyMode: (bool) $context['APP_READ_ONLY_MODE'], environment: $context['APP_ENV'], debug: (bool) $context['APP_DEBUG'], ); };
bin/console
should look like this:
#!/usr/bin/env php <?php declare(strict_types=1); use App\Kernel; use Symfony\Bundle\FrameworkBundle\Console\Application; if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) { throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".'); } require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; return static function (array $context): Application { $kernel = new Kernel( appNamespace: $context['APP_NAMESPACE'], appSystem: $context['APP_SYSTEN'], appVersion: $context['APP_VERSION'], appReadOnlyMode: (bool) $context['APP_READ_ONLY_MODE'], environment: $context['APP_ENV'], debug: (bool) $context['APP_DEBUG'], ); return new Application($kernel); };
Configuration
You must define config in config/packages/anzu_common.yaml
. Here is a fully listed config:
anzu_common: settings: # Service id of your application Redis app_redis: TestRedis # Boolean flag for enabling/disabling proxy cache headers. app_cache_proxy_enabled: true # Set FCQN to your User entity class user_entity_class: App\Entity\User # Namespace of your application entity classes app_entity_namespace: App\Entity # Namespace of your application value objects. app_value_object_namespace: App\Model\ValueObject # FCQN of your commands which won't be locked against concurrency. Defaults to command listed bellow. unlocked_commands: - Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand - Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand - Symfony\Component\Messenger\Command\ConsumeMessagesCommand health_check: enabled: true # Table name against which is performed health check. mysql_table_name: _doctrine_migration_versions mongo_collections: [anzu_mongo_app_log_collection, anzu_mongo_audit_log_collection] # Modules used for health check. Defaults to modules listed bellow. # Here you can only define some of these modules. # For none use modules: [] modules: - AnzuSystems\CommonBundle\HealthCheck\Module\OpCacheModule - AnzuSystems\CommonBundle\HealthCheck\Module\ForwardIpModule - AnzuSystems\CommonBundle\HealthCheck\Module\MysqlModule - AnzuSystems\CommonBundle\HealthCheck\Module\MongoModule - AnzuSystems\CommonBundle\HealthCheck\Module\RedisModule - AnzuSystems\CommonBundle\HealthCheck\Module\DataMountModule errors: enabled: true # Default empty. You can define regexes on which is error handling enabled. only_uri_match: - ^/api/ # Default exception handler service id. You can change to your own service id, it's required. default_exception_handler: AnzuSystems\CommonBundle\Exception\Handler\DefaultExceptionHandler # Exception Handlers used in `AnzuSystems\CommonBundle\Event\Listener\ExceptionListener`. # Here you can only define some of these handlers. # For none use exception_handlers: [] exception_handlers: - AnzuSystems\CommonBundle\Exception\Handler\NotFoundExceptionHandler - AnzuSystems\CommonBundle\Exception\Handler\ValidationExceptionHandler - AnzuSystems\CommonBundle\Exception\Handler\AppReadOnlyModeExceptionHandler - AnzuSystems\CommonBundle\Exception\Handler\AccessDeniedExceptionHandler logs: enabled: true # Logs are sent through Symfony Messenger. messenger_transport: # Name of your messenger transport. name: 'core_log' # Messenger transport DSN dsn: '%env(MESSENGER_TRANSPORT_DSN)%?topic[name]=core_log' # Application log section app: # Mongo connection definition mongo: uri: '%env(ANZU_MONGODB_APP_LOG_URI)%' username: '%env(ANZU_MONGODB_APP_LOG_USERNAME)%' password: '%env(ANZU_MONGODB_APP_LOG_PASSWORD)%' database: '%env(ANZU_MONGODB_APP_LOG_DB)%' ssl: '%env(bool:ANZU_MONGODB_APP_LOG_SSL)%' collection: appLogs # Audit log section audit: # Mongo connection definition mongo: uri: '%env(ANZU_MONGODB_AUDIT_LOG_URI)%' username: '%env(ANZU_MONGODB_AUDIT_LOG_USERNAME)%' password: '%env(ANZU_MONGODB_AUDIT_LOG_PASSWORD)%' database: '%env(ANZU_MONGODB_AUDIT_LOG_DB)%' ssl: '%env(bool:ANZU_MONGODB_AUDIT_LOG_SSL)%' collection: auditLogs logged_methods: ['POST', 'PUT', 'PATCH', 'DELETE'] permissions: # List of roles that can be assigned to user. roles: [ROLE_USER, ROLE_ADMIN] # Default list of grants that can be assigned to all permissions. default_grants: [2, 0] config: # List of arbitrary subjects of permission. app_article: # List of subject's actions with default grants: create: update: # Action with non-default grants for permission app_article_delete: delete: grants: [0, 1, 2] app_post: create: translation: subjects: # Translation of all unique subjects defined in config above. app_article: # Feel free to add more languages. en: Article sk: Článok app_post: en: Post sk: Príspevok actions: # Translation of all unique actions in all subjects defined in config above. create: en: Create sk: Vytvor update: en: Update sk: Uprav delete: en: Delete sk: Zmaž roles: # Translation of all roles provided in configuration above. ROLE_USER: en: User sk: Užívateľ ROLE_ADMIN: en: Admin sk: Administrátor
Setup permissions and their management
Documentation
Besides AnzuSystems' own serializer-bundle and contracts, common-bundle provides many functionalities, you can read about them in following categories:
- Argument Resolvers
- Debug
- Exception Handlers
- Fixtures
- Health Check
- Helpers
- Locks
- Logs
- Param Converters (deprecated)
- Proxy Cache
- Tests
- Traits
- Value Objects
- Permissions
Troubleshooting
Some packages as Google SDK requires environment variables to be defined globally.
Allow usage of putenv in your composer.json
"extra": { "runtime": { "use_putenv": true } }