smartbooster/core-bundle

将所有供应商、通用工具和服务打包在一起,这些是我们每个项目中使用的

安装次数: 2,145

依赖者: 1

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

类型:symfony-bundle

v1.13.1 2024-09-24 15:23 UTC

README

将所有供应商、通用工具和服务打包在一起,这些是我们每个项目中使用的

CI

里面有什么!

  • 配置 IniOverrideConfig 服务,轻松覆盖 php.ini 选项
  • 监控路由,用于正常运行时间跟踪、phpinfo 调试等
  • DataFixtures 抽象助手
  • 查询函数以扩展 Doctrine DQL 功能
  • SentryCallback 具有特殊的 CleverCloud 专用行为
  • Array、Date、Math、Regex 和 String 的实用工具
  • EmailChain、Modulo、Password 等验证约束

安装

composer require smartbooster/core-bundle

启用监控路由

要启用监控路由,请将以下代码添加到您的 config/routes.yaml 文件中

_smart_core:
    resource: .
    type: smart_core
    # We recommand to restrict thoses routes on a secure subdomain 
    host: "admin.%domain%"

路径 ^/anonymous 必须在项目的 security.yaml 配置中具有 PUBLIC_ACCESS,以便探测路由可以无用户访问

# security.yaml
access_control:
    - { path: ^/anonymous, roles: PUBLIC_ACCESS }

额外 DQL 函数

根据您的缺失功能需求,将以下代码添加到您的 config/packages/doctrine.yaml 文件中

doctrine:
    # ...
    orm:
        # ...
        dql:
            string_functions:
                group_concat: Smart\CoreBundle\Query\MySQL\GroupConcat

Sentry 配置

要使用我们的 SentryCallback,请将以下内容添加到您的 config/packages/sentry.yaml 文件中

when@prod:
    sentry:
        dsn: '%env(SENTRY_DSN)%'
        options:
            environment: '%env(ENVIRONMENT)%'
            before_send: 'sentry.callback.before_send'
            integrations:
                - 'Sentry\Integration\IgnoreErrorsIntegration'
        register_error_listener: false

services:
    Sentry\Integration\IgnoreErrorsIntegration:
        arguments:
            $options:
                ignore_exceptions:
                    - 'Symfony\Component\Security\Core\Exception\AccessDeniedException'
    sentry.callback.before_send:
        class: 'Smart\CoreBundle\Sentry\SentryCallback'
        factory: [ '@Smart\CoreBundle\Sentry\SentryCallback', 'getBeforeSend' ]

同时,在您的 config/packages/monolog.yaml 文件中声明以下内容

when@prod:
    monolog:
        handlers:
            # other handlers
            sentry:
                type: service
                id: Sentry\Monolog\Handler

并在您的 services.yaml 中定义 Sentry\Monolog\Handler 服务

services:
    # other services
    Sentry\Monolog\Handler:
        arguments:
            $hub: '@Sentry\State\HubInterface'
            $level: !php/const Monolog\Logger::ERROR

Nelmio 安全建议

我们建议在 nelmio 安全配方生成的配置基础上设置内容安全策略

nelmio_security:
    # ...
    
    # Content Security Policy
    csp:
        enabled: true
        hosts: []
        content_types: []
        enforce:
            # see full description below
            level1_fallback: true
            # only send directives supported by the browser, defaults to false
            # this is a port of https://github.com/twitter/secureheaders/blob/83a564a235c8be1a8a3901373dbc769da32f6ed7/lib/secure_headers/headers/policy_management.rb#L97
            browser_adaptive:
                enabled: true
            # this is a full list of known case, you must keep only useful script in project
            script-src:
                - 'self'
                - 'unsafe-inline'
                - 'unsafe-eval'
                - 'https://maps.googleapis.com'
                - 'https://use.fontawesome.com'
                - 'https://#'
                - 'https://www.youtube.com'
                - 'https://www.youtube-nocookie.com'
                - 'https://js.stripe.com'
                - 'https://canny.io/'
                - 'https://www.google.com/'
                - 'https://www.gstatic.com/'
                - 'https://code.iconify.design'
                - 'https://cdn.jsdelivr.net.cn'
                - 'https://#'
                - 'https://#'
            block-all-mixed-content: true # defaults to false, blocks HTTP content over HTTPS transport

贡献

欢迎提交拉取请求。

感谢 所有已经做出贡献的人

本项目由 SmartBooster 支持