1: <?php
2:
3: namespace Deimos\Flow;
4:
5: abstract class FlowFunction
6: {
7:
8: const REGEXP_CALLBACK = '[\w"\[\]\(\)\$-\>]+';
9: const REGEXP_VARIABLE = '\$[\w"\'\[\]\(\)\$-\>]+';
10:
11: /**
12: * @var array
13: */
14: public $data;
15:
16: /**
17: * @var Flow
18: */
19: public $flow;
20:
21: /**
22: * @var Configure
23: */
24: public $configure;
25:
26: /**
27: * FlowFunction constructor.
28: *
29: * @param Flow $flow
30: * @param Configure $configure
31: * @param array $data
32: */
33: public function __construct(Flow $flow, Configure $configure, array $data)
34: {
35: $this->flow = $flow;
36: $this->configure = $configure;
37: $this->data = $data;
38: }
39:
40: /**
41: * @param $variable
42: *
43: * @return string
44: */
45: protected function variable($variable)
46: {
47: $variable = preg_replace('~(\$)(.*)\.([\w-_]+)~', '$1$2[\'$3\']', $variable);
48:
49: return trim($variable, '"\' ');
50: }
51:
52: /**
53: * @return int
54: */
55: public function random()
56: {
57: return $this->flow->random();
58: }
59:
60: abstract public function view();
61:
62: }