承接 ksfraser/superglobals 相关项目开发

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

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

ksfraser/superglobals

Composer 安装命令:

composer require ksfraser/superglobals

包简介

A PHP library for testable superglobal access with SRP design

README 文档

README

A PHP library that provides testable, dependency-injectable access to superglobals ($_GET, $_POST, $_FILES, etc.) following the Single Responsibility Principle.

Installation

composer require ksfraser/superglobals

Usage

Basic Usage

use Ksfraser\Superglobals\PostParameterProvider;
use Ksfraser\Superglobals\FormSubmission;

// Inject the parameter provider
$parameterProvider = new PostParameterProvider();
$formSubmission = new FormSubmission($parameterProvider);

// Use in your application logic
if ($formSubmission->hasUpload()) {
    $parser = $formSubmission->getParser();
    $bankAccount = $formSubmission->getBankAccount();
    // ... handle upload logic
}

Testing

The library is designed to be easily testable by injecting mock parameter providers:

use Ksfraser\Superglobals\FormSubmission;
use Ksfraser\Superglobals\ParameterProvider;

class MockParameterProvider implements ParameterProvider {
    private $data;

    public function __construct(array $data) {
        $this->data = $data;
    }

    public function get(string $key): ?string {
        return $this->data[$key] ?? null;
    }

    public function has(string $key): bool {
        return isset($this->data[$key]);
    }

    public function all(): array {
        return $this->data;
    }
}

// Test your form handling logic
$form = new FormSubmission(new MockParameterProvider([
    'upload' => '1',
    'parser' => 'QFX',
    'bank_account' => '123'
]));

assert($form->hasUpload() === true);
assert($form->getParser() === 'QFX');

Architecture

The library follows SOLID principles:

  • Single Responsibility: Each class has one reason to change
  • Open/Closed: Classes are open for extension but closed for modification
  • Liskov Substitution: Implementations can be substituted for the interface
  • Interface Segregation: Clients depend only on methods they use
  • Dependency Inversion: High-level modules don't depend on low-level modules

Classes

ParameterProvider Interface

Abstracts access to parameter arrays (like $_GET, $_POST).

PostParameterProvider

Concrete implementation for $_POST superglobal.

GetParameterProvider

Concrete implementation for $_GET superglobal.

FormSubmission

Handles form submission logic with dependency injection for testability.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

This project is licensed under the GPL-3.0-or-later License - see the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固