wardenyarn / loripsum
Simple https://loripsum.net API helper
1.3.1
2023-08-11 10:59 UTC
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^7.0
- symfony/css-selector: ^5.3 || ^6.0
- symfony/dom-crawler: ^5.3 || ^6.0
README
Simple https://loripsum.net API helper
Installation
You can install the package via composer:
composer require wardenyarn/loripsum
Usage
use Wardenyarn\Loripsum\Loremipsum; use Wardenyarn\Loripsum\Enums\Option; $lorem = new LoremIpsum(); $result = $lorem ->with([ Option::HEADERS, Option::UNORDERED_LIST, Option::BLOCKQUOTE, ]) ->long() ->paragraphs(10) ->withImages() // insert random images from placeholder.com ->html(); // html with 10 long paragraphs with headings (h1-h6), unordered lists and blockquotes // OR $lorem->random($max_paragraphs = 10)->html(); // html with randomly applied options and size
with()
Options
Wardenyarn\Loripsum\Enums\Option::AVAILABLE_OPTIONS; // Array of available options
Option::DECORATE
- Add bold, italic and marked text.Option::LINK
- Add links.Option::UNORDERED_LIST
- Add unordered lists.Option::ORDERED_LIST
- Add numbered lists.Option::DESCRIPTION_LIST
- Add description lists.Option::BLOCKQUOTE
- Add blockquotes.Option::CODE
- Add code samples.Option::HEADERS
- Add headers (h1-h6).Option::AS_PLAINTEXT
- Return result as plain text.Option::ALL_CAPS
- Return result in all uppercase letters.Option::PRUDE
- Avoid potentially offensive Latin words (applied as default, you can disable it withnotPrude()
method)
use Wardenyarn\Loripsum\Loremipsum; use Wardenyarn\Loripsum\Enums\Option; $lorem = new LoremIpsum(); $result = $lorem ->with([ Option::DECORATE, Option::LINK, Option::UNORDERED_LIST, ... ]) ->html();
Sizes
Wardenyarn\Loripsum\Enums\Size::AVAILABLE_SIZES; // Array of available sizes
Size::SHORT
Size::MEDIUM
Size::LONG
Size::VERY_LONG
use Wardenyarn\Loripsum\Loremipsum; use Wardenyarn\Loripsum\Enums\Size; $lorem = new LoremIpsum(); $result = $lorem ->short() ->medium() ->long() ->verylong() // OR ->size(Size::SHORT) ->html();
Images
use Wardenyarn\Loripsum\Loremipsum; $lorem = new LoremIpsum(); $result = $lorem ->withImages() // insert random images from placeholder.com ->imageChance(60) // Probability percent of inserting image after DOM node; Default: 30% ->html(); $result = $lorem ->withImages(['/src/1.jpg', '/src/2.jpg']) // Will use given images first ->html();
Misc
use Wardenyarn\Loripsum\Loremipsum; $lorem = new LoremIpsum(); $result = $lorem ->notPrude() // Will use potentially offensive Latin words ->html(); $result = $lorem ->allcaps() // Will uppercase all output ->html(); $result = $lorem->plaintext(); // Will strip tags
Trait
use Wardenyarn\Loripsum\WithLoremIpsum; class Example { use WithLoremIpsum; function factory() { return [ 'body' = $this->loremIpsum() // returns an instance of Wardenyarn\Loripsum\Loremipsum ->random() ->html(), ... ] } }
License
The MIT License (MIT). Please see License File for more information.