intellex/generator
Composer 安装命令:
composer require intellex/generator
包简介
README 文档
README
Examples and full list of supported generators below.
Image:
- Image URL generator from Pixabay service (requires free API key).
Core:
- Boolean generator with selectable chance of true.
- Get a number in range, with or without Gaussian distribution.
- Random item from weighted array, allows you to manipulate chances.
- Random date time from a period, in any format.
Text and HTML:
- Generate random strings from custom or predefined pools of characters.
- Lorem ipsum text generator that supports: single word, variable length sentences, full paragraphs and complete articles.
- Full HTML generator for decorated sentences, paragraphs or full-out article with images (requires free Pixabay API key).
Bonus
- Generate a GPS coordinate, that is a maximum of meters away from any center you choose.
- A hardcoded generator that always returns the same results, just for good measure :)
Examples
Tip: After cloning, point browser to tests/index.php to see every possible result.
Image:
echo '<img src="' . (new PixabayImageURLGen($pixabayAPIKey, [ 'q' => 'kitten' ], PixabayImageURLGen::SIZE_960))->gen() . '" />';
GPS location within 3000 meters from the city centre of Amsterdam, Netherlands:
(new \Intellex\Generator\Plus\GpsLocationGen(52.3677607, 4.8785829, 3000));
Boolean with 50% chance of true:
(new BooleanGen())->gen();
Boolean with 80% chance of true:
(new BooleanGen(0.8))->gen();
Random number in range of 50 - 250:
(new NumericGen(50, 250))->gen();
Random number of mean 38 and mean 5 (Gaussian distribution):
(new GaussianDistributionGen(38, 4))->gen();
Random item from array:
(new ItemGen([ 1, 2, 3, 5, 7, 11 ]))->gen();
Random weighted item from array, where is 2 times more likely than B and 6 times more likely than C:
(new WeightedItemGen([ 'A' => 6, 'B' => 3, 'C' => 1 ]))->gen();
Full HTML article, with images:
(new HTMLArticleGen(true, $pixabayAPIKey))->gen();
List of all generators
Core:
- BooleanGen generates a boolean value, with the ability to give more chances to any of the results.
- NumericGen generates a random number in a specified range.
- GaussianDistributionGen uses a normal distribution to pick a random value in a range.
- HardcodedGen uses the value supplied in the constructor as a generated value, every time.
- ItemGen picks an item from the pool, where every item has the same change of being picked.
- WeightedItemGen picks a random item from the pool, with the ability to influence the change of picking for each item.
Bonus:
- GpsLocationGen generates a GPS location, within a supplied radius of a given central point. Output format is ,, with a maximum of 6 decimal digit precision.
- PixabayImageURLGen generates a URL to a random image on the Pixabay free image service, using their API.
Time:
- TimestampGen generates a random timestamp in a given range.
- DateTimeGen generates a random date in YYYY-MM-DD hh:mm:ss format.
- DateGen generates a random date in YYYY-MM-DD format.
- TimeGen generates a time in 24h format.
Strings and text:
- StringGen generates a random string.
- WordGen generates a single word, from a predefined "lorem ipsum" dictionary.
- SentenceGenerator generates a dummy sentence.
- ParagraphGen generates a random paragraph from random sentences.
- ArticleGen generates a random article form random paragraphs.
HTML:
- HTMLSentenceGen generates a random sentences with random HTML tags, such as b, strong, em, etc...
- HTMLParagraphGen generates a valid HTML paragraph.
- HTMLSectionGen generates an HTML header with random paragraphs.
- HTMLArticleGen generates a complete HTML article.
To do
- Testing of the results.
- Better implementation of the WeightedItemGen.
- Setters for all constructor parameters for all generators.
- New generators.
Licence
MIT License
Copyright (c) 2019 Intellex
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Credits
Script has been written by the Intellex team.
intellex/generator 适用场景与选型建议
intellex/generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 intellex/generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 intellex/generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-09