-
Notifications
You must be signed in to change notification settings - Fork 0
/
7-structure.php
49 lines (42 loc) · 1.22 KB
/
7-structure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php file_exists('../vendor/autoload.php') ? require '../vendor/autoload.php' : exit;
use Nabeghe\Tepade\Tepade;
use Nabeghe\Tepade\Validators;
function structure($text)
{
Tepade::structure(
[
// substructure 1
[
// patterns
['The package name is {name}', 'My package name is {name}'],
// callback
function (array $params, ?string $text) {
echo "The package name = `$params[name]`\n";
echo "The package name from index 0 = `$params[0]`\n";
},
// validators
null,
],
// substructure 2 : class mode
NumberCallback::class => [
// pattern
'The number is {number}',
// validators
['number' => Validators::NUMERIC],
],
],
// text
$text,
// custom args
null,
);
}
class NumberCallback
{
public static function on(array $params, ?string $text)
{
echo "The number = $params[number]\n";
}
}
structure('My package name is nabeghe/text-params-detector');
structure('The number is 14');