team-mate-pro/infra-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

team-mate-pro/infra-bundle

Composer 安装命令:

composer require team-mate-pro/infra-bundle

包简介

Infrastructure verification bundle for Symfony applications

README 文档

README

Version: 1.4.0 Type: symfony-bundle

Infrastructure verification bundle for Symfony applications. Provides a base command for verifying server configuration before deployment.

Installation

composer require team-mate-pro/infra-bundle:^1.0

Configuration

Register the bundle in config/bundles.php:

return [
    // ...
    TeamMatePro\InfraBundle\TeamMateProInfraBundle::class => ['all' => true],
];

Usage

Create a verification command by extending AbstractInfraVerifyCommand:

<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use TeamMatePro\InfraBundle\Command\AbstractInfraVerifyCommand;

#[AsCommand(
    name: 'app:infra:verify',
    description: 'Verify infrastructure configuration',
)]
final class InfraVerifyCommand extends AbstractInfraVerifyCommand
{
    protected function verify(): void
    {
        // Add your verification logic here
    }
}

Run the command:

php bin/console app:infra:verify

Available Verifiers

section(string $title)

Creates a visual section in the output.

$this->section('PHP Extensions');

verifyPhpExtension(string $name, ?string $description = null)

Checks if a PHP extension is loaded.

$this->verifyPhpExtension(name: 'pdo_mysql');
$this->verifyPhpExtension(name: 'gd', description: 'image processing');

verifyPhpIniSetting(string $name, string $expectedValue, ?string $description = null)

Checks if a PHP ini setting has the expected value. Normalizes boolean-like values (On/Off/1/0/true/false).

// Sentry - stack trace arguments
$this->verifyPhpIniSetting('zend.exception_ignore_args', 'Off', 'Sentry stack trace arguments');

// Memory limit
$this->verifyPhpIniSetting('memory_limit', '256M');

// Display errors off in production
$this->verifyPhpIniSetting('display_errors', 'Off', 'must be disabled in production');

verifyEnvVariable(string $name, ?string $description = null, ?string $expectedValue = null)

Checks if an environment variable is set. Optionally validates expected value.

// Check if set
$this->verifyEnvVariable(name: 'APP_SECRET');

// Check with description
$this->verifyEnvVariable(name: 'DATABASE_URL', description: 'database connection');

// Check exact value
$this->verifyEnvVariable(
    name: 'APP_ENV',
    expectedValue: 'prod',
);

// Full example
$this->verifyEnvVariable(
    name: 'SSO_AUTH_URL',
    description: 'frontend redirects here for login',
    expectedValue: 'https://login.example.com/',
);

verifyBinary(array $command, ?string $description = null)

Checks if a system binary is available and executable.

$this->verifyBinary(
    command: ['/usr/bin/wkhtmltopdf', '--version'],
    description: 'PDF generation',
);

$this->verifyBinary(
    command: ['node', '--version'],
    description: 'Node.js runtime',
);

verifyDatabaseConnection(int $timeoutSeconds = 5)

Verifies MySQL database connection using DATABASE_URL environment variable.

Note: If ext-pdo is not loaded, shows [WARN] and skips the check instead of failing.

$this->verifyDatabaseConnection();
$this->verifyDatabaseConnection(timeoutSeconds: 10);

verifyHttpConnection(string $url, ?string $description = null, int $expectedStatusCode = 200, int $timeoutSeconds = 5)

Checks HTTP endpoint and validates response status code.

$this->verifyHttpConnection(
    url: 'https://api.example.com/health',
    description: 'API health check',
);

$this->verifyHttpConnection(
    url: 'https://api.example.com/status',
    expectedStatusCode: 204,
    timeoutSeconds: 10,
);

verifyHttpConnectionHandshake(string $url, ?string $description = null, int $timeoutSeconds = 5)

Checks if HTTP endpoint is reachable (any response is OK). Use this when you only need to verify network connectivity.

$this->verifyHttpConnectionHandshake(
    url: 'https://login.example.com/oauth2/jwks',
    description: 'SSO JWKS endpoint',
);

$this->verifyHttpConnectionHandshake(
    url: 'https://external-api.example.com/',
    description: 'External API',
    timeoutSeconds: 10,
);

Example Command

<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use TeamMatePro\InfraBundle\Command\AbstractInfraVerifyCommand;

#[AsCommand(
    name: 'app:infra:verify',
    description: 'Verify infrastructure configuration',
)]
final class InfraVerifyCommand extends AbstractInfraVerifyCommand
{
    protected function verify(): void
    {
        $this->section('PHP Extensions');
        $this->verifyPhpExtension(name: 'pdo_mysql', description: 'database');
        $this->verifyPhpExtension(name: 'intl', description: 'internationalization');

        $this->section('Environment Variables');
        $this->verifyEnvVariable(name: 'APP_ENV', expectedValue: 'prod');
        $this->verifyEnvVariable(name: 'APP_SECRET');
        $this->verifyEnvVariable(name: 'DATABASE_URL');

        $this->section('System Binaries');
        $this->verifyBinary(
            command: ['/usr/bin/wkhtmltopdf', '--version'],
            description: 'PDF generation',
        );

        $this->section('Services');
        $this->verifyDatabaseConnection();

        $this->section('External Connections');
        $this->verifyHttpConnectionHandshake(
            url: 'https://api.example.com/',
            description: 'External API',
        );
    }
}

Output Example

Infrastructure Verification
===========================

PHP Extensions
--------------
[OK] ext-pdo_mysql (database)
[OK] ext-intl (internationalization)

Environment Variables
---------------------
[OK] APP_ENV
[OK] APP_SECRET
[OK] DATABASE_URL

System Binaries
---------------
[OK] /usr/bin/wkhtmltopdf (PDF generation)

Services
--------
[OK] MySQL connection

External Connections
--------------------
[OK] https://api.example.com/ (External API)

 [OK] All infrastructure checks passed

Requirements

  • PHP 8.3+
  • Symfony 7.0+

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固