当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionClass::isInterface方法代码示例

本文整理汇总了PHP中ReflectionClass::isInterface方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::isInterface方法的具体用法?PHP ReflectionClass::isInterface怎么用?PHP ReflectionClass::isInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


在下文中一共展示了ReflectionClass::isInterface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportCode

 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $code_lines = array();
     $code_lines[] = '<?php';
     // Export the namespace
     if ($this->_reflection_class->getNamespaceName()) {
         $code_lines[] = '';
         $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';';
         $code_lines[] = '';
     }
     // Export the class' signature
     $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : '');
     $code_lines[] = '{';
     $code_lines[] = '';
     // Export constants
     foreach ($this->_reflection_class->getConstants() as $name => $value) {
         $reflection_constant = new ReflectionConstant($name, $value);
         $code_lines[] = "\t" . $reflection_constant->exportCode();
         $code_lines[] = '';
     }
     // Export properties
     foreach ($this->_reflection_class->getProperties() as $property) {
         $reflection_property = new ReflectionProperty($property);
         $code_lines[] = "\t" . $reflection_property->exportCode();
         $code_lines[] = '';
     }
     // Export methods
     foreach ($this->_reflection_class->getMethods() as $method) {
         $reflection_method = new ReflectionMethod($method);
         $code_lines[] = "\t" . $reflection_method->exportCode();
         $code_lines[] = '';
     }
     $code_lines[] = '}';
     return join("\n", $code_lines);
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:40,代码来源:ReflectionClass.php

示例2: getType

 /**
  * Get current object type
  * @return string  - class/trait/interface
  */
 public function getType()
 {
     if ($this->reflectionClass->isInterface()) {
         return 'interface';
     }
     if (method_exists($this->reflectionClass, 'isTrait') && $this->reflectionClass->isTrait()) {
         return 'trait';
     }
     return 'class';
 }
开发者ID:vgrish,项目名称:dvelum,代码行数:14,代码来源:Analyzer.php

示例3: 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());
 }
开发者ID:donquixote,项目名称:hasty-reflection-common,代码行数:54,代码来源:ClassIndexTest.php

示例4: _createClassCode

 private static function _createClassCode($decoratee_class, $decorator_class, $events_handler)
 {
     $reflection = new ReflectionClass($decoratee_class);
     if ($reflection->isInterface()) {
         $relation = "implements";
     } else {
         $relation = "extends";
     }
     $code = "class {$decorator_class} {$relation} {$decoratee_class} {" . PHP_EOL;
     $code .= $events_handler->onDeclareProperties() . PHP_EOL;
     $code .= "    function __construct() {" . PHP_EOL;
     //dealing with proxied class' public properties
     foreach ($reflection->getProperties() as $property) {
         if ($property->isPublic()) {
             $code .= 'unset($this->' . $property->getName() . ");" . PHP_EOL;
         }
     }
     $code .= "        \$args = func_get_args();" . PHP_EOL;
     $code .= $events_handler->onConstructor() . PHP_EOL;
     $code .= "    }" . PHP_EOL;
     $code .= self::_createHandlerCode($decoratee_class, $decorator_class, $events_handler) . PHP_EOL;
     $code .= "}" . PHP_EOL;
     //var_dump($code);
     return $code;
 }
开发者ID:snowjobgit,项目名称:limb,代码行数:25,代码来源:lmbDecorator.class.php

示例5: filter

 /**
  * Filter classes.
  *
  * @param \ReflectionClass $class Class to filter.
  *
  * @throws FilterException
  */
 public function filter(\ReflectionClass $class)
 {
     $name = $class->getShortName();
     if ($class->isAbstract() || $class->isInterface() || !(strlen($name) > 4 && substr($name, -4) === 'Test')) {
         throw new FilterException(sprintf('TestCase was filtered by "%s" filter.', $this->getName()));
     }
 }
开发者ID:komex,项目名称:unteist,代码行数:14,代码来源:ClassFilter.php

示例6: getFile

 protected function getFile($file, $classToCheck = null)
 {
     if (!file_exists($file)) {
         throw new ShopException("File {$file} not found");
     }
     if (!is_readable($file)) {
         throw new ShopException("File {$file} exists, but it's not readable");
     }
     require_once $file;
     if ($classToCheck === 'Product') {
         $classToCheck = array('ConfigurableProduct', 'SimpleProduct');
     }
     if ($classToCheck) {
         if (!is_array($classToCheck)) {
             $classToCheck = array($classToCheck);
         }
         foreach ($classToCheck as $class) {
             $reflection = new ReflectionClass($class);
             if (!$reflection->isInstantiable()) {
                 if (!$reflection->isAbstract() && !$reflection->isInterface()) {
                     throw new ShopException("{$class} class is not instantiable");
                 }
             }
         }
     }
 }
开发者ID:haegyung,项目名称:xe-module-shop,代码行数:26,代码来源:ShopAutoloader.class.php

