Skip to content

Commit 82b039d

Browse files
committed
Initial draft of expander mechanism with StartsWith expander example
Replaced [] with array() in AST\Expander class for php 5.3 support Refactoring Added Boolean and Null argument types support Added negative numbers support Added argument to StartsWith expander Set Lexer as a dependency of Parser and Parser as a dependency of StringMatcher Added possibility to add new expander definitions Added notBlank expander Changed expanderName definition Added lowerThan expander Implement expanders in IntegerMatcher Added expanders to DoubleMatcher Added GreaterThan expander Added EndsWith expander Renamed NotBlank into NotEmpty Added array argument type support Added InArray expander Added Contains expander
1 parent 7809ef4 commit 82b039d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2300
-80
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"php": ">=5.3.0",
1818
"coduo/php-to-string": "~1.0",
1919
"symfony/property-access": "~2.3",
20-
"symfony/expression-language": "~2.4"
20+
"symfony/expression-language": "~2.4",
21+
"doctrine/lexer": "1.0.*"
2122
},
2223
"require-dev": {
2324
"phpunit/phpunit": "3.7.*"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\AST;
4+
5+
class Expander implements Node
6+
{
7+
/**
8+
* @var
9+
*/
10+
private $name;
11+
12+
/**
13+
* @var array
14+
*/
15+
private $arguments;
16+
17+
/**
18+
* @param $name
19+
*/
20+
public function __construct($name)
21+
{
22+
$this->name = $name;
23+
$this->arguments = array();
24+
}
25+
26+
/**
27+
* @return mixed
28+
*/
29+
public function getName()
30+
{
31+
return $this->name;
32+
}
33+
34+
/**
35+
* @param $argument
36+
*/
37+
public function addArgument($argument)
38+
{
39+
$this->arguments[] = $argument;
40+
}
41+
42+
/**
43+
* @return bool
44+
*/
45+
public function hasArguments()
46+
{
47+
return (boolean) count($this->arguments);
48+
}
49+
50+
/**
51+
* @return array
52+
*/
53+
public function getArguments()
54+
{
55+
return $this->arguments;
56+
}
57+
}

src/Coduo/PHPMatcher/AST/Node.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\AST;
4+
5+
interface Node
6+
{
7+
8+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\AST;
4+
5+
class Pattern implements Node
6+
{
7+
/**
8+
* @var Type
9+
*/
10+
private $type;
11+
12+
/**
13+
* @var Expander[]|array
14+
*/
15+
private $expanders;
16+
17+
/**
18+
* @param Type $type
19+
*/
20+
public function __construct(Type $type)
21+
{
22+
$this->expanders = array();
23+
$this->type = $type;
24+
}
25+
26+
/**
27+
* @return mixed
28+
*/
29+
public function getType()
30+
{
31+
return $this->type;
32+
}
33+
34+
/**
35+
* @return bool
36+
*/
37+
public function hasExpanders()
38+
{
39+
return (boolean) count($this->expanders);
40+
}
41+
42+
/**
43+
* @return Expander[]|array
44+
*/
45+
public function getExpanders()
46+
{
47+
return $this->expanders;
48+
}
49+
50+
/**
51+
* @param Expander $expander
52+
*/
53+
public function addExpander(Expander $expander)
54+
{
55+
$this->expanders[] = $expander;
56+
}
57+
}

src/Coduo/PHPMatcher/AST/Type.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\AST;
4+
5+
class Type implements Node
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $type;
11+
12+
/**
13+
* @param string $type
14+
*/
15+
public function __construct($type)
16+
{
17+
$this->type = $type;
18+
}
19+
20+
public function __toString()
21+
{
22+
return $this->type;
23+
}
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\Exception;
4+
5+
class Exception extends \Exception
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\Exception;
4+
5+
class InvalidExpanderTypeException extends Exception
6+
{
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\Exception;
4+
5+
class PatternException extends Exception
6+
{
7+
public static function syntaxError($message, $previous = null)
8+
{
9+
return new self('[Syntax Error] ' . $message, 0, $previous);
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\Exception;
4+
5+
class UnknownExpanderClassException extends Exception
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Coduo\PHPMatcher\Exception;
4+
5+
class UnknownExpanderException extends Exception
6+
{
7+
}

0 commit comments

Comments
 (0)