/**
* Current target context.
*
- * @var string
+ * @var integer
*/
private $target;
/**
* An array of default namespaces if operating in simple mode.
*
- * @var array
+ * @var string[]
*/
private $namespaces = array();
* The names must be the raw names as used in the class, not the fully qualified
* class names.
*
- * @var array
+ * @var bool[] indexed by annotation name
*/
private $ignoredAnnotationNames = array();
+ /**
+ * A list with annotations in namespaced format
+ * that are not causing exceptions when not resolved to an annotation class.
+ *
+ * @var bool[] indexed by namespace name
+ */
+ private $ignoredAnnotationNamespaces = array();
+
/**
* @var string
*/
* The names are supposed to be the raw names as used in the class, not the
* fully qualified class names.
*
- * @param array $names
+ * @param bool[] $names indexed by annotation name
*
* @return void
*/
$this->ignoredAnnotationNames = $names;
}
+ /**
+ * Sets the annotation namespaces that are ignored during the parsing process.
+ *
+ * @param bool[] $ignoredAnnotationNamespaces indexed by annotation namespace name
+ *
+ * @return void
+ */
+ public function setIgnoredAnnotationNamespaces($ignoredAnnotationNamespaces)
+ {
+ $this->ignoredAnnotationNamespaces = $ignoredAnnotationNamespaces;
+ }
+
/**
* Sets ignore on not-imported annotations.
*
/**
* Sets the default namespaces.
*
- * @param array $namespace
+ * @param string $namespace
*
* @return void
*
// search for first valid annotation
while (($pos = strpos($input, '@', $pos)) !== false) {
- // if the @ is preceded by a space or * it is valid
- if ($pos === 0 || $input[$pos - 1] === ' ' || $input[$pos - 1] === '*') {
+ $preceding = substr($input, $pos - 1, 1);
+
+ // if the @ is preceded by a space, a tab or * it is valid
+ if ($pos === 0 || $preceding === ' ' || $preceding === '*' || $preceding === "\t") {
return $pos;
}
$originalName = $name;
if ('\\' !== $name[0]) {
- $alias = (false === $pos = strpos($name, '\\'))? $name : substr($name, 0, $pos);
+ $pos = strpos($name, '\\');
+ $alias = (false === $pos)? $name : substr($name, 0, $pos);
$found = false;
+ $loweredAlias = strtolower($alias);
if ($this->namespaces) {
foreach ($this->namespaces as $namespace) {
break;
}
}
- } elseif (isset($this->imports[$loweredAlias = strtolower($alias)])) {
+ } elseif (isset($this->imports[$loweredAlias])) {
$found = true;
$name = (false !== $pos)
? $this->imports[$loweredAlias] . substr($name, $pos)
}
if ( ! $found) {
- if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
+ if ($this->isIgnoredAnnotation($name)) {
return false;
}
}
}
+ $name = ltrim($name,'\\');
+
if ( ! $this->classExists($name)) {
throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context));
}
// verify that the class is really meant to be an annotation and not just any ordinary class
if (self::$annotationMetadata[$name]['is_annotation'] === false) {
- if (isset($this->ignoredAnnotationNames[$originalName])) {
+ if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])) {
return false;
}
if ( ! defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
list($className, $const) = explode('::', $identifier);
- $alias = (false === $pos = strpos($className, '\\')) ? $className : substr($className, 0, $pos);
+ $pos = strpos($className, '\\');
+ $alias = (false === $pos) ? $className : substr($className, 0, $pos);
$found = false;
+ $loweredAlias = strtolower($alias);
switch (true) {
case !empty ($this->namespaces):
}
break;
- case isset($this->imports[$loweredAlias = strtolower($alias)]):
+ case isset($this->imports[$loweredAlias]):
$found = true;
$className = (false !== $pos)
? $this->imports[$loweredAlias] . substr($className, $pos)
* FieldAssignment ::= FieldName "=" PlainValue
* FieldName ::= identifier
*
- * @return array
+ * @return \stdClass
*/
private function FieldAssignment()
{
return array(null, $this->Value());
}
+
+ /**
+ * Checks whether the given $name matches any ignored annotation name or namespace
+ *
+ * @param string $name
+ *
+ * @return bool
+ */
+ private function isIgnoredAnnotation($name)
+ {
+ if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
+ return true;
+ }
+
+ foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
+ $ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';
+
+ if (0 === stripos(rtrim($name, '\\') . '\\', $ignoredAnnotationNamespace)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}