Defective Code Logo

Total Downloads Latest Stable Version Latest Stable Version

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로 대체합니다.

사용법

기본 워크플로우

모든 생성기는 동일한 패턴을 따릅니다:

  1. 생성기로 Faker 인스턴스 생성
  2. 생성기 구성 (선택 사항)
  3. 저장소 목적지 설정
  4. 동시성 및 개수 구성
  5. 파일 생성
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();

저장소 구성

Flysystem 사용

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();

AWS S3 저장소

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.png
Faker::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();

각 파일은 기본 시드와 파일 인덱스에서 파생된 고유한 결정론적 시드를 받습니다.

생성기

이미지 생성기

모든 이미지 생성기는 크기 및 품질 구성을 지원합니다.

PNG

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();

JPG

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();

GIF

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();

BMP

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();

WEBP

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();

AVIF

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 생성기

랜덤 데이터가 포함된 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();

이메일 헤더

생성된 이메일에는 다음이 포함됩니다:

첨부 파일이 있는 이메일

생성기 클래스 이름이나 인스턴스를 사용하여 파일 첨부:

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 tomorrow
Date: Fri, 03 Jan 2026 10:30:00 +0000
Message-ID: <3e92e5c2b0d632b3a36fbbb17484b7fe@example.com>
Content-Type: multipart/mixed; boundary="----=_Part_123"
 
------=_Part_123
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
 
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
 
------=_Part_123
Content-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;
}

성능 팁

  1. Swoole 사용: 최고의 성능을 위해 Swoole 확장을 설치하세요
  2. 동시성 조정: 최적의 처리량을 위해 스레드 수를 CPU 코어에 맞추세요
  3. 배치 작업: 여러 번의 작은 실행보다는 큰 배치를 생성하세요
  4. 저장 위치: 업로드 전에 임시 파일을 위해 빠른 저장소(SSD, 로컬 디스크)를 사용하세요
  5. 네트워크 I/O: S3를 사용할 때는 대역폭 사용을 극대화하기 위해 동시성을 증가시키세요

당신은 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 및 기타 온라인 리소스가 가장 좋은 선택입니다.

버그 및 기능 우선순위

오픈 소스 프로젝트를 관리하는 현실은 모든 보고된 버그나 기능 요청을 즉시 처리할 수 없다는 것입니다. 우리는 다음과 같은 순서로 문제를 우선시합니다:

1. 유료 제품에 영향을 미치는 버그

유료 제품에 영향을 미치는 버그는 항상 최우선 순위입니다. 경우에 따라서는 우리에게 직접 영향을 미치는 버그만 처리할 수도 있습니다.

2. 커뮤니티 풀 리퀘스트

버그를 식별하고 해결책을 찾았다면 풀 리퀘스트를 제출해 주세요. 우리 제품에 영향을 미치는 문제 다음으로 이러한 커뮤니티 주도의 수정 사항에 높은 우선순위를 부여합니다. 검토 및 승인 후, 귀하의 솔루션을 병합하고 기여를 인정하겠습니다.

3. 재정적 지원

언급된 범주 외의 문제에 대해서는 해결을 위해 자금을 지원할 수 있습니다. 각 오픈 이슈는 재정적으로 기여할 수 있는 주문 양식과 연결되어 있습니다. 우리는 제공된 자금의 양에 따라 이러한 문제를 우선시합니다.

커뮤니티 기여

오픈 소스는 커뮤니티가 활발할 때 번성합니다. 버그를 수정하지 않더라도 코드 개선, 문서 업데이트, 튜토리얼 작성, 커뮤니티 채널에서 다른 사람을 돕는 등의 방법으로 기여를 고려해 보세요. 우리는 모든 사람이 커뮤니티로서 오픈 소스 작업을 지원하는 것을 적극 권장합니다.

다시 말하지만, DefectiveCode는 유료 제품에 미치는 영향, 커뮤니티 풀 리퀘스트, 문제에 대한 재정적 지원을 기준으로 버그의 우선순위를 정할 것입니다.

라이선스 - MIT 라이선스

저작권 © Defective Code, LLC. 모든 권리 보유

본 소프트웨어 및 관련 문서 파일(이하 "소프트웨어")의 사본을 취득하는 모든 사람에게 사용, 복사, 수정, 병합, 출판, 배포, 서브라이선스 및/또는 소프트웨어의 사본을 판매할 권리를 포함하여 제한 없이 소프트웨어를 처리할 수 있는 권한을 무료로 부여합니다. 단, 다음 조건을 충족해야 합니다:

위의 저작권 고지와 이 허가 고지는 소프트웨어의 모든 사본 또는 상당 부분에 포함되어야 합니다.

본 소프트웨어는 "있는 그대로" 제공되며, 상품성, 특정 목적에의 적합성 및 비침해에 대한 보증을 포함하여 명시적이거나 묵시적인 어떠한 종류의 보증도 제공되지 않습니다. 어떠한 경우에도 저자 또는 저작권 보유자는 계약, 불법 행위 또는 기타 행위로 인해 발생하는 모든 청구, 손해 또는 기타 책임에 대해 책임을 지지 않습니다. 소프트웨어 또는 소프트웨어 사용 또는 기타 거래와 관련하여 발생하는 경우도 포함됩니다.