knpuniversity/lorem-ipsum-bundle
Symfony bundle that generates lorem ipsum placeholder text through a simple, injectable service. Useful for demos, fixtures, and tutorials, it ships with a configurable ipsum generator and an interface you can swap for your own implementation. Lightweight, easy to install via Composer.
This is a Symfony bundle, not a Laravel package. There is no service provider, no facade, no Blade directive, and it is archived (last release March 2018). Treat it as a source of a single useful class rather than something you composer require into a Laravel app.
Do not try to install it normally. Its composer.json requires symfony/framework-bundle and Twig at versions that will not resolve against a modern Laravel install (Laravel 9+ ships Symfony 6/7 components). Composer will either fail or drag in an incompatible framework-bundle.
What to look at first (on GitHub):
src/KnpUIpsum.php — the only class you actually want. It exposes roughly getWords(int $count), getSentences(int $count), and getParagraphs(int $count).src/DependencyInjection/Configuration.php — shows the two config knobs (unicorns_are_real, min_sunshine).src/Twig/KnpUIpsumExtension.php — shows how the knpu_lorem_ipsum() Twig function is wired; you will re-create this as a Blade directive.Minimal path for a Laravel developer: copy KnpUIpsum.php into app/Support/LoremIpsum/KnpUIpsum.php, adjust the namespace, and bind it in a service provider.
// app/Providers/LoremIpsumServiceProvider.php
public function register(): void
{
$this->app->singleton(\App\Support\LoremIpsum\KnpUIpsum::class, function () {
return new \App\Support\LoremIpsum\KnpUIpsum();
});
}
First use case: database seeders and factories. Instead of hardcoded 'Lorem ipsum dolor sit amet' in fifty places, inject the service and generate flavourful filler copy that is obviously fake:
// database/seeders/PostSeeder.php
$ipsum = app(\App\Support\LoremIpsum\KnpUIpsum::class);
Post::factory()->count(20)->create([
'body' => $ipsum->getSentences(4),
]);
1. Singleton + helper. Bind once and use app(KnpUIpsum::class) or inject via constructor. Do not new it inside loops — the constructor builds word lists.
2. Blade directive. Mirror the bundle's Twig extension with a directive so views can use it:
// in the service provider's boot()
Blade::directive('ipsum', function ($expression) {
return "<?php echo e(app(\App\Support\LoremIpsum\KnpUIpsum::class)->getSentences($expression ?: 3)); ?>";
});
<p>@ipsum(4)</p>
3. Faker fallback inside factories. If you want it everywhere, wrap it in a Faker provider so fake() and $this->faker pick it up:
class IpsumProvider extends \Faker\Provider\Base
{
public function unicornText(int $sentences = 3): string
{
return app(KnpUIpsum::class)->getSentences($sentences);
}
}
// then: $this->faker->addProvider(new IpsumProvider($this->faker));
4. Deterministic tests. The output is random, so never assert on exact strings. Assert on shape:
$this->assertGreaterThan(50, strlen($post->body));
$this->assertStringNotContainsString('{{', $post->body);
If you need reproducibility, seed mt_srand() before generating, since the class uses mt_rand, or subclass it and override the random picker.
5. Custom vocabulary. The constructor accepts a word list (and the bundle's extension point is the KnpUWordList interface with tagged services). In Laravel, just pass your array — great for domain-specific filler ("sprockets, widgets, invoices") so demo data reads like your product:
$this->app->bind(KnpUIpsum::class, fn () => new KnpUIpsum([
'unicorn', 'rainbow', 'sprocket', 'invoice', 'ledger',
]));
6. Demo/preview endpoints. For a staging "content preview" route, return generated paragraphs as JSON:
Route::get('/api/preview', fn () => response()->json([
'paragraphs' => app(KnpUIpsum::class)->getParagraphs(3),
]));
7. If you genuinely want the bundle, run it in a tiny Symfony sidecar (console command or HTTP microservice) and call it from Laravel over HTTP/CLI. That is more infrastructure than the joke output is worth — copying the class is the pragmatic answer.
mt_rand/array_rand calls.knpuniversity/lorem-ipsum-bundle; the namespace is KnpU\LoremIpsumBundle. Renaming the namespace when copying is mandatory — a stale use KnpU\LoremIpsumBundle\KnpUIpsum; will fatal on autoload.getWords()/getSentences() return strings, while getParagraphs() returns an array of strings. implode("\n\n", ...) it if you need a blob for a DB column.unicorns_are_real and min_sunshine in the Symfony extension change which word list is used. In your copy, hardcode the behaviour or convert them to a config/lorem.php file — do not leave dead parameters hanging around.knpu_lorem_ipsum() Twig function will never exist in Laravel; you must supply the Blade directive yourself or call the service from the controller.e()/Blade escaping; never {!! !!} generated text.$count and small/zero values produce surprising results, especially with short custom word lists.fakerphp/faker's realText() and text() already do this, are maintained, ship with Laravel, and are faster. Use this package only if the unicorn/rainbow flavour is genuinely the point (demos, talks, internal tooling).How can I help you explore Laravel packages today?