Installation:
composer require ahuang/lorem-ipsum-bundle --dev
Add to config/bundles.php:
return [
// ...
AdamHuang\LoremIpsumBundle\LoremIpsumBundle::class => ['dev' => true],
];
First Use Case: Inject the service in a controller or service:
use AdamHuang\LoremIpsumBundle\Service\LoremIpsumService;
public function __construct(private LoremIpsumService $loremIpsum)
{
}
public function generatePlaceholder()
{
return $this->loremIpsum->generateParagraphs(3); // Generates 3 paragraphs
}
Configuration:
Check config/packages/adamhuang_lorem_ipsum.yaml for customization (e.g., word count, paragraph length).
Placeholder Generation:
LoremIpsumService::generateWords(5) for fake user names).generateParagraphs(2) for mock content in admin panels).Integration with Forms:
// In a form type
$builder->add('description', TextType::class, [
'data' => $this->loremIpsum->generateParagraphs(1),
]);
Dynamic Content:
$fakeData = [
'title' => $this->loremIpsum->generateSentence(),
'content' => $this->loremIpsum->generateParagraphs(2),
];
Service Layer Abstraction:
class CustomLoremService extends LoremIpsumService {
public function generateBlogPost(): array {
return [
'title' => $this->generateSentence(),
'excerpt' => $this->generateSentence(),
'body' => $this->generateParagraphs(5),
];
}
}
Dev-Only Bundle:
config/bundles.php). Explicitly enable it if needed:
['dev' => false, 'test' => true], // For testing environments
Limited Customization:
# config/packages/adamhuang_lorem_ipsum.yaml
adamhuang_lorem_ipsum:
word_list: ['@custom_word_list'] # DI reference
Thread Safety:
config/packages/adamhuang_lorem_ipsum.yaml for misconfigured paragraph_length or word_count settings.bundles.php and PHP version meets ^7.1.3.Custom Word Lists: Create a service to inject custom words:
$container->set('custom_word_list', new ArrayList(['custom', 'words', 'here']));
HTML Generation: Extend the service to wrap output in HTML tags:
class HtmlLoremService extends LoremIpsumService {
public function generateHtmlParagraphs(int $count): string {
return '<p>' . implode('</p><p>', array_map(fn($p) => $p, $this->generateParagraphs($count))) . '</p>';
}
}
Localization: Override the service to support non-Latin scripts (requires custom word lists).
How can I help you explore Laravel packages today?