wardenyarn/ loripsum
简单的https://loripsum.net API 辅助工具
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
简单的https://loripsum.net API 辅助工具
安装
您可以通过composer安装此包
composer require wardenyarn/loripsum
使用方法
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()
选项
Wardenyarn\Loripsum\Enums\Option::AVAILABLE_OPTIONS; // Array of available options
Option::DECORATE
- 添加粗体、斜体和标记文本。Option::LINK
- 添加链接。Option::UNORDERED_LIST
- 添加无序列表。Option::ORDERED_LIST
- 添加有序列表。Option::DESCRIPTION_LIST
- 添加描述列表。Option::BLOCKQUOTE
- 添加引用。Option::CODE
- 添加代码示例。Option::HEADERS
- 添加标题(h1-h6)。Option::AS_PLAINTEXT
- 返回纯文本结果。Option::ALL_CAPS
- 返回全部大写字母的结果。Option::PRUDE
- 避免潜在的冒犯性拉丁词汇(默认应用,您可以通过notPrude()
方法禁用它)
use Wardenyarn\Loripsum\Loremipsum; use Wardenyarn\Loripsum\Enums\Option; $lorem = new LoremIpsum(); $result = $lorem ->with([ Option::DECORATE, Option::LINK, Option::UNORDERED_LIST, ... ]) ->html();
大小
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();
图片
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();
杂项
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
特质
use Wardenyarn\Loripsum\WithLoremIpsum; class Example { use WithLoremIpsum; function factory() { return [ 'body' = $this->loremIpsum() // returns an instance of Wardenyarn\Loripsum\Loremipsum ->random() ->html(), ... ] } }
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。