| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
stubClassLoader::load('net::stubbles::reflection::annotations::stubAnnotation', |
|---|
| 10 |
'net::stubbles::reflection::annotations::stubAbstractAnnotation', |
|---|
| 11 |
'net::stubbles::xml::stubXMLException', |
|---|
| 12 |
'net::stubbles::xml::serializer::annotations::stubXMLMethodsAnnotation', |
|---|
| 13 |
'net::stubbles::xml::serializer::annotations::stubXMLPropertiesAnnotation' |
|---|
| 14 |
); |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
class stubXMLMatcherAnnotation extends stubAbstractAnnotation implements stubAnnotation, stubXMLPropertiesAnnotation, stubXMLMethodsAnnotation |
|---|
| 28 |
{ |
|---|
| 29 |
|
|---|
| 30 |
* Pattern of the properties, that should be serialized |
|---|
| 31 |
* |
|---|
| 32 |
* @var string |
|---|
| 33 |
*/ |
|---|
| 34 |
protected $pattern; |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
* Set the pattern |
|---|
| 38 |
* |
|---|
| 39 |
* @param string $pattern |
|---|
| 40 |
*/ |
|---|
| 41 |
public function setPattern($pattern) |
|---|
| 42 |
{ |
|---|
| 43 |
$this->pattern = $pattern; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Get the name of the tag to use for a property |
|---|
| 48 |
* |
|---|
| 49 |
* @param stubReflectionProperty $property |
|---|
| 50 |
* @return string|false |
|---|
| 51 |
* @throws stubXMLException |
|---|
| 52 |
*/ |
|---|
| 53 |
public function getTagnameForProperty(stubReflectionProperty $property) |
|---|
| 54 |
{ |
|---|
| 55 |
$matches = array(); |
|---|
| 56 |
$success = @preg_match($this->pattern, $property->getName(), $matches); |
|---|
| 57 |
if (false === $success) { |
|---|
| 58 |
throw new stubXMLException("Syntax error in regular expression '{$this->pattern}': {$php_errormsg}"); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
if (empty($matches) === true) { |
|---|
| 62 |
return false; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if (isset($matches[1]) === true) { |
|---|
| 66 |
return $matches[1]; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
return $matches[0]; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
* Get the name of the tag to use for a method |
|---|
| 74 |
* |
|---|
| 75 |
* @param stubReflectionMethod $method |
|---|
| 76 |
* @return string|bool |
|---|
| 77 |
* @throws stubXMLException |
|---|
| 78 |
*/ |
|---|
| 79 |
public function getTagnameForMethod(stubReflectionMethod $method) |
|---|
| 80 |
{ |
|---|
| 81 |
$matches = array(); |
|---|
| 82 |
$success = preg_match($this->pattern, $method->getName(), $matches); |
|---|
| 83 |
if (false === $success) { |
|---|
| 84 |
throw new stubXMLException("Syntax error in regular expression '{$this->pattern}': {$php_errormsg}"); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
if (empty($matches) === true) { |
|---|
| 88 |
return false; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
if (isset($matches[1]) === true) { |
|---|
| 92 |
$name = $matches[1]; |
|---|
| 93 |
} else { |
|---|
| 94 |
$name = $matches[0]; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
return strtolower($name{0}) . substr($name, 1); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* Returns the target of the annotation as bitmap. |
|---|
| 102 |
* |
|---|
| 103 |
* @return int |
|---|
| 104 |
*/ |
|---|
| 105 |
public function getAnnotationTarget() |
|---|
| 106 |
{ |
|---|
| 107 |
return stubAnnotation::TARGET_CLASS; |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
?> |
|---|