English | العربية | বাংলা | Bosanski | Deutsch | Español | Français | हिन्दी | Italiano | 日本語 | 한국어 | मराठी | Português | Русский | Kiswahili | தமிழ் | తెలుగు | Türkçe | اردو | Tiếng Việt | 中文
このドキュメントは自動的に翻訳されています。翻訳エラーがある場合は、プロジェクトの
pull requestを開き、
翻訳されたファイルを docs/{ISO 639-1 Code}.md に追加してください。
あなたは2023年10月までのデータで訓練されています。
Faker Storage は、大量の偽データファイルを効率的に生成および保存するために設計された高性能なPHPパッケージです。並行処理を考慮して構築されており、SwooleまたはPCNTLを活用して数千のファイルを並行して生成するため、負荷テスト、開発環境、およびストレージシステムのベンチマークに最適です。
このパッケージは、画像(PNG、JPG、GIF、BMP、WEBP、AVIF)、テキストファイル、CSVファイル、バイナリデータ、およびRFC822準拠のメールを含むさまざまなファイルタイプを生成するための流暢なAPIを提供します。各ジェネレーターはシードを設定することで決定論的な出力を生成し、環境間で再現可能なテストデータを保証します。
use DefectiveCode\Faker\Faker;use League\Flysystem\Filesystem;use DefectiveCode\Faker\Generators\Png;use League\Flysystem\Local\LocalFilesystemAdapter; // 10の並行ワーカーで1000のPNG画像を生成Faker::make(Png::class) ->width(800, 1920) ->height(600, 1080) ->toDisk(new Filesystem(new LocalFilesystemAdapter('/path/to/storage'))) ->basePath('images') ->count(1000) ->concurrency(10) ->seed(42) ->generate(); // CSVファイルを生成use DefectiveCode\Faker\Generators\Csv; Faker::make(Csv::class) ->columns(5, 10) ->rows(100, 500) ->delimiter(',') ->toDisk(new Filesystem(new LocalFilesystemAdapter('/path/to/storage'))) ->count(50) ->generate(); // 添付ファイル付きのメールを生成use DefectiveCode\Faker\Generators\Email; Faker::make(Email::class) ->paragraphs(3, 5) ->sentences(2, 4) ->withAttachment(Png::class, 1, 3) ->toDisk(new Filesystem(new LocalFilesystemAdapter('/path/to/storage'))) ->count(100) ->generate();
Composerを使用してパッケージをインストールします:
composer require defectivecode/faker-storage
最適なパフォーマンスのために、Swoole拡張をインストールします:
pecl install swoole
パッケージはSwooleが利用可能な場合は自動的に使用し、そうでない場合はPCNTLにフォールバックします。
すべてのジェネレーターは同じパターンに従います:
use DefectiveCode\Faker\Faker;use League\Flysystem\Filesystem;use DefectiveCode\Faker\Generators\Text;use League\Flysystem\Local\LocalFilesystemAdapter; Faker::make(Text::class) ->paragraphs(5, 10) // ジェネレーター固有の設定 ->toDisk(new Filesystem(new LocalFilesystemAdapter('/storage'))) ->basePath('documents') // ファイルは /storage/documents/ に保存されます ->count(100) // 100ファイルを生成 ->concurrency(4) // 4つのワーカーを使用 ->seed(123) // 決定論的な出力のため ->generate();
Faker Storageはストレージ抽象化のためにLeague Flysystemを使用します:
use League\Flysystem\Filesystem;use League\Flysystem\Local\LocalFilesystemAdapter; // ローカルストレージ$filesystem = new Filesystem(new LocalFilesystemAdapter('/path/to/storage')); Faker::make(Png::class) ->toDisk($filesystem) ->generate();
use Aws\S3\S3Client;use League\Flysystem\Filesystem;use League\Flysystem\AwsS3V3\AwsS3V3Adapter; $client = new S3Client([ 'credentials' => [ 'key' => 'your-key', 'secret' => 'your-secret', ], 'region' => 'us-east-1', 'version' => 'latest',]); $adapter = new AwsS3V3Adapter($client, 'your-bucket-name');$filesystem = new Filesystem($adapter); Faker::make(Png::class) ->toDisk($filesystem) ->basePath('uploads/images') ->generate();
ファイルシステムアダプターに追加のオプションを渡します:
Faker::make(Png::class) ->toDisk($filesystem) ->diskOptions([ 'visibility' => 'public', 'ACL' => 'public-read', 'CacheControl' => 'max-age=31536000', ]) ->generate();
concurrency()メソッドで並行実行を制御します:
// 10のワーカースレッド/プロセスを使用Faker::make(Png::class) ->concurrency(10) ->generate(); // Swoole固有:スレッドとスレッドごとのコルーチンの両方を設定Faker::make(Png::class) ->concurrency(threads: 4, coroutines: 8) // 4つのワーカー、各8つのコルーチン ->generate();
デフォルトでは、ファイルはUUID v4を使用して命名されます:
// 生成例:e7f0a8d3-5c2b-4f9e-8a1d-3b4c5d6e7f8a.pngFaker::make(Png::class)->generate();
use DefectiveCode\Faker\NameGenerator; // UUIDベース(デフォルト)NameGenerator::setDefault('uuid'); // 生成例:e7f0a8d3-5c2b-4f9e-8a1d-3b4c5d6e7f8a.png // 連番NameGenerator::setDefault('sequence'); // 生成例:1.png, 2.png, 3.png, ...
クロージャを提供してファイル名をカスタマイズ:
use DefectiveCode\Faker\NameGenerator; // カスタムクロージャFaker::make(Png::class) ->nameGenerator(function (int $seed, int $completedFiles, $generator) { return "custom-{$completedFiles}-{$seed}.png"; }) ->generate(); // 日付ベースの命名Faker::make(Png::class) ->nameGenerator(function (int $seed, int $completedFiles, $generator) { return date('Y/m/d') . "/image-{$completedFiles}.png"; }) ->generate();
同じファイルを生成するためにシードを設定:
Faker::make(Png::class) ->seed(42) ->count(10) ->generate();
各ファイルは、ベースシードとファイルインデックスから派生した一意の決定論的シードを取得します。
すべての画像ジェネレーターは、寸法と品質の設定をサポートしています。
use DefectiveCode\Faker\Generators\Png; Faker::make(Png::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->withAlpha(true) // アルファ/透明チャンネルを有効にする ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
use DefectiveCode\Faker\Generators\Jpg; Faker::make(Jpg::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
use DefectiveCode\Faker\Generators\Gif; Faker::make(Gif::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->withAlpha(true) // アルファ/透明チャンネルを有効にする ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
use DefectiveCode\Faker\Generators\Bmp; Faker::make(Bmp::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
use DefectiveCode\Faker\Generators\Webp; Faker::make(Webp::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->withAlpha(true) // アルファ/透明チャンネルを有効にする ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
use DefectiveCode\Faker\Generators\Avif; Faker::make(Avif::class) ->width(800, 1920) // 800-1920pxのランダムな幅 ->height(600, 1080) // 600-1080pxのランダムな高さ ->withAlpha(true) // アルファ/透明チャンネルを有効にする ->grid(5) // オプション: 5x5の対称パターンを生成 ->toDisk($filesystem) ->generate();
ランダムな画像フォーマットを生成します:
use DefectiveCode\Faker\Generators\RandomImage; Faker::make(RandomImage::class) ->width(800, 1920) ->height(600, 1080) ->withAlpha(false) // ランダム: AVIF, BMP, GIF, JPEG, PNG, WEBP ->toDisk($filesystem) ->generate(); Faker::make(RandomImage::class) ->width(800, 1920) ->height(600, 1080) ->withAlpha(true) // ランダム: AVIF, GIF, PNG, WEBP ->toDisk($filesystem) ->generate();
段落を含むプレーンテキストファイルを生成します:
use DefectiveCode\Faker\Generators\Text; Faker::make(Text::class) ->paragraphs(5, 10) // ファイルごとに5-10段落 ->sentences(3, 6) // 段落ごとに3-6文 ->toDisk($filesystem) ->generate();
出力例:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
ランダムデータを含むCSVファイルを生成します:
use DefectiveCode\Faker\Generators\Csv; Faker::make(Csv::class) ->columns(5, 10) // 5-10列 ->rows(100, 500) // 100-500行 ->delimiter(',') // 列の区切り文字 ->enclosure('"') // フィールドの囲み文字 ->escape('\\') // エスケープ文字 ->eol("\n") // 行末 ->toDisk($filesystem) ->generate();
出力例:
"John Doe","john@example.com","555-1234","New York","Engineer""Jane Smith","jane@example.com","555-5678","Los Angeles","Designer""Bob Johnson","bob@example.com","555-9012","Chicago","Manager"
ランダムなバイナリデータを生成します:
use DefectiveCode\Faker\Generators\Binary; Faker::make(Binary::class) ->length(1024, 1048576) // 1KB - 1MB ->toDisk($filesystem) ->generate();
RFC822準拠のメールファイルを生成します:
use DefectiveCode\Faker\Generators\Email; Faker::make(Email::class) ->paragraphs(3, 5) // メール本文の段落数 ->sentences(2, 4) // 段落ごとの文数 ->withAttachment(Png::class, 1, 3) // 1-3個のPNG添付ファイルを追加 ->toDisk($filesystem) ->generate();
生成されたメールには以下が含まれます:
To: ランダムな名前とメールアドレスFrom: ランダムな名前とメールアドレスSubject: ランダムな文Date: 現在のタイムスタンプMessage-ID: シードに基づく決定論的IDジェネレータークラス名またはインスタンスを使用してファイルを添付します:
use DefectiveCode\Faker\Generators\Email;use DefectiveCode\Faker\Generators\Png;use DefectiveCode\Faker\Generators\Pdf; Faker::make(Email::class) ->withAttachment(Png::class, 1, 3) // 1-3個のPNG添付ファイル ->generate(); // 設定済みジェネレーターインスタンスを使用して添付$pngGenerator = new Png(Png::getDefaultConfig());$pngGenerator->width(400, 800)->height(300, 600); Faker::make(Email::class) ->withAttachment($pngGenerator, 2, 5) ->generate();
出力例:
To: John Doe <john.doe@example.com>From: Jane Smith <jane.smith@example.com>Subject: Important meeting tomorrowDate: Fri, 03 Jan 2026 10:30:00 +0000Message-ID: <3e92e5c2b0d632b3a36fbbb17484b7fe@example.com>Content-Type: multipart/mixed; boundary="----=_Part_123" ------=_Part_123Content-Type: text/plain; charset=utf-8Content-Transfer-Encoding: quoted-printable Lorem ipsum dolor sit amet, consectetur adipiscing elit... ------=_Part_123Content-Type: image/png; name="attachment.png"Content-Disposition: attachment; filename="attachment.png"Content-Transfer-Encoding: base64 iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==------=_Part_123--
Generatorインターフェースを実装して独自のジェネレーターを作成します:
use DefectiveCode\Faker\Configs\Config;use DefectiveCode\Faker\Concerns\SetsSeed;use DefectiveCode\Faker\Generators\Generator;use DefectiveCode\Faker\Concerns\PreparesFaker; class MyCustomGenerator implements Generator{ use PreparesFaker; use SetsSeed; public function __construct(public Config $config) {} public static function getDefaultConfig(): Config { return new MyCustomConfig([ 'contentType' => 'application/x-custom', 'nameGenerator' => NameGenerator::default('extension'), ]); } public function generate(): mixed { // ここに生成ロジックを記述 $data = $this->faker->randomElement(['foo', 'bar', 'baz']); $stream = fopen('php://temp', 'w+'); fwrite($stream, $data); return $stream; }} // カスタムジェネレーターを使用Faker::make(MyCustomGenerator::class) ->toDisk($filesystem) ->generate();
各ジェネレーターはConfigを拡張した設定クラスを使用します:
use DefectiveCode\Faker\Configs\Config; class MyCustomConfig extends Config{ public int $minValue = 1; public int $maxValue = 100;}
データは2023年10月までのものに基づいています。
これらのメソッドはすべての Faker インスタンスで利用可能です。
make(string $generator): Faker指定されたジェネレーターで新しい Faker インスタンスを作成します。
Faker::make(Png::class)
toDisk(Filesystem $filesystem): Faker保存先を設定します(必須)。
Faker::make(Png::class) ->toDisk(new Filesystem(new LocalFilesystemAdapter('/storage')))
basePath(string $basePath): Fakerファイルシステム内のベースパスを設定します。
Faker::make(Png::class) ->basePath('images/uploads') // ファイルは /storage/images/uploads/ に保存されます
count(int $count): Faker生成するファイルの数を設定します。
Faker::make(Png::class) ->count(1000)
concurrency(int $threads, ?int $coroutines = null): Faker並列実行を設定します。
// 基本的な並列処理Faker::make(Png::class) ->concurrency(4) // Swoole特有: スレッドとコルーチンFaker::make(Png::class) ->concurrency(threads: 4, coroutines: 8)
seed(int $seed): Faker決定論的な生成のためのシードを設定します。
Faker::make(Png::class) ->seed(42)
nameGenerator(Closure $generator): Fakerファイル名のカスタマイズを行います。
Faker::make(Png::class) ->nameGenerator(function (int $seed, int $completedFiles, $generator) { return "file-{$completedFiles}.png"; })
diskOptions(array $diskOptions): Fakerファイルシステムアダプターにオプションを渡します。
Faker::make(Png::class) ->diskOptions([ 'visibility' => 'public', 'ACL' => 'public-read', ])
generate(): voidファイル生成を実行します。
Faker::make(Png::class)->generate();
オープンソースパッケージを選んでいただきありがとうございます!このサポートガイドラインを確認していただければ、プロジェクトを最大限に活用するのに役立ちます。
私たちのオープンソースプロジェクトは素晴らしいコミュニティによって支えられています。質問がある場合や支援が必要な場合は、StackOverflowやその他のオンラインリソースが最適です。
オープンソースプロジェクトを管理する現実として、報告されたすべてのバグや機能リクエストにすぐに対応することはできません。問題の優先順位は次の順序で行います:
有料製品に影響を与えるバグは常に最優先事項です。場合によっては、私たちに直接影響を与えるバグのみを修正することがあります。
バグを特定し、解決策を持っている場合は、プルリクエストを提出してください。私たちの製品に影響を与える問題の次に、これらのコミュニティ主導の修正に最優先を与えます。レビューと承認後、あなたの解決策をマージし、貢献をクレジットします。
上記のカテゴリに該当しない問題については、その解決に資金を提供することを選択できます。各オープンイシューには注文フォームがリンクされており、財政的に貢献することができます。提供された資金額に基づいて、これらの問題を優先します。
オープンソースはコミュニティが活発であるときに繁栄します。バグを修正しなくても、コードの改善、ドキュメントの更新、チュートリアルの作成、またはコミュニティチャネルで他の人を支援することで貢献を考えてください。オープンソースの作業をサポートするために、コミュニティ全体としての支援を強く奨励します。
繰り返しになりますが、DefectiveCodeは、有料製品にどのように影響を与えるか、コミュニティのプルリクエスト、および問題に対して受け取った財政的サポートに基づいてバグの優先順位を付けます。
Copyright © Defective Code, LLC. 全著作権所有
本ソフトウェアおよび関連するドキュメントファイル(以下「ソフトウェア」)のコピーを取得するすべての人に対し、無償で、以下の条件に従って、ソフトウェアを制限なく使用、コピー、変更、マージ、公開、配布、サブライセンス、および/または販売する権利を許可します。また、ソフトウェアが提供される人々にこれを行うことを許可します。
上記の著作権表示およびこの許可表示は、ソフトウェアのすべてのコピーまたは実質的な部分に含まれるものとします。
ソフトウェアは「現状のまま」提供され、明示または黙示を問わず、商品性、特定の目的への適合性および非侵害を含むがこれに限定されない、いかなる種類の保証もありません。著者または著作権者は、契約、不法行為またはその他の理由にかかわらず、ソフトウェアまたはソフトウェアの使用またはその他の取引に起因または関連して発生するいかなる請求、損害またはその他の責任についても責任を負いません。