本文整理汇总了PHP中Zend\Code\Reflection\ClassReflection::getInterfaces方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassReflection::getInterfaces方法的具体用法?PHP ClassReflection::getInterfaces怎么用?PHP ClassReflection::getInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Reflection\ClassReflection
的用法示例。
在下文中一共展示了ClassReflection::getInterfaces方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dumpClass
/**
* Returns class' code inside namespace
*
* @param ClassReflection $class
*/
private function dumpClass(ClassReflection $class)
{
if (array_search($class->getName(), $this->cachedClasses) !== false) {
return;
}
if ($class->isInternal()) {
return;
}
if ($class->getParentClass()) {
$this->dumpClass($class->getParentClass());
}
foreach ($class->getInterfaces() as $interface) {
$this->dumpClass($interface);
}
if ($class->getTraits()) {
foreach ($class->getTraits() as $trait) {
$this->dumpClass($trait);
}
}
$classContents = $class->getContents(false);
$classFileDir = dirname($class->getFileName());
$classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
$uses = implode("\n", $this->codeGenerator->getUseLines($class));
$this->cache[] = "namespace " . $class->getNamespaceName() . " {\n" . ($uses ? $uses . "\n" : '') . $this->codeGenerator->getDeclarationLine($class) . "\n" . $classContents . "\n}\n";
$this->cachedClasses[] = $class->getName();
}
示例2: testInterfaceReturn
public function testInterfaceReturn()
{
$reflectionClass = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass4');
$interfaces = $reflectionClass->getInterfaces();
$this->assertEquals(1, count($interfaces));
$interface = array_shift($interfaces);
$this->assertEquals('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClassInterface', $interface->getName());
}
示例3: fromReflection
/**
* Build a Code Generation Php Object from a Class Reflection
*
* @param ClassReflection $classReflection
* @return ClassGenerator
*/
public static function fromReflection(ClassReflection $classReflection)
{
// class generator
$cg = new static($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
}
$cg->setAbstract($classReflection->isAbstract());
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
/* @var \Zend\Code\Reflection\ClassReflection $parentClass */
$parentClass = $classReflection->getParentClass();
if ($parentClass) {
$cg->setExtendedClass($parentClass->getName());
$interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces());
} else {
$interfaces = $classReflection->getInterfaces();
}
$interfaceNames = array();
foreach ($interfaces as $interface) {
/* @var \Zend\Code\Reflection\ClassReflection $interface */
$interfaceNames[] = $interface->getName();
}
$cg->setImplementedInterfaces($interfaceNames);
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
$properties[] = PropertyGenerator::fromReflection($reflectionProperty);
}
}
$cg->addProperties($properties);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
$cg->addMethods($methods);
return $cg;
}
示例4: buildInterface
/**
* Build the interface part
*
* @param array $uses
* @param Reflection\ClassReflection $class
* @return string
*/
protected function buildInterface(&$uses, Reflection\ClassReflection $class)
{
$code = '';
$interfaces = $class->getInterfaces();
$parentClass = $class->getParentClass();
// Normalize interfaces array to string
foreach ($interfaces as &$interface) {
$interfaceReflections[$interface->getName()] = $interface;
$interface = $interface->getName();
}
// Remove interface from parent class
if ($parentClass !== false) {
$parentInterfaces = $parentClass->getInterfaces();
foreach ($parentInterfaces as &$parentInterface) {
$interfaceReflections[$parentInterface->getName()] = $parentInterface;
$parentInterface = $parentInterface->getName();
}
$interfaces = array_diff($interfaces, $parentInterfaces);
}
// No interfaces found? Return ''
if (count($interfaces) === 0) {
return $code;
}
// Create extend/implement keyword
$code .= $class->isInterface() ? ' extends ' : ' implements ';
$classNamespace = $class->getNamespaceName();
// Retrieve interfaces from the interfaces
foreach ($interfaces as &$interface) {
$parentInterfaces = $interfaceReflections[$interface]->getInterfaces();
foreach ($parentInterfaces as &$parentInterface) {
$interfaceReflections[$parentInterface->getName()] = $parentInterface;
$parentInterface = $parentInterface->getName();
}
// Remove already implemented interfaces
$interfaces = array_diff($interfaces, $parentInterfaces);
}
// define interface names
foreach ($interfaces as &$interface) {
// Make sure the class has already been cached
$this->processClassIntoCacheFile($interfaceReflections[$interface]);
// Check if the interface has been defined in the uses
if (array_key_exists($interface, $uses)) {
// Set the use alias or the shortname when no alias has been set
$interface = empty($uses[$interface]) ? $interfaceReflections[$interface]->getShortName() : $uses[$interface];
} else {
// Check if we're implementing from a subnamespace
$inNamespace = strpos($interface, $classNamespace) === 0;
if ($inNamespace) {
$interface = substr($interface, strlen($classNamespace) + 1);
} else {
$interface = "\\{$interface}";
}
}
}
$code .= implode(', ', $interfaces);
return $code;
}
示例5: getInterfaces
/**
*
* @param ClassReflection $class
* @return ClassReflection[]
*/
private function getInterfaces(ClassReflection $class)
{
$classes = [];
foreach ($class->getInterfaces() as $interface) {
$classes = array_merge($classes, $this->getInterfaces($interface));
}
if ($class->isUserDefined() && $class->isInterface() && !in_array($class->getName(), $this->seen)) {
$this->seen[] = $class->getName();
$classes[] = $class;
}
return $classes;
}
示例6: getGeneratorFromReflection
/**
* Copied from ClassGenerator::fromReflection and tweaked slightly
* @param ClassReflection $classReflection
*
* @return ClassGenerator
*/
public function getGeneratorFromReflection(ClassReflection $classReflection)
{
// class generator
$cg = new ClassGenerator($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$docblock = DocBlockGenerator::fromReflection($classReflection->getDocBlock());
$docblock->setIndentation(Generator::$indentation);
$cg->setDocBlock($docblock);
}
$cg->setAbstract($classReflection->isAbstract());
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
/* @var \Zend\Code\Reflection\ClassReflection $parentClass */
$parentClass = $classReflection->getParentClass();
if ($parentClass) {
$cg->setExtendedClass('\\' . ltrim($parentClass->getName(), '\\'));
$interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces());
} else {
$interfaces = $classReflection->getInterfaces();
}
$interfaceNames = array();
foreach ($interfaces as $interface) {
/* @var \Zend\Code\Reflection\ClassReflection $interface */
$interfaceNames[] = $interface->getName();
}
$cg->setImplementedInterfaces($interfaceNames);
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
$property = PropertyGenerator::fromReflection($reflectionProperty);
$property->setIndentation(Generator::$indentation);
$properties[] = $property;
}
}
$cg->addProperties($properties);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$method = MethodGenerator::fromReflection($reflectionMethod);
$method->setBody(preg_replace("/^\\s+/m", '', $method->getBody()));
$method->setIndentation(Generator::$indentation);
$methods[] = $method;
}
}
$cg->addMethods($methods);
return $cg;
}