public function canBeCachedViaXpRegistry() { with(\xp::$registry['details.' . ($fixture = 'DummyDetails')] = $details = $this->dummyDetails()); $actual = \lang\XPClass::detailsForClass($fixture); unset(\xp::$registry['details.' . $fixture]); $this->assertEquals($details, $actual); }
public function parseDetails($class) { $details = XPClass::detailsForClass($class->getName()); return isset($details['class']); }
function newinstance($spec, $args, $def = null) { static $u = 0; if ('#' === $spec[0]) { $p = strrpos($spec, ' '); $annotations = substr($spec, 0, $p) . ' '; $spec = substr($spec, $p + 1); } else { $annotations = ''; } // Create unique name $n = "·" . ++$u; if (0 === strncmp($spec, 'php.', 4)) { $spec = substr($spec, 4); } else { if (false === strpos($spec, '.')) { $spec = \lang\XPClass::nameOf($spec); } } // Handle generics, PHP types and all others. if (strstr($spec, '<')) { $class = \lang\Type::forName($spec); $type = $class->literal(); $generic = xp::$meta[$class->getName()]['class'][DETAIL_GENERIC]; } else { if (false === strpos($spec, '.')) { $type = $spec; $generic = null; } else { try { $type = xp::$loader->loadClass0($spec); } catch (\lang\ClassLoadingException $e) { xp::error($e->getMessage()); } $generic = null; } } $name = strtr($type, '\\', '.') . $n; if (interface_exists($type)) { $decl = ['kind' => 'class', 'extends' => ['lang.Object'], 'implements' => ['\\' . $type], 'use' => []]; } else { if (trait_exists($type)) { $decl = ['kind' => 'class', 'extends' => ['lang.Object'], 'implements' => [], 'use' => ['\\' . $type]]; } else { $decl = ['kind' => 'class', 'extends' => ['\\' . $type], 'implements' => [], 'use' => []]; } } $defined = \lang\ClassLoader::defineType($annotations . $name, $decl, $def); if (false === strpos($type, '\\')) { xp::$cn[$type . $n] = $spec . $n; } if ($generic) { \lang\XPClass::detailsForClass($name); xp::$meta[$name]['class'][DETAIL_GENERIC] = $generic; } if ($defined->hasConstructor()) { return $defined->getConstructor()->newInstance($args); } else { return $defined->newInstance(); } }
/** @return var */ public function typeAnnotations() { $class = $this->typeName(); $details = XPClass::detailsForClass($class); if ($details && $details['class'][DETAIL_ANNOTATIONS]) { return $this->annotationsOf($details['class'][DETAIL_ANNOTATIONS]); } else { return null; } }