-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.php
84 lines (63 loc) · 2.18 KB
/
example.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This is a simple script to show the example types in actions
*
* These types aren't meant to be product-ready, or even a good idea.
* They're merely examples of different inline object types.
*/
require_once dirname(__FILE__).'/../lib/InlineObjectAutoloader.php';
InlineObjectAutoloader::register();
/*
* 1) The Capitalize type
*/
require_once dirname(__FILE__).'/InlineObjectCapitalize.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectCapitalize('caps'));
$text = 'Capitalize the next [caps:word].';
render_value($text, $parser->parse($text), 'Capitalize');
/*
* 2) The Constant type
*/
require_once dirname(__FILE__).'/InlineObjectConstant.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectConstant('const'));
$text = '[const:M_PI]';
render_value($text, $parser->parse($text), 'Constant');
/*
* 3) The Date type
*/
require_once dirname(__FILE__).'/InlineObjectDate.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectDate('date'));
$text = '[date:year]';
render_value($text, $parser->parse($text), 'Date');
/*
* 4) The function type
*/
require_once dirname(__FILE__).'/InlineObjectFunction.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectFunction('fxn'));
$text = '[fxn:cos arg=3.1415926]';
render_value($text, $parser->parse($text), 'Function');
/*
* 5) The substring type
*/
require_once dirname(__FILE__).'/InlineObjectSubstring.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectSubstring('substring'));
$text = 'Return only a "[substring:portion length=4 start=2]" of a word.';
render_value($text, $parser->parse($text), 'Substring');
/*
* 6) The translation type
*/
require_once dirname(__FILE__).'/InlineObjectTranslate.php';
$parser = new InlineObjectParser();
$parser->addType(new InlineObjectTranslate('translate'));
$text = 'I could even [translate:"translate a phrase" from=en to=es] into spanish.';
render_value($text, $parser->parse($text), 'Translate');
// Helper method for outputting in a nice way
function render_value($raw, $value, $type)
{
echo sprintf('Testing the %s type: "%s"', $type, $raw)."\n\n";
echo ' ' . $value ."\n\n";
}