Skip to content

Commit 3791c99

Browse files
committed
Create README.md
1 parent a5ce654 commit 3791c99

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# DynamicString
2+
3+
> Generate random strings from templates.
4+
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lastguest/DynamicString/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lastguest/DynamicString/?branch=master)
6+
7+
## Installation
8+
9+
Install via [composer](https://getcomposer.org/download/):
10+
11+
```bash
12+
$ composer require lastguest/dynamic-string -o
13+
```
14+
15+
### How to use
16+
17+
```php
18+
$generator = new DynamicString();
19+
echo $generator->render("I want a (fried|double|spicy) (tuna|salmon|crab) (sushi|(ura|te)maki), please.");
20+
```
21+
22+
### Templates
23+
24+
Use `()` for define a group that will be replaced by one of the contained alternatives, random selected.
25+
26+
The `|` character is used as a separator for multiple choices.
27+
28+
29+
This template will render `Yes` or `No` randomly :
30+
31+
```
32+
(Yes|No)
33+
```
34+
35+
Groups can be nested, they will resolved with a deep-first order.
36+
37+
This template will render `Finger`, `Fingers`, `Hand`, `Hands` randomly :
38+
39+
```
40+
(Finge(r|rs)|Han(d|ds))
41+
```
42+
43+
A complete template for generate random Sushi orders :
44+
45+
```
46+
I want a (fried|double|spicy) (tuna|salmon|crab) (sushi|(ura|te)maki), please.
47+
```
48+
49+
Some outputs :
50+
51+
```
52+
I want a spicy salmon sushi, please.
53+
I want a double tuna uramaki, please.
54+
I want a double salmon temaki, please.
55+
I want a spicy crab sushi, please.
56+
```
57+
58+
### Changing default group envelope and separator
59+
60+
You can change the default group envelope and separator in the `DynamicString` constructor.
61+
62+
```php
63+
$generator = new DynamicString('<>',',');
64+
echo $generator->render("<public,protected,private> function(<string,array,callable> myVar){};");
65+
```
66+
67+
Output:
68+
69+
```
70+
private function(array myVar){};
71+
```
72+
73+
## License (MIT)
74+
75+
Copyright (c) 2015 Stefano Azzolini
76+
77+
Permission is hereby granted, free of charge, to any person
78+
obtaining a copy of this software and associated documentation
79+
files (the "Software"), to deal in the Software without
80+
restriction, including without limitation the rights to use,
81+
copy, modify, merge, publish, distribute, sublicense, and/or sell
82+
copies of the Software, and to permit persons to whom the
83+
Software is furnished to do so, subject to the following
84+
conditions:
85+
86+
The above copyright notice and this permission notice shall be
87+
included in all copies or substantial portions of the Software.
88+
89+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
91+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
92+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
93+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
94+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
96+
OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)