定制 philipphermes/symfony-layered-architecture 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

philipphermes/symfony-layered-architecture

Composer 安装命令:

composer require philipphermes/symfony-layered-architecture

包简介

Provides a Twig compiler pass and routing loaders that enable support for a layered architecture.

README 文档

README

Provides a Twig compiler pass and routing loaders that enable support for a layered architecture.

CI PHP

Table of Contents

  1. Installation
    1. twig compiler pass
    2. services
    3. routes
    4. doctrine
    5. migrations
    6. install deptrac
    7. configure deptrac
  2. Code Quality
    1. deptrac
    2. phpstan
  3. Test
    1. phpunit

Installation

composer require philipphermes/symfony-layered-architecture

Register Twig Compiler Pass

<?php

namespace App;

use PhilippHermes\Symfony\LayeredArchitecture\Shared\Twig\TwigPathCompilerPass;
use PhilippHermes\Symfony\LayeredArchitecture\Shared\Twig\TwigPathRegistrator\Plugin\BackendTwigRegistratorPlugin;
use PhilippHermes\Symfony\LayeredArchitecture\Shared\Twig\TwigPathRegistrator\Plugin\FrontendTwigRegistratorPlugin;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    /**
     * @inheritDoc
     */
    protected function build(ContainerBuilder $container): void
    {
        $twigPathCompilerPass = new TwigPathCompilerPass([
            //TwigRegistratorPlugins
            new BackendTwigRegistratorPlugin(),
            new FrontendTwigRegistratorPlugin(),
            //you can add your own ones e.g. when you have an additional layer like for merchants
        ]);
    
        $container->addCompilerPass($twigPathCompilerPass);
    }
}

Update services.yaml

parameters:

services:
  _defaults:
    autowire: true
    autoconfigure: true

  App\:
    resource: '../src/'
    exclude:
      - '../src/DependencyInjection/'
      - '../src/Kernel.php'
      - '../src/Backend/.+/Persistence/Entity/'
      - '../src/Generated/'

  PhilippHermes\Symfony\LayeredArchitecture\Shared\Routing\ControllerLoader:
    arguments:
      $classLoader: '@routing.loader.attribute'
      $projectDir: '%kernel.project_dir%'
    tags:
      - { name: routing.loader }

Update routes.yaml

modular_controllers:
    resource: .
    type: modular

Update doctrine.yaml

doctrine:
    ...
    orm:
        validate_xml_mapping: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        identity_generation_preferences:
            Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
        auto_mapping: true
        mappings:
            App:
                type: attribute
                is_bundle: false
                dir: '%kernel.project_dir%/src/Backend'
                prefix: 'App\Backend'
                alias: Backend
    ...

Update doctrine_migrations.yaml

doctrine_migrations:
    migrations_paths:
        'DoctrineMigrations': '%kernel.project_dir%/src/Generated/Migrations'
    enable_profiler: false

install deptrac:

composer require --dev deptrac/deptrac

Add deptrac.yaml to your project root:

deptrac:
    paths:
        - ./src
    exclude_files:
        - '#.*test.*#i'
    layers:
        -   name: Backend_Business
            collectors:
                -   type: directory
                    value: src/Backend/.+/Business/.*
        -   name: Backend_Persistence
            collectors:
                -   type: directory
                    value: src/Backend/.+/Persistence/.*
        -   name: Backend_Communication
            collectors:
                -   type: directory
                    value: src/Backend/.+/Communication/.*
        -   name: Backend_Presentation
            collectors:
                -   type: directory
                    value: src/Backend/.+/Presentation/.*
        -   name: Frontend_Controller
            collectors:
                -   type: directory
                    value: src/Frontend/.+/Controller/.*
        -   name: Frontend_Theme
            collectors:
                -   type: directory
                    value: src/Frontend/.+/Theme/.*
        -   name: Client
            collectors:
                -   type: directory
                    value: src/Client/.+/*
        -   name: Service
            collectors:
                -   type: directory
                    value: src/Service/.+/*
        -   name: Shared
            collectors:
                -   type: directory
                    value: src/Shared/.+/*
        -   name: Generated
            collectors:
                -   type: directory
                    value: src/Generated/*
        -   name: Doctrine
            collectors:
                -   type: classLike
                    value: ^Doctrine\\.*
        -   name: Vendor
            collectors:
                -   type: classLike
                    value: ^(Symfony|Psr|Monolog|Ramsey|League)\\.* #need to find a better solution

    ruleset:
        Backend_Business:
            - Backend_Business
            - Backend_Persistence
            - Service
            - Shared
            - Generated
            - Vendor
        Backend_Persistence:
            - Backend_Persistence
            - Service
            - Shared
            - Generated
            - Doctrine
            - Vendor
        Backend_Communication:
            - Backend_Communication
            - Backend_Business
            - Service
            - Shared
            - Generated
            - Vendor
        Backend_Presentation:
            - Backend_Presentation
        Frontend_Controller:
            - Frontend_Controller
            - Client
            - Service
            - Shared
            - Generated
            - Vendor
        Frontend_Theme:
            - Frontend_Theme
        Client:
            - Backend_Business
            - Client
            - Service
            - Shared
            - Generated
            - Vendor
        Service:
            - Service
            - Shared
            - Generated
            - Vendor
        Shared:
            - Shared
            - Generated
            - Vendor
        Generated:
            - Generated
            - Vendor
            - Doctrine # need this because of migrations

Code Quality

Deptrac

vendor/bin/deptrac

Phpstan

vendor/bin/phpstan analyse --memory-limit=1G

Test

Phpunit

vendor/bin/phpunit

# With coverage
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage-report

philipphermes/symfony-layered-architecture 适用场景与选型建议

philipphermes/symfony-layered-architecture 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 106 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 philipphermes/symfony-layered-architecture 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-18