本文整理汇总了PHP中ReflectionClass::getInterfaceNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getInterfaceNames方法的具体用法?PHP ReflectionClass::getInterfaceNames怎么用?PHP ReflectionClass::getInterfaceNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getInterfaceNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContexts
/**
* Get a hierarchy of contexts for the given class as an array
*
* @param string $class
* @return array
*/
private function getContexts($class)
{
if ($class == Wires_Locator_Interface::GLOBAL_CONTEXT) {
return array($class);
}
$ref = new ReflectionClass($class);
$contexts = array($class);
// collect interfaces
if (is_array($ref->getInterfaceNames())) {
foreach ($ref->getInterfaceNames() as $interface) {
$contexts[] = $interface;
}
}
// add parent class
if ($ref->getParentClass()) {
$parent_contexts = $this->getContexts($ref->getParentClass()->getName());
foreach ($parent_contexts as $pc) {
if ($pc != Wires_Locator_Interface::GLOBAL_CONTEXT && !in_array($pc, $contexts)) {
$contexts[] = $pc;
}
}
}
$contexts[] = Wires_Locator_Interface::GLOBAL_CONTEXT;
return $contexts;
}
示例2: testCheckInterfaceExtending
public function testCheckInterfaceExtending()
{
$refl = new \ReflectionClass('Test\\ExtendedInterface');
$this->assertTrue($refl->isInterface());
$this->assertContains('IteratorAggregate', $refl->getInterfaceNames());
$this->assertContains('Countable', $refl->getInterfaceNames());
}
示例3: getImplements
/**
* Get implemented interface names
* @return string
*/
public function getImplements()
{
$i = $this->reflectionClass->getInterfaceNames();
if (!empty($i)) {
return implode(', ', $i);
}
return '';
}
示例4: __construct
public function __construct(DiInterface $di, $class)
{
if (!is_string($class) && !is_object($class)) {
throw new Exception("第二个参数只能接受字符串或对象");
}
$this->_di = $di;
$this->_class = new ReflectionClass($class);
if (is_object($class)) {
$this->_instance = $class;
} elseif (is_string($class) && !$this->_class->isInstantiable()) {
throw new Exception("不能对一个无法实例化的类进行注入");
}
$this->_interfaceNames = $this->_class->getInterfaceNames();
}
示例5: __construct
protected function __construct($events = null)
{
if ($events !== null) {
$this->events = $events;
return;
}
static::$definedClasses = get_declared_classes();
$allClass = static::$definedClasses;
foreach ($allClass as $key => $className) {
$reflectionClass = new \ReflectionClass($className);
if (!in_array(EventHander::class, $reflectionClass->getInterfaceNames())) {
var_dump($reflectionClass->getInterfaceNames());
}
}
}
示例6: testClassIndex
/**
* @param \Donquixote\HastyReflectionCommon\Canvas\ClassIndex\ClassIndexInterface $classIndex
* @param string $class
*
* @dataProvider provideClassIndexArgs()
*/
function testClassIndex(ClassIndexInterface $classIndex, $class)
{
$classReflection = $classIndex->classGetReflection($class);
$reflectionClass = new \ReflectionClass($class);
// Test identity.
$this->assertTrue($classReflection === $classIndex->classGetReflection($class));
// Test class type/info.
$expectedIsClass = !$reflectionClass->isInterface() && !$reflectionClass->isTrait();
$this->assertEquals($reflectionClass->getName(), $classReflection->getName());
$this->assertEquals($reflectionClass->getShortName(), $classReflection->getShortName());
$this->assertEquals($reflectionClass->getDocComment(), $classReflection->getDocComment());
$this->assertEquals($reflectionClass->isInterface(), $classReflection->isInterface());
$this->assertEquals($reflectionClass->isTrait(), $classReflection->isTrait());
$this->assertEquals($expectedIsClass, $classReflection->isClass());
$this->assertEquals($reflectionClass->isAbstract() && $expectedIsClass, $classReflection->isAbstractClass());
// Test context.
$this->assertEquals($reflectionClass->getNamespaceName(), $classReflection->getNamespaceUseContext()->getNamespaceName());
// Test interfaces
foreach ($classReflection->getOwnInterfaces() as $interfaceName => $interfaceReflection) {
$this->assertTrue($reflectionClass->implementsInterface($interfaceName));
}
foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {
$this->assertTrue($classReflection->extendsOrImplementsInterface($interfaceName, FALSE));
}
$expectedAllInterfaceNames = $expectedAllAndSelfInterfaceNames = $reflectionClass->getInterfaceNames();
if ($reflectionClass->isInterface()) {
array_unshift($expectedAllAndSelfInterfaceNames, $class);
}
$this->assertEqualSorted($expectedAllAndSelfInterfaceNames, array_keys($classReflection->getAllInterfaces(TRUE)));
$this->assertEqualSorted($expectedAllInterfaceNames, array_keys($classReflection->getAllInterfaces(FALSE)));
$expectedMethodNames = array();
$expectedOwnMethodNames = array();
foreach ($reflectionClass->getMethods() as $method) {
$expectedMethodNames[] = $method->getName();
if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) {
$expectedOwnMethodNames[] = $method->getName();
}
}
$this->assertEquals($expectedOwnMethodNames, array_keys($classReflection->getOwnMethods()));
$this->assertEqualSorted($expectedMethodNames, array_keys($classReflection->getMethods()));
$methodReflections = $classReflection->getMethods();
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
$methodReflection = $methodReflections[$reflectionMethod->getShortName()];
$this->assertEqualMethods($reflectionMethod, $methodReflection);
}
// isAbstract() is a beast, so we test it least.
$this->assertEquals($reflectionClass->isAbstract(), $classReflection->isAbstract());
}
示例7: getAddonRouter
public function getAddonRouter($addon, $group = 'content')
{
if (!isset($this->addonRouters[$addon])) {
$addonname = ucfirst($addon);
$class = 'PlgTZ_Portfolio_Plus' . ucfirst($group) . $addonname . 'Router';
if (!class_exists($class)) {
// Use the component routing handler if it exists
$path = JPATH_SITE . '/components/com_tz_portfolio_plus/addons/' . $group . '/' . $addon . '/router.php';
// Use the custom routing handler if it exists
if (file_exists($path)) {
require_once $path;
}
}
if (class_exists($class)) {
$reflection = new ReflectionClass($class);
if (in_array('JComponentRouterInterface', $reflection->getInterfaceNames())) {
$this->addonRouters[$addon] = new $class($this->app, $this->menu);
}
}
}
if (isset($this->addonRouters[$addon]) && $this->addonRouters[$addon]) {
return $this->addonRouters[$addon];
}
return false;
}
示例8: getManagedTemplate
/**
* Returns the managed template for a given object if one exists, looks for
* templates along the object's ancestors until it finds one. If no template
* is found, an <code>InvalidArgumentException</code> is thrown.
*
* @param unknown $object
* @throws \InvalidArgumentException
* @return multitype:
*/
public function getManagedTemplate($object)
{
// ** Collection to hold the list of class names that we are looking for templates in...
$classes = array();
// ** Get the object class and push it into the list of classes, also check to see if the array key exists.
$objectClass = get_class($object);
array_push($classes, $objectClass);
if (array_key_exists($objectClass, $this->templateMap)) {
return $this->templateMap[$objectClass];
}
// ** Search through the ancestors of the object for a matching template...
$class = new \ReflectionClass($objectClass);
$interfaces = $class->getInterfaceNames();
while ($class = $class->getParentClass()) {
$key = $class->getName();
$classes[] = $key;
if (array_key_exists($key, $this->templateMap)) {
return $this->templateMap[$key];
}
}
// ** Finally look for a template defined at the interface level...
foreach ($interfaces as $interface) {
$classes[] = $interface;
if (array_key_exists($interface, $this->templateMap)) {
return $this->templateMap[$interface];
}
}
throw new \InvalidArgumentException('Unable to find template for object: ' . $objectClass . ' in the template manager. Looked for template in: ' . implode(', ', $classes));
}
示例9: resolve
/**
* @param object $type
* @return string
* @throws \Exception
*/
public function resolve($type)
{
// @todo remove after MAGETWO-52608 resolved
$className = get_class($type);
if (isset($this->typeMapping[$className])) {
return $this->typeMapping[$className];
}
$reflectionClass = new \ReflectionClass($type);
$interfaceNames = $reflectionClass->getInterfaceNames();
$dataInterfaces = [];
foreach ($interfaceNames as $interfaceName) {
if (strpos($interfaceName, '\\Api\\Data\\')) {
$dataInterfaces[] = isset($this->config[$interfaceName]) ? $this->config[$interfaceName] : $interfaceName;
}
}
if (count($dataInterfaces) == 0) {
throw new \Exception('Unable to determine data interface for ' . $className);
}
foreach ($dataInterfaces as $dataInterface) {
if ($this->metadataPool->hasConfiguration($dataInterface)) {
$this->typeMapping[$className] = $dataInterface;
}
}
return $this->typeMapping[$className];
}
示例10: getComponentRouter
/**
* Tries to create a new router object for given component, returns NULL
* if object not supported
*
* @staticvar JComponentRouterInterface[] $cache
* @param string $component Component name in format "com_xxx"
* @return \JComponentRouterInterface
*/
protected static function getComponentRouter($component)
{
static $cache = array();
if (!array_key_exists($component, $cache)) {
$router = null;
$compName = ucfirst(substr($component, 4));
$class = $compName . 'Router';
if (class_exists($class)) {
// Check if it supports the Joomla router interface, because
// some components use classes with the same name causing
// fatal error then (eg. EasyBlog)
$reflection = new ReflectionClass($class);
if (in_array('JComponentRouterInterface', $reflection->getInterfaceNames())) {
// Create the router object
$app = JFactory::getApplication();
$menu = $app->getMenu('site');
$router = new $class($app, $menu);
}
}
// If router class not supported, create legacy router object (Joomla 3)
if (!$router && class_exists('JComponentRouterLegacy')) {
$router = new JComponentRouterLegacy($compName);
}
// Cache the router object
$cache[$component] = $router;
}
return $cache[$component];
}
示例11: array
static function class_implements($c, $autoload = true)
{
if (is_object($c)) {
$class = get_class($c);
} else {
if (!class_exists($c, $autoload) && !interface_exists($c, false) && !trait_exists($c, false)) {
user_error(__FUNCTION__ . '(): Class ' . $c . ' does not exist and could not be loaded', E_USER_WARNING);
return false;
} else {
$c = self::ns2us($c);
}
}
/**/
if (function_exists('class_implements')) {
$autoload = class_implements($c, false);
/**/
} else {
if (class_exists('ReflectionClass', false)) {
$autoload = array();
$c = new ReflectionClass($c);
foreach ($c->getInterfaceNames() as $c) {
$autoload[$c] = $c;
}
/**/
} else {
return false;
/**/
}
}
foreach ($autoload as $c) {
isset(self::$us2ns[$a = strtolower($c)]) && ($autoload[$c] = self::$us2ns[$a]);
}
return $autoload;
}
示例12: __construct
/**
* Fügt mehrere Plugins hinzu und registriert diese bei allen Schnittstellen
* @param array $plugins
*/
public function __construct(array $plugins)
{
$configCache = new Dragon_Application_Config('dragon/plugin/cache');
$this->_filepath = $configCache->filepath;
if (isset($this->_filepath) && is_file($this->_filepath)) {
list($this->_plugins, $this->_unsortedplugins, $this->_sortedplugins) = unserialize(file_get_contents($this->_filepath));
} else {
foreach ($plugins as $plugin) {
if (is_object($plugin)) {
$pluginname = get_class($plugin);
} else {
$pluginname = $plugin;
}
$this->_plugins[$pluginname] = $pluginname;
$reflectionClass = new ReflectionClass($plugin);
foreach ($reflectionClass->getInterfaceNames() as $interfacename) {
if (!isset($this->_unsortedplugins[$interfacename])) {
$this->_unsortedplugins[$interfacename] = array();
}
$this->_unsortedplugins[$interfacename][] = $plugin;
}
}
if (isset($this->_filepath)) {
file_put_contents($this->_filepath, serialize(array($this->_plugins, $this->_unsortedplugins, $this->_sortedplugins)));
}
}
}
示例13: introspectClass
protected function introspectClass(ConfigurableObjectInterface $object)
{
$originalReflectionClass = $reflectionClass = new \ReflectionClass($object);
$this->addClass($reflectionClass->getName());
while (($class = $reflectionClass->getParentClass()) !== false) {
$this->addClass($class->getName());
foreach ($class->getInterfaceNames() as $interface) {
$this->addClass($interface);
$reflectionInterface = new \ReflectionClass($interface);
$interfaces = $reflectionInterface->getInterfaceNames();
foreach ($interfaces as $interface) {
$this->addClass($interface);
}
}
$reflectionClass = $class;
}
foreach ($originalReflectionClass->getInterfaceNames() as $name) {
$this->addClass($name);
$interfaces[] = $name;
$reflectionInterface = new \ReflectionClass($name);
$theseInterfaces = $reflectionInterface->getInterfaceNames();
$theseInterfaces = array_reverse($theseInterfaces);
foreach ($theseInterfaces as $interface) {
$this->addClass($interface);
}
}
$this->classes = array_reverse($this->classes);
return $this->classes;
}
示例14: emit
public function emit(...$eventList)
{
foreach ($eventList as $event) {
if (!is_object($event)) {
throw new EventBusException(sprintf('EventBus does not support emitting [%s] type.', gettype($event)));
}
$reflectionClass = new \ReflectionClass($event);
$reflectionList = $reflectionClass->getInterfaceNames();
$reflectionList[] = $reflectionClass->getName();
foreach ($reflectionList as $reflection) {
if (!isset($this->listenerList[$reflection])) {
continue;
}
foreach ($this->listenerList[$reflection] as $listener) {
call_user_func($listener, $event);
if ($event instanceof IEvent) {
if (!$event->canBubble()) {
break 2;
}
}
}
}
}
return $this;
}
示例15: GetDetailsOfModule
/**
* Get info and details about a module.
*
* @param $module string with the module name.
* @returns array with information on the module.
*/
private function GetDetailsOfModule($module)
{
$details = array();
if (class_exists($module)) {
$rc = new ReflectionClass($module);
$details['name'] = $rc->name;
$details['filename'] = $rc->getFileName();
$details['doccomment'] = $rc->getDocComment();
$details['interface'] = $rc->getInterfaceNames();
$details['isController'] = $rc->implementsInterface('IController');
if ($rc->name != 'CMDatabase') {
$details['isModel'] = preg_match('/^CM[A-Z]/', $rc->name);
} else {
$details['isModel'] = '';
}
$details['hasSQL'] = $rc->implementsInterface('IHasSQL');
$details['isManageable'] = $rc->implementsInterface('IModule');
$details['isLydiaCore'] = in_array($rc->name, $this->lydiaCoreModules);
$details['isLydiaCMF'] = in_array($rc->name, $this->lydiaCMFModules);
$details['publicMethods'] = $rc->getMethods(ReflectionMethod::IS_PUBLIC);
$details['protectedMethods'] = $rc->getMethods(ReflectionMethod::IS_PROTECTED);
$details['privateMethods'] = $rc->getMethods(ReflectionMethod::IS_PRIVATE);
$details['staticMethods'] = $rc->getMethods(ReflectionMethod::IS_STATIC);
}
return $details;
}