示例7: loadTemplateForClass

 /**
  * @param \ReflectionClass $class
  * @return string
  * @throws IoException
  */
 public function loadTemplateForClass(\ReflectionClass $class)
 {
     if ($class->isInterface()) {
         return $this->loadFile($this->templateDir . 'Interface.php.template');
     }
     return $this->loadFile($this->templateDir . 'Class.php.template');
 }
开发者ID:belanur,项目名称:mokka,代码行数:12,代码来源:ClassTemplateLoader.php

示例8: throwErrorIfRpcRequestIsInvalid

 /**
  * @param $rpcRequest \RpcGateway\Request
  * @throws \Exception
  */
 protected function throwErrorIfRpcRequestIsInvalid($rpcRequest)
 {
     $serviceMethodName = $rpcRequest->getMethodName();
     // create a PHP compatible version of the requested service class
     $serviceClassName = $this->getServiceClassNamespace() . str_replace(Request::METHOD_DELIMITER, '_', $rpcRequest->getClassName());
     try {
         class_exists($serviceClassName);
     } catch (\Exception $exception) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__);
     }
     $serviceClassReflection = new \ReflectionClass($serviceClassName);
     if ($serviceClassReflection->isAbstract() || $serviceClassReflection->isInterface() || $serviceClassReflection->isInternal()) {
         throw new \Exception("Invalid rpc.class [" . $rpcRequest->getMethod() . "] at " . __METHOD__);
     }
     if ($serviceClassReflection->hasMethod($serviceMethodName) !== true) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__);
     }
     $serviceMethodReflection = $serviceClassReflection->getMethod($serviceMethodName);
     if ($serviceMethodReflection->isAbstract() || $serviceMethodReflection->isConstructor() || $serviceMethodReflection->isStatic() || !$serviceMethodReflection->isPublic()) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not invokable) at " . __METHOD__);
     }
     $argsExpectedMin = $serviceMethodReflection->getNumberOfRequiredParameters();
     $argsExpectedMax = $serviceMethodReflection->getNumberOfParameters();
     $argsOptional = $argsExpectedMax - $argsExpectedMin;
     $argsGiven = count($rpcRequest->getParams());
     if ($argsGiven < $argsExpectedMin || $argsGiven > $argsExpectedMax) {
         $msg = 'Invalid rpc.method [' . $rpcRequest->getMethod() . ']' . " Wrong number of parameters:" . " " . $argsGiven . " given" . " (required: " . $argsExpectedMin . " optional: " . $argsOptional . ")" . " expectedMin: " . $argsExpectedMin . " expectedMax: " . $argsExpectedMax;
         throw new Exception($msg);
     }
 }
开发者ID:basilicom,项目名称:rpc-gateway,代码行数:34,代码来源:Gateway.php

示例9: getExtensibleInterfaceName

 /**
  * Identify concrete extensible interface name based on the class name.
  *
  * @param string $extensibleClassName
  * @return string
  */
 public function getExtensibleInterfaceName($extensibleClassName)
 {
     $exceptionMessage = "Class '{$extensibleClassName}' must implement an interface, " . "which extends from '" . self::EXTENSIBLE_INTERFACE_NAME . "'";
     $notExtensibleClassFlag = '';
     if (isset($this->classInterfaceMap[$extensibleClassName])) {
         if ($notExtensibleClassFlag === $this->classInterfaceMap[$extensibleClassName]) {
             throw new \LogicException($exceptionMessage);
         } else {
             return $this->classInterfaceMap[$extensibleClassName];
         }
     }
     $modelReflection = new \ReflectionClass($extensibleClassName);
     if ($modelReflection->isInterface() && $modelReflection->isSubClassOf(self::EXTENSIBLE_INTERFACE_NAME) && $modelReflection->hasMethod('getExtensionAttributes')) {
         $this->classInterfaceMap[$extensibleClassName] = $extensibleClassName;
         return $this->classInterfaceMap[$extensibleClassName];
     }
     foreach ($modelReflection->getInterfaces() as $interfaceReflection) {
         if ($interfaceReflection->isSubclassOf(self::EXTENSIBLE_INTERFACE_NAME) && $interfaceReflection->hasMethod('getExtensionAttributes')) {
             $this->classInterfaceMap[$extensibleClassName] = $interfaceReflection->getName();
             return $this->classInterfaceMap[$extensibleClassName];
         }
     }
     $this->classInterfaceMap[$extensibleClassName] = $notExtensibleClassFlag;
     throw new \LogicException($exceptionMessage);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:31,代码来源:ExtensionAttributesFactory.php

示例10: compile

 public function compile()
 {
     foreach (PluginRepository::findAll() as $plugin) {
         $containerBuilder = new UnfreezableContainerBuilder();
         $containerBuilder->registerExtension(new GeneralExtension());
         $extensionClass = new \ReflectionClass('Stagehand\\TestRunner\\DependencyInjection\\Extension\\' . $plugin->getPluginID() . 'Extension');
         if (!$extensionClass->isInterface() && !$extensionClass->isAbstract() && $extensionClass->isSubclassOf('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')) {
             $containerBuilder->registerExtension($extensionClass->newInstance());
         }
         foreach ($containerBuilder->getExtensions() as $extension) {
             /* @var $extension \Symfony\Component\DependencyInjection\Extension\ExtensionInterface */
             $containerBuilder->loadFromExtension($extension->getAlias(), array());
         }
         $containerBuilder->addCompilerPass(new ReplaceDefinitionByPluginDefinitionPass($plugin));
         $containerBuilder->getCompilerPassConfig()->setOptimizationPasses(array_filter($containerBuilder->getCompilerPassConfig()->getOptimizationPasses(), function (CompilerPassInterface $compilerPass) {
             return !$compilerPass instanceof ResolveParameterPlaceHoldersPass;
         }));
         ErrorReporting::invokeWith(error_reporting() & ~E_USER_DEPRECATED, function () use($containerBuilder) {
             $containerBuilder->compile();
         });
         $phpDumper = new PhpDumper($containerBuilder);
         $containerClass = $plugin->getPluginID() . 'Container';
         $containerClassSource = $phpDumper->dump(array('class' => $containerClass));
         $containerClassSource = preg_replace('/^<\\?php/', '<?php' . PHP_EOL . 'namespace ' . self::COMPILED_CONTAINER_NAMESPACE . ';' . PHP_EOL, $containerClassSource);
         file_put_contents(__DIR__ . '/../' . $containerClass . '.php', $containerClassSource);
     }
 }
开发者ID:piece,项目名称:stagehand-testrunner,代码行数:27,代码来源:Compiler.php

示例11: findInstallableRecords

 /**
  * Finds installable records from the models folder.
  *
  * @return array
  */
 public function findInstallableRecords()
 {
     $records = array();
     $recordsFolder = craft()->path->getAppPath() . 'records/';
     $recordFiles = IOHelper::getFolderContents($recordsFolder, false, ".*Record\\.php\$");
     foreach ($recordFiles as $file) {
         if (IOHelper::fileExists($file)) {
             $fileName = IOHelper::getFileName($file, false);
             $class = __NAMESPACE__ . '\\' . $fileName;
             // Ignore abstract classes and interfaces
             $ref = new \ReflectionClass($class);
             if ($ref->isAbstract() || $ref->isInterface()) {
                 Craft::log("Skipping record {$file} because it’s abstract or an interface.", LogLevel::Warning);
                 continue;
             }
             $obj = new $class('install');
             if (method_exists($obj, 'createTable')) {
                 $records[] = $obj;
             } else {
                 Craft::log("Skipping record {$file} because it doesn’t have a createTable() method.", LogLevel::Warning);
             }
         } else {
             Craft::log("Skipping record {$file} because it doesn’t exist.", LogLevel::Warning);
         }
     }
     return $records;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:32,代码来源:InstallService.php

示例12: from

 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:33,代码来源:ClassType.php

示例13: testCheckInterfaceExtending

 public function testCheckInterfaceExtending()
 {
     $refl = new \ReflectionClass('Test\\ExtendedInterface');
     $this->assertTrue($refl->isInterface());
     $this->assertContains('IteratorAggregate', $refl->getInterfaceNames());
     $this->assertContains('Countable', $refl->getInterfaceNames());
 }
开发者ID:phalcon,项目名称:zephir,代码行数:7,代码来源:ExtendedInterfaceTest.php

示例14: classData

function classData(ReflectionClass $class)
{
    $details = "";
    $name = $class->getName();
    if ($class->isUserDefined()) {
        $details .= "{$name} is user defined\n";
    }
    if ($class->isInternal()) {
        $details .= "{$name} is built-in\n";
    }
    if ($class->isInterface()) {
        $details .= "{$name} is interface\n";
    }
    if ($class->isAbstract()) {
        $details .= "{$name} is an abstract class\n";
    }
    if ($class->isFinal()) {
        $details .= "{$name} is a final class\n";
    }
    if ($class->isInstantiable()) {
        $details .= "{$name} can be instantiated\n";
    } else {
        $details .= "{$name} can not be instantiated\n";
    }
    return $details;
}
开发者ID:jabouzi,项目名称:projet,代码行数:26,代码来源:listing5.26.php

示例15: run

 /**
  * Check if all classes given by the cli are instantiable.
  */
 public function run()
 {
     $classNames = array_keys($this->_args);
     //No classes given
     if (!$classNames) {
         exit(1);
     }
     //Perform single checks for the classes
     foreach ($classNames as $className) {
         $reflectionClass = new ReflectionClass($className);
         //Is an interface?
         if ($reflectionClass->isInterface()) {
             echo "Interface";
             exit(1);
         }
         //Is an abstract class?
         if ($reflectionClass->isAbstract()) {
             echo "Abstract";
             exit(1);
         }
         //Is a trait?
         if ($reflectionClass->isTrait()) {
             echo "Trait";
             exit(1);
         }
         //Can create the class with new?
         if (!$reflectionClass->isInstantiable()) {
             echo "Not instantiable";
             exit(1);
         }
     }
     echo 'Done';
 }
开发者ID:Wohlie,项目名称:phpstorm-magento-mapper,代码行数:36,代码来源:instantiableTester.php


注:本文中的ReflectionClass::isInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。