ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\Utils\JsFunctionsScanner Class Reference
+ Inheritance diagram for Gettext\Utils\JsFunctionsScanner:
+ Collaboration diagram for Gettext\Utils\JsFunctionsScanner:

Public Member Functions

 __construct ($code)
 Constructor. More...
 
 getFunctions ()
 {} More...
 
- Public Member Functions inherited from Gettext\Utils\FunctionsScanner
 getFunctions ()
 Scan and returns the functions and the arguments. More...
 
 saveGettextFunctions (array $functions, Translations $translations, $file='')
 Search for specific functions and create translations. More...
 

Protected Member Functions

 status ($match=null)
 Get the current context of the scan. More...
 
 downStatus ($status)
 Add a new status to the stack. More...
 
 upStatus ()
 Removes and return the current status. More...
 

Static Protected Member Functions

static prepareArgument ($argument)
 Prepares the arguments found in functions. More...
 

Protected Attributes

 $code
 
 $status = array()
 

Detailed Description

Definition at line 5 of file JsFunctionsScanner.php.

Constructor & Destructor Documentation

◆ __construct()

Gettext\Utils\JsFunctionsScanner::__construct (   $code)

Constructor.

Parameters
string$codeThe php code to scan

Definition at line 15 of file JsFunctionsScanner.php.

References Gettext\Utils\JsFunctionsScanner\$code.

16  {
17  $this->code = $code;
18  }

Member Function Documentation

◆ downStatus()

Gettext\Utils\JsFunctionsScanner::downStatus (   $status)
protected

Add a new status to the stack.

Parameters
string$status

Definition at line 186 of file JsFunctionsScanner.php.

References Gettext\Utils\JsFunctionsScanner\$status, and Gettext\Utils\JsFunctionsScanner\status().

Referenced by Gettext\Utils\JsFunctionsScanner\getFunctions().

187  {
188  array_unshift($this->status, $status);
189  }
status($match=null)
Get the current context of the scan.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFunctions()

Gettext\Utils\JsFunctionsScanner::getFunctions ( )

{}

Definition at line 23 of file JsFunctionsScanner.php.

References array, Gettext\Utils\JsFunctionsScanner\downStatus(), Gettext\Utils\JsFunctionsScanner\status(), and Gettext\Utils\JsFunctionsScanner\upStatus().

24  {
25  $length = strlen($this->code);
26  $line = 1;
27  $buffer = '';
28  $functions = array();
29  $bufferFunctions = array();
30  $char = null;
31 
32  for ($pos = 0; $pos < $length; ++$pos) {
33  $prev = $char;
34  $char = $this->code[$pos];
35  $next = isset($this->code[$pos]) ? $this->code[$pos] : null;
36 
37  switch ($char) {
38  case "\n":
39  ++$line;
40 
41  if ($this->status('line-comment')) {
42  $this->upStatus();
43  }
44  break;
45 
46  case '/':
47  switch ($this->status()) {
48  case 'simple-quote':
49  case 'double-quote':
50  case 'line-comment':
51  break;
52 
53  case 'block-comment':
54  if ($prev === '*') {
55  $this->upStatus();
56  }
57  break;
58 
59  default:
60  if ($next === '/') {
61  $this->downStatus('line-comment');
62  } elseif ($next === '*') {
63  $this->downStatus('block-comment');
64  }
65  break;
66  }
67  break;
68 
69  case "'":
70  switch ($this->status()) {
71  case 'simple-quote':
72  $this->upStatus();
73  break;
74 
75  case 'line-comment':
76  case 'block-comment':
77  case 'double-quote':
78  break;
79 
80  default:
81  $this->downStatus('simple-quote');
82  break;
83  }
84  break;
85 
86  case '"':
87  switch ($this->status()) {
88  case 'double-quote':
89  $this->upStatus();
90  break;
91 
92  case 'line-comment':
93  case 'block-comment':
94  case 'simple-quote':
95  break;
96 
97  default:
98  $this->downStatus('double-quote');
99  break;
100  }
101  break;
102 
103  case '(':
104  switch ($this->status()) {
105  case 'double-quote':
106  case 'line-comment':
107  case 'block-comment':
108  case 'line-comment':
109  break;
110 
111  default:
112  if ($buffer && preg_match('/(\w+)$/', $buffer, $matches)) {
113  $this->downStatus('function');
114  array_unshift($bufferFunctions, array($matches[1], $line, array()));
115  $buffer = '';
116  continue 3;
117  }
118  break;
119  }
120  break;
121 
122  case ')':
123  switch ($this->status()) {
124  case 'function':
125  if (($argument = self::prepareArgument($buffer))) {
126  $bufferFunctions[0][2][] = $argument;
127  }
128 
129  if (!empty($bufferFunctions)) {
130  $functions[] = array_shift($bufferFunctions);
131  }
132 
133  $buffer = '';
134  continue 3;
135  }
136 
137  case ',':
138  switch ($this->status()) {
139  case 'function':
140  if (($argument = self::prepareArgument($buffer))) {
141  $bufferFunctions[0][2][] = $argument;
142  }
143 
144  $buffer = '';
145  continue 3;
146  }
147  }
148 
149  switch ($this->status()) {
150  case 'line-comment':
151  case 'block-comment':
152  break;
153 
154  default:
155  $buffer .= $char;
156  break;
157  }
158  }
159 
160  return $functions;
161  }
status($match=null)
Get the current context of the scan.
downStatus($status)
Add a new status to the stack.
upStatus()
Removes and return the current status.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ prepareArgument()

static Gettext\Utils\JsFunctionsScanner::prepareArgument (   $argument)
staticprotected

Prepares the arguments found in functions.

Parameters
string$argument
Returns
string

Definition at line 208 of file JsFunctionsScanner.php.

209  {
210  if ($argument && ($argument[0] === '"' || $argument[0] === "'")) {
211  if ($argument[0] === '"') {
212  $argument = str_replace('\\"', '"', $argument);
213  } else {
214  $argument = str_replace("\\'", "'", $argument);
215  }
216 
217  return substr($argument, 1, -1);
218  }
219  }

◆ status()

Gettext\Utils\JsFunctionsScanner::status (   $match = null)
protected

Get the current context of the scan.

Parameters
null | string$matchTo check whether the current status is this value
Returns
string|bool

Definition at line 170 of file JsFunctionsScanner.php.

References Gettext\Utils\JsFunctionsScanner\$status.

Referenced by Gettext\Utils\JsFunctionsScanner\downStatus(), Gettext\Utils\JsFunctionsScanner\getFunctions(), and Gettext\Utils\JsFunctionsScanner\upStatus().

171  {
172  $status = isset($this->status[0]) ? $this->status[0] : null;
173 
174  if ($match !== null) {
175  return $status === $match;
176  }
177 
178  return $status;
179  }
status($match=null)
Get the current context of the scan.
+ Here is the caller graph for this function:

◆ upStatus()

Gettext\Utils\JsFunctionsScanner::upStatus ( )
protected

Removes and return the current status.

Returns
string|null

Definition at line 196 of file JsFunctionsScanner.php.

References Gettext\Utils\JsFunctionsScanner\status().

Referenced by Gettext\Utils\JsFunctionsScanner\getFunctions().

197  {
198  return array_shift($this->status);
199  }
status($match=null)
Get the current context of the scan.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $code

Gettext\Utils\JsFunctionsScanner::$code
protected

Definition at line 7 of file JsFunctionsScanner.php.

Referenced by Gettext\Utils\JsFunctionsScanner\__construct().

◆ $status

Gettext\Utils\JsFunctionsScanner::$status = array()
protected

The documentation for this class was generated from the following file: