承接 anzusystems/common-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anzusystems/common-bundle

Composer 安装命令:

composer require anzusystems/common-bundle

包简介

Anzu common services, utils and helpers

README 文档

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_journal_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
            - AnzuSystems\CommonBundle\Exception\Handler\HttpExceptionHandler
    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'
        # Journal log section
        journal:
            # 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

See Permission management

Documentation

Besides AnzuSystems' own serializer-bundle and contracts, common-bundle provides many functionalities, you can read about them in following categories:

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
    }
}

anzusystems/common-bundle 适用场景与选型建议

anzusystems/common-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.46k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「anzusystems」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 anzusystems/common-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anzusystems/common-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 anzusystems/common-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-11-28