match() public static method

Token pattern matching.
public static match ( string $code, string $parameters, array $options = [] ) : array
$code string Source code to be analyzed.
$parameters string An array containing token patterns to be matched.
$options array The list of options to be used when matching `$code`: - 'ignore': An array of language tokens to ignore. - 'return': If set to 'content' returns an array of matching tokens.
return array Array of matching tokens.
Ejemplo n.º 1
0
 public function testTokenPatternMatching()
 {
     $code = '$defaults = array("id" => "foo", "name" => "bar", \'count\' => 5);';
     $result = Parser::match($code, array('"string"'), array('return' => 'content'));
     $expected = array('"id"', '"foo"', '"name"', '"bar"', '\'count\'');
     $this->assertEqual($expected, $result);
     $result = Parser::match($code, array('"string"' => array('before' => '=>'), '1' => array('before' => '=>')), array('return' => 'content'));
     $expected = array('"foo"', '"bar"', '5');
     $this->assertEqual($expected, $result);
     $result = Parser::match($code, array('"string"' => array('after' => '=>')), array('return' => 'content'));
     $expected = array('"id"', '"name"', '\'count\'');
     $this->assertEqual($expected, $result);
 }