twLoremIpsumPlugin
0.5.0beta
for sf 1.4sf 1.3sf 1.2 MIT
False data generator with more-or-less normal distribution of letters
When it is necessary to generate test data for performance testing, or if you need to generate data for presentation purposes this plugin can be helpfull.
Feel free to contribute on github : twAdminPlugin
Developers
License
The MIT License
Copyright (c) 2010 Arkadiusz Tułodziecki
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.
twLoremIpsum plugin
False data generator with more-or-less normal distribution of letters
When it is necessary to generate test data for performance testing, or if you need to generate data for presentation purposes this plugin can be helpful.
Instalation
symfony plugin:install twLoremIpsumPlugin -s beta
Configuration
By default plugin uses own library of words and sentences fragments saved in json format. This files are:
This dictionary files are not to big and if for generation purposes bigger sets of data is needed - Special task to generate this kind of files is added to dis plugin.
For example with plugin you have files based of polish translattion of Homer Iliada book:
How to generate own dictionary files
Generating sentences file
symfony loremipsum:sentences-generator [--nonumeric[="..."]] source output
* Where optional --nonumeric gives information about possibility of numbers inside of sentences like:
There is 2 tree's in this garden.
Generating words file
symfony loremipsum:words-generator [--nonumeric[="..."]] [--regex[="..."]] source output
* Where optional --nonumeric gives information about possibility to use numbers as word in dictionary and optional --regex to add own filter for words
How to use own dictionary files
The fastes way is to put dictionary files to data folder of twLoremIpsumPlugin.
Setting sentences source file
$loremipsum = new twLoremIpsum();
$loremipsum->setSentencesSourceFile('my_sentences_data.json')
Setting words source file
$loremipsum = new twLoremIpsum();
$loremipsum->setWordsSourceFile('my_sentences_data.json')
How to use own set's of TLDS for URI generator
$mytlds = array('com', 'net', 'gov', 'com.pl', 'pl', 'org');
$loremipsum = new twLoremIpsum();
$loremipsum->setTlds($mytlds)
Usage
Best way to explain usability of this plugin is lots of examples. Plugin can be useful in task's and in modules.
Generating paragraphs
For Generating paragraphs we have 2 methods
generateParagraph($length = 10) - Where $length is mixed number of sentences
- Number of sentences in paragraph: if int or number of sentences to randomly select if array($min, $max)
- Returns string with paragraph
generateParagraphs($num, $length = 10) - Where $num is number of paragraphs to genearte and $length is mixed number of sentences in paragraphs
- Number of sentences in paragraph: if int or number of sentences to randomly select if array($min, $max)
- Returns array with paragraphs
Exaples
If we need to generate paragraph by with sentences betwean 3 to 10
$loremipsum = new twLoremIpsum();
$sentence = $loremipsum->generateParagraph(array(3, 10));
If we need to generate 10 paragraphs by default with sentences betwean 4 to 9 per paragraph
$loremipsum = new twLoremIpsum();
$sentences = $loremipsum->generateParagraphs(10, array(4, 9);
Generating sentences
For Generating sentences we have 2 methods
generateSentence($length = array(1, 3)) - Where $length is mixed number of sentences fragments seperated by ,
- Number of sub sentences in sentence: if int or number of sub sentences in sentence to randomly select if array($min, $max)
- Returns string with sentence
generateSentences($num, $length = array(1, 3)) - Where $num is number of sentences to genearte and $length is mixed number of sentences fragments seperated by ,
- Number of sub sentences in sentence: if int or number of sub sentences in sentence to randomly select if array($min, $max)
- Returns array with sentences
Exaples
If we need to generate sentence with 1 to 5 sentences fragments
$loremipsum = new twLoremIpsum();
$sentence = $loremipsum->generateSentence(array(1, 5));
If we need to generate 20 sentences with 2 to 4 sentences fragments
$loremipsum = new twLoremIpsum();
$sentences = $loremipsum->generateSentences(20, array(2, 4));
Generating words
For Generating words we have 4 methods
generateUniqueWord($length = 10, $namespace = 'default') - Where $length is mixed number of chars in word and $namespace is use for contener with used words to preserve uniq generation
- Number of letters in word: if int or number of letters in word to randomly select if array($min, $max)
- There is allways limit of unique words. If this limit will be reached Exception will be generated
- Returns string with word
generateUniqueWords($num, $length = 10, $namespace = 'default') - Where $num is number of words to genearte and $length is mixed number of chars in word and $namespace is use for contener with used words to preserve uniq generation
- Number of letters in word: if int or number of letters in word to randomly select if array($min, $max)
- There is allways limit of unique words. If this limit will be reached Exception will be generated
- Returns array with words
generateWord($length = 10) - Works almoust the same like generateUniqueWord but not checking if word was used
generateWords($num, $length = 10) - Works almoust the same like generateUniqueWords but not checking if word was used
Exaples
We need to generate 200 unique users with names betwean 5 to 20 letters in namespace users
$loremipsum = new twLoremIpsum();
$users = $loremipsum->generateUniqueWords(200, array(5, 20), 'users');
Generating unique strings
For Generating random unique strings we have 2 methods
generateUniqueString($length = 0, $namespace = 'default') - Where $length is mixed number of chars in string and $namespace is use for contener with used strings to preserve uniq generation
- Number of chars in string: if int or range of length to randomly select if array($min, $max)
- There is allways limit of unique string based on length. But if string have more then 8 chars then is hard to generate Exception for limit reached
- Returns string
generateUniqueStrings($num, $length = 0, $namespace = 'default') - Where $num is number of strings to genearte and $length is mixed number of chars in string and $namespace is use for contener with used strings to preserve uniq generation
- Number of chars in string: if int or range of length to randomly select if array($min, $max)
- There is allways limit of unique string based on length. But if string have more then 8 chars then is hard to generate Exception for limit reached
- Returns array of strings
Examples
Generating 1000 unique strings with string lenght changes from 5 to 10
$loremipsum = new twLoremIpsum();
$this->mystring = $loremipsum->generateUniqueStrings(1000, array(5, 10));
Generating random emails
For Generating random emails we have 2 methods
Generating random http links
Generating random IP address
Generating random created_at (timestampable) value
- generateRandomCreatedAt($year)
TODO
- Bytes generator - generating setup number of bytes
- Option to generate emails based on user name or words. In this moment only Rand sets of letters avaiable
- Option to generate url's based on words. In this moment only Rand sets of letters avaiable
- Better IP's generator