本文整理汇总了PHP中XPClass::getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP XPClass::getAnnotations方法的具体用法?PHP XPClass::getAnnotations怎么用?PHP XPClass::getAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XPClass
的用法示例。
在下文中一共展示了XPClass::getAnnotations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createGenericType
/**
* Creates a generic type
*
* @param lang.XPClass self
* @param lang.Type[] arguments
* @return string created type's literal name
*/
public static function createGenericType(XPClass $self, array $arguments)
{
// Verify
$annotations = $self->getAnnotations();
if (!isset($annotations['generic']['self'])) {
throw new IllegalStateException('Class ' . $self->name . ' is not a generic definition');
}
$components = array();
foreach (explode(',', $annotations['generic']['self']) as $cs => $name) {
$components[] = ltrim($name);
}
$cs++;
if ($cs !== sizeof($arguments)) {
throw new IllegalArgumentException(sprintf('Class %s expects %d component(s) <%s>, %d argument(s) given', $self->name, $cs, implode(', ', $components), sizeof($arguments)));
}
// Compose names
$cn = $qc = '';
foreach ($arguments as $typearg) {
$cn .= '¸' . strtr($typearg->literal(), '\\', '¦');
$qc .= ',' . $typearg->getName();
}
$name = $self->literal() . '··' . substr($cn, 1);
$qname = $self->name . '<' . substr($qc, 1) . '>';
// Create class if it doesn't exist yet
if (!class_exists($name, FALSE) && !interface_exists($name, FALSE)) {
$meta = xp::$meta[$self->name];
// Parse placeholders into a lookup map
$placeholders = array();
foreach ($components as $i => $component) {
$placeholders[$component] = $arguments[$i]->getName();
}
// Work on sourcecode
$cl = self::_classLoaderFor($self->name);
if (!$cl || !($bytes = $cl->loadClassBytes($self->name))) {
throw new IllegalStateException($self->name);
}
// Namespaced class
if (FALSE !== ($ns = strrpos($name, '\\'))) {
$decl = substr($name, $ns + 1);
$namespace = substr($name, 0, $ns);
$src = 'namespace ' . $namespace . ';';
} else {
$decl = $name;
$namespace = NULL;
$src = '';
}
// Replace source
$annotation = NULL;
$matches = array();
$state = array(0);
$counter = 0;
$tokens = token_get_all($bytes);
for ($i = 0, $s = sizeof($tokens); $i < $s; $i++) {
if (T_COMMENT === $tokens[$i][0]) {
continue;
} else {
if (0 === $state[0]) {
if (T_ABSTRACT === $tokens[$i][0] || T_FINAL === $tokens[$i][0]) {
$src .= $tokens[$i][1] . ' ';
} else {
if (T_CLASS === $tokens[$i][0] || T_INTERFACE === $tokens[$i][0]) {
$meta['class'][DETAIL_GENERIC] = array($self->name, $arguments);
$src .= $tokens[$i][1] . ' ' . $decl;
array_unshift($state, $tokens[$i][0]);
}
}
continue;
} else {
if (T_CLASS === $state[0]) {
if (T_EXTENDS === $tokens[$i][0]) {
$i += 2;
$parent = '';
while ((T_STRING === $tokens[$i][0] || T_NS_SEPARATOR === $tokens[$i][0]) && $i < $s) {
$parent .= $tokens[$i][1];
$i++;
}
$i--;
'\\' === $parent[0] || ($parent = $namespace . '\\' . $parent);
if (isset($annotations['generic']['parent'])) {
$xargs = array();
foreach (explode(',', $annotations['generic']['parent']) as $j => $placeholder) {
$xargs[] = Type::forName(strtr(ltrim($placeholder), $placeholders));
}
$src .= ' extends \\' . self::createGenericType($self->getParentClass(), $xargs);
} else {
$src .= ' extends ' . $parent;
}
} else {
if (T_IMPLEMENTS === $tokens[$i][0]) {
$src .= ' implements';
$counter = 0;
$annotation = @$annotations['generic']['implements'];
array_unshift($state, 5);
//.........这里部分代码省略.........