Installation:
composer require anzusystems/common-bundle --no-scripts
Kernel Configuration:
Update public/index.php and bin/console to extend AnzuKernel with required parameters:
return new Kernel(
appNamespace: $context['APP_NAMESPACE'],
appSystem: $context['APP_SYSTEM'], // e.g., "core"
appVersion: $context['APP_VERSION'], // e.g., "1.0.0"
appReadOnlyMode: (bool) $context['APP_READ_ONLY_MODE'],
environment: $context['APP_ENV'],
debug: (bool) $context['APP_DEBUG'],
);
Configuration:
Define config/packages/anzu_common.yaml with minimal required settings (e.g., user_entity_class, app_entity_namespace).
First Use Case:
Leverage the health check feature by enabling it in anzu_common.yaml:
health_check:
enabled: true
Access /health endpoint to verify system status.
Journal Logs: Use MongoDB for structured logging (configured in logs.journal).
logs:
journal:
mongo:
uri: '%env(ANZU_MONGODB_APP_LOG_URI)%'
Logs are sent via Symfony Messenger (configure messenger_transport).
Audit Logs: Track CRUD operations on entities (configure logs.audit.logged_methods).
logs:
audit:
logged_methods: ['POST', 'PUT', 'PATCH', 'DELETE']
anzu_common.permissions.config:
permissions:
config:
app_article:
create: {}
delete:
grants: [0, 1, 2]
AbstractVoter for role-based access control (RBAC):
use AnzuSystems\CommonBundle\Security\Voter\AbstractVoter;
class ArticleVoter extends AbstractVoter {
protected function supports(string $attribute, mixed $subject): bool {
return $attribute === 'EDIT' && $subject instanceof Article;
}
}
OpCacheModule, RedisModule) or add custom ones:
use AnzuSystems\CommonBundle\HealthCheck\Module\HealthCheckModuleInterface;
class CustomHealthCheckModule implements HealthCheckModuleInterface {
public function check(): bool { /* ... */ }
}
Register in anzu_common.health_check.modules.ConsumeMessagesCommand is unlocked by default):
unlocked_commands:
- App\Command\ImportDataCommand
ValueObject trait for immutable data:
use AnzuSystems\CommonBundle\Model\ValueObject;
class Email implements ValueObject {
private string $address;
public function __construct(string $address) {
$this->address = $address;
}
}
UniqueEntityDto for validation:
use AnzuSystems\CommonBundle\Dto\UniqueEntityDto;
class UserDto extends UniqueEntityDto {
public string $email;
}
CurrentUserResolver) in controllers:
use AnzuSystems\CommonBundle\Controller\ArgumentResolver\CurrentUserResolver;
#[Route('/profile')]
public function profile(#[CurrentUser] User $user) { /* ... */ }
FixturesLoader:
use AnzuSystems\CommonBundle\Fixtures\FixturesLoader;
$loader = new FixturesLoader();
$loader->load('path/to/fixtures');
Environment Variables:
Add use_putenv to composer.json for global env vars (e.g., Google SDK):
"extra": {
"runtime": {
"use_putenv": true
}
}
Proxy Cache: Enable HTTP cache headers:
settings:
app_cache_proxy_enabled: true
Error Handling:
Customize exception handlers in anzu_common.errors.exception_handlers:
exception_handlers:
- App\Exception\Handler\CustomValidationHandler
Symfony Messenger: Configure transport for logs:
logs:
messenger_transport:
name: 'core_log'
dsn: '%env(MESSENGER_TRANSPORT_DSN)%?topic[name]=core_log'
Kernel Initialization:
appSystem, appVersion, and appReadOnlyMode to AnzuKernel will cause runtime errors.index.php, console) initialize AnzuKernel correctly.BC Breaks:
anzu_mongo_app_log_collection → anzu_mongo_journal_log_collection (check routes and config).AbstractVoter now expects ROLE_SUPER_ADMIN (not ROLE_ADMIN) for full access.modifiedBy if not handled properly.Permissions:
default_grants) apply to all actions unless overridden. Misconfiguration can lead to unintended access.ROLE_SUPER_ADMIN first.Logging:
journal for MongoDB logs.MESSENGER_TRANSPORT_DSN is set in .env.Health Checks:
HealthCheckModuleInterface. Missing check() method will fail silently.DataMountModule for filesystem issues (e.g., missing directories).Concurrency:
unlocked_commands are locked by default. Overlapping executions may cause deadlocks.findByApiParamsWithInfiniteListing for paginated, concurrent-safe queries.Permission Denied:
debug: true in AnzuKernel) and check Symfony’s security events.bin/console debug:security
Logging Issues:
logs.journal.mongo and logs.audit.mongo.bin/console debug:container AnzuSystems\CommonBundle\Logger\JournalLogger
Health Check Failures:
health_check.modules to isolate the issue.modules:
- AnzuSystems\CommonBundle\HealthCheck\Module\MysqlModule
Command Locking:
anzu_common.settings.app_redis for Redis service ID.bin/console anzusystems:lock:test App\Command\MyCommand
Value Object Validation:
UniqueEntityDto for database uniqueness checks:
$dto = new UserDto();
$dto->email = 'test@example.com';
$validator = new UniqueEntityDtoValidator($dto, User::class, 'email');
$errors = $validator->validate();
Custom Exception Handlers:
AbstractExceptionHandler:
use AnzuSystems\CommonBundle\Exception\Handler\AbstractExceptionHandler;
class CustomHandler extends AbstractExceptionHandler {
public function handle(Throwable $exception): Response { /* ... */ }
}
anzu_common.errors.exception_handlers.Custom Health Check Modules:
HealthCheckModuleInterface:
class CustomModule implements HealthCheckModuleInterface {
public function check(): bool {
return file_exists('/custom/health/file');
}
}
health_check.modules.Custom Argument Resolvers:
AbstractArgumentResolver:
use AnzuSystems\CommonBundle\Controller\ArgumentResolver\AbstractArgumentResolver;
class CustomResolver extends AbstractArgumentResolver {
public function supports(Request $request,
How can I help you explore Laravel packages today?