本文へ移動
cccskills
無料GitHub で公開

acc-create-psr17-http-factory

Generates PSR-17 HTTP Factories implementation for PHP 8.5. Creates RequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ServerRequestFactoryInterface, UploadedFileFactoryInterface. Includes unit tests.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md5.4 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

PSR-17 HTTP Factories Generator

Overview

Generates PSR-17 compliant HTTP factory implementations for creating PSR-7 objects.

When to Use

  • Creating PSR-7 messages in DI containers
  • Testing HTTP interactions
  • Building HTTP frameworks
  • Decoupling from specific PSR-7 implementations

Template: HTTP Factory

<?php

declare(strict_types=1);

namespace App\Infrastructure\Http\Factory;

use App\Infrastructure\Http\Message\Request;
use App\Infrastructure\Http\Message\Response;
use App\Infrastructure\Http\Message\ServerRequest;
use App\Infrastructure\Http\Message\Stream;
use App\Infrastructure\Http\Message\UploadedFile;
use App\Infrastructure\Http\Message\Uri;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface;

final readonly class HttpFactory implements
    RequestFactoryInterface,
    ResponseFactoryInterface,
    ServerRequestFactoryInterface,
    StreamFactoryInterface,
    UploadedFileFactoryInterface,
    UriFactoryInterface
{
    public function createRequest(string $method, $uri): RequestInterface
    {
        return new Request(
            $method,
            $uri instanceof UriInterface ? $uri : $this->createUri($uri),
        );
    }

    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
    {
        return new Response($code, $reasonPhrase);
    }

    public function createServerRequest(
        string $method,
        $uri,
        array $serverParams = [],
    ): ServerRequestInterface {
        return new ServerRequest(
            $method,
            $uri instanceof UriInterface ? $uri : $this->createUri($uri),
            serverParams: $serverParams,
        );
    }

    public function createStream(string $content = ''): StreamInterface
    {
        return new Stream($content);
    }

    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
    {
        $resource = fopen($filename, $mode);

        if ($resource === false) {
            throw new \RuntimeException("Cannot open file: {$filename}");
        }

        return $this->createStreamFromResource($resource);
    }

    public function createStreamFromResource($resource): StreamInterface
    {
        $content = stream_get_contents($resource);

        if ($content === false) {
            throw new \RuntimeException('Cannot read from resource');
        }

        return new Stream($content);
    }

    public function createUploadedFile(
        StreamInterface $stream,
        ?int $size = null,
        int $error = UPLOAD_ERR_OK,
        ?string $clientFilename = null,
        ?string $clientMediaType = null,
    ): UploadedFileInterface {
        $tmpFile = tempnam(sys_get_temp_dir(), 'upload_');
        file_put_contents($tmpFile, (string) $stream);

        return new UploadedFile(
            $tmpFile,
            $size ?? $stream->getSize(),
            $error,
            $clientFilename,
            $clientMediaType,
        );
    }

    public function createUri(string $uri = ''): UriInterface
    {
        return Uri::fromString($uri);
    }
}

Usage Example

<?php

use App\Infrastructure\Http\Factory\HttpFactory;

$factory = new HttpFactory();

// Create request
$request = $factory->createRequest('GET', 'https://api.example.com/users');
$request = $request->withHeader('Accept', 'application/json');

// Create response
$response = $factory->createResponse(200);
$response = $response
    ->withHeader('Content-Type', 'application/json')
    ->withBody($factory->createStream(json_encode(['status' => 'ok'])));

// Create server request
$serverRequest = $factory->createServerRequest('POST', '/api/users', $_SERVER);

// Create URI
$uri = $factory->createUri('https://example.com/path?query=value');

// Create stream from file
$stream = $factory->createStreamFromFile('/path/to/file.txt');

DI Container Registration

<?php

// Symfony services.yaml
services:
    App\Infrastructure\Http\Factory\HttpFactory:
        public: true

    Psr\Http\Message\RequestFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

    Psr\Http\Message\ResponseFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

    Psr\Http\Message\StreamFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

    Psr\Http\Message\UriFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

    Psr\Http\Message\ServerRequestFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

    Psr\Http\Message\UploadedFileFactoryInterface:
        alias: App\Infrastructure\Http\Factory\HttpFactory

Requirements

{
    "require": {
        "psr/http-factory": "^1.1",
        "psr/http-message": "^2.0"
    }
}

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

MikeCheng1208 のスキルをすべて見る

このスキルの問題を報告する