bambamboole/extended-faker
Composer 安装命令:
composer require --dev bambamboole/extended-faker
包简介
A FakerPHP extension providing realistic product, category, blog post, and fixture-backed page data across locales.
README 文档
README
PHP package extending FakerPHP/Faker with realistic product, category, blog post, and page data. Products are generated from compositional templates (effectively unlimited, trademark-free). Provides 19+ categories, 12 fixture-backed pages, and dynamically generates 1000+ unique blog posts with localized content across English (en_US) and German (de_DE).
Features
- Cross-language consistency: Same identifiers across locales with localized content
- Multiple data types: Products, categories, blog posts, and pages
- Dynamic blog post generation: Compositional template system generates 1000+ unique blog posts
- Markdown blog posts: Professional content with headings, code blocks, and rich formatting
- Fixture-backed pages: Named pages composed of structured Content blocks, renderable to Markdown or WordPress block markup
- Realistic data: Synthetic, trademark-free product names, descriptions, categories, and dynamically composed articles
- Deterministic generation: Same seed produces same blog post for reproducible testing
- Extensible: Easy to add new data via JSON template files
Installation
composer require bambamboole/extended-faker
Usage
Products
Products are generated deterministically from compositional templates, so
$faker->unique()->product() yields effectively unlimited unique products
(synthetic, trademark-free names like "Voltari Pulse 7 Pro 256GB Graphite").
use Faker\Factory; use Bambamboole\ExtendedFaker\Providers\en_US\Product; $faker = Factory::create('en_US'); $faker->addProvider(new Product($faker)); $product = $faker->product(); // random ProductDto $product = $faker->generateProduct(42); // deterministic by seed $same = $faker->productBySku($product->sku); // round-trips to the same product $de = $faker->getProductInLocale($product->sku, 'de_DE'); // same SKU, localized
Categories
use Bambamboole\ExtendedFaker\Providers\en_US\Category; $faker->addProvider(new Category($faker)); $category = $faker->category(); // Random category $categoryName = $faker->categoryName(); // "Electronics"
Blog Posts
use Bambamboole\ExtendedFaker\Providers\en_US\BlogPost; $faker->addProvider(new BlogPost($faker)); // Random blog post (dynamically generated) $post = $faker->blogPost(); // BlogPostDto with title, content, excerpt, tags, author, etc. // Specific blog post methods $title = $faker->blogPostTitle(); // "Getting Started with Docker in 2024" $content = $faker->blogPostContent(); // Full markdown content $excerpt = $faker->blogPostExcerpt(); // Short summary $tags = $faker->blogPostTags(); // ["docker", "devops", "containers"] $author = $faker->blogPostAuthor(); // "Michael Chen" $category = $faker->blogPostCategory(); // "technology" $readingTime = $faker->blogPostReadingTime(); // 2 (minutes) // Get post by dynamically generated slug $slug = $post->slug; $retrievedPost = $faker->blogPostBySlug($slug); // Cross-locale blog posts work with any generated slug $enPost = $faker->blogPost(); $dePost = $faker->getBlogPostInLocale($enPost->slug, 'de_DE');
Pages
use Bambamboole\ExtendedFaker\Providers\en_US\Page; use Bambamboole\ExtendedFaker\Page\PageType; $faker->addProvider(new Page($faker)); // Named fixture-backed page $page = $faker->page('about'); // PageDto with title, slug, content blocks, excerpt, template, seo, etc. // Typed page lookup $pricing = $faker->page(PageType::Pricing); $about = $faker->pageByType(PageType::About); // Render page content $content = $faker->pageContent('about'); // Markdown content $blocks = $faker->pageBlockContent('about'); // WordPress block markup $seo = $faker->pageSeo('about'); // SEO title and description // Cross-locale pages work with shared slugs $dePage = $faker->getPageInLocale($page->slug, 'de_DE'); $aboutPage = $faker->pageBySlug('about', 'en_US');
Using ExtendedFaker Helper
For convenience, use the ExtendedFaker::extend() method to register all providers at once:
use Faker\Factory; use Bambamboole\ExtendedFaker\ExtendedFaker; // Automatically registers Product, Category, BlogPost, and Page providers $faker = Factory::create('en_US'); ExtendedFaker::extend($faker, 'en_US'); // Now use any provider $product = $faker->product(); $category = $faker->category(); $blogPost = $faker->blogPost(); $page = $faker->page(); // German locale $fakerDe = Factory::create('de_DE'); ExtendedFaker::extend($fakerDe, 'de_DE');
Available Methods
Product Provider
productName(?string $identifier = null): stringproductDescription(?string $identifier = null): stringproductCategory(?string $identifier = null): stringproduct(?string $identifier = null): ProductDtogenerateProduct(int $seed, ?string $category = null, ?string $locale = null): ProductDtoproductBySku(string $sku, ?string $locale = null): ProductDtogetProductInLocale(string $sku, string $locale): ProductDto
Category Provider
categoryName(?string $identifier = null): stringcategory(?string $identifier = null): array
BlogPost Provider
blogPostTitle(?string $identifier = null): stringblogPostContent(?string $identifier = null): stringblogPostExcerpt(?string $identifier = null): stringblogPostCategory(?string $identifier = null): stringblogPostTags(?string $identifier = null): arrayblogPostAuthor(?string $identifier = null): stringblogPostReadingTime(?string $identifier = null): intblogPost(?string $identifier = null): BlogPostDtoblogPostBySlug(string $slug, ?string $locale = null): BlogPostDtogetBlogPostSlug(string $title): stringgetBlogPostInLocale(string $slug, string $locale): BlogPostDto
Page Provider
pageTitle(string|PageType|null $identifier = null): stringpageContent(string|PageType|null $identifier = null): stringpageBlockContent(string|PageType|null $identifier = null, ?WordPressBlockOptions $options = null): stringpageExcerpt(string|PageType|null $identifier = null): stringpageTemplate(string|PageType|null $identifier = null): stringpageSeo(string|PageType|null $identifier = null): arraypage(string|PageType|null $identifier = null): PageDtopageByType(PageType $page, ?string $locale = null): PageDtopageBySlug(string $slug, ?string $locale = null): PageDtogetPageSlug(string $title): stringgetPageInLocale(string $slug, string $locale): PageDto
Data Structure
Categories and pages are stored as JSON files. Products and blog posts are dynamically generated from composable templates:
resources/
├── categories/
│ ├── cell-phones-smartphones.json
│ ├── electronics.json
│ └── ...
├── pages/
│ ├── about.json
│ ├── contact.json
│ └── ...
└── blog-templates/
├── titles.json // Title patterns by category
├── introductions.json // Opening paragraph templates
├── sections.json // Body content blocks by category
├── conclusions.json // Closing paragraph templates
├── code-examples.json // Code snippets for tech posts
└── metadata.json // Authors, tags, topics, dates
Blog Post Generation
Blog posts are dynamically generated using a compositional template system that mixes and matches components:
- 1000+ unique combinations from template patterns
- Deterministic generation: Same seed always produces the same post
- Category-specific content: Technology, Business, Travel, Lifestyle
- Automatic slug generation from titles
- Reading time calculation based on word count (200 words/minute)
- 3-5 minute reads: Short, focused blog posts (150-350 words)
Available Categories: Technology, Business, Travel, Lifestyle
Each generated post includes:
- Unique title and slug
- Category-appropriate introduction
- 4-5 content sections
- Conclusion
- 3-5 relevant tags
- Random author name
- Published date (2023-2024)
- Calculated reading time
- Optional code examples (technology posts)
Fixture Images
Every product, category, and page exposes a small, copyright-safe comic image
(bold-outline SVG rasterized to WebP, committed under resources/images/).
$faker->productImageDto(); // ImageDto -> images/products/{category}/{n}.webp $faker->productImage(); // path, e.g. "images/products/cell-phones-smartphones/3.webp" $faker->category()['image']; // "images/categories/electronics.webp" $faker->page('about')->image; // "images/pages/about.webp" $faker->pageImage('about'); // same path
Each generated product gets a committed WebP matching its category and colour: every
category's comic motif is rendered in each palette, and a product points to the palette
that matches its colour (so products sharing a category and colour share an image). The
ImageDto exposes the relative path plus the resolved absolute path and file metadata. The
shipped package only reads the committed WebP files. To regenerate the set, run
npm install && composer images:build — rasterization uses Node + sharp.
See the creating-fixture-images skill for the motif system.
Requirements
- PHP 8.3+
- fakerphp/faker ^1.24
- league/commonmark ^2.7
- symfony/yaml ^7.3
Testing
composer test # run the test suite composer test:coverage # run with coverage composer test:lint # check code style (Pint) composer analyse # static analysis (PHPStan)
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email manuel@christlieb.eu instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
bambamboole/extended-faker 适用场景与选型建议
bambamboole/extended-faker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51.97k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「faker」 「fixtures」 「testing」 「seeding」 「bambamboole」 「fakerphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bambamboole/extended-faker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bambamboole/extended-faker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bambamboole/extended-faker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing object factory for PHP
Testing Suite For Lumen like Laravel does.
Testing object factory for PHP
Plugin to compare fixtures with live DB tables
Symfony bundle to manage fixtures with Alice and Faker.
Additional plugin for fakerphp/faker that allows you to generate a random animal
统计信息
- 总下载量: 51.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-20