本文整理汇总了PHP中ReflectionClass::isFinal方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::isFinal方法的具体用法?PHP ReflectionClass::isFinal怎么用?PHP ReflectionClass::isFinal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::isFinal方法的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);
}
示例2: fromReflection
/**
* Creates a PHP class from reflection
*
* @param \ReflectionClass $ref
* @return PhpClass
*/
public static function fromReflection(\ReflectionClass $ref)
{
$class = new static();
$class->setQualifiedName($ref->name)->setAbstract($ref->isAbstract())->setFinal($ref->isFinal())->setUseStatements(ReflectionUtils::getUseStatements($ref));
if ($ref->getDocComment()) {
$docblock = new Docblock($ref);
$class->setDocblock($docblock);
$class->setDescription($docblock->getShortDescription());
$class->setLongDescription($docblock->getLongDescription());
}
// methods
foreach ($ref->getMethods() as $method) {
$class->setMethod(static::createMethod($method));
}
// properties
foreach ($ref->getProperties() as $property) {
$class->setProperty(static::createProperty($property));
}
// traits
foreach ($ref->getTraits() as $trait) {
$class->addTrait(PhpTrait::fromReflection($trait));
}
// constants
// TODO: https://github.com/gossi/php-code-generator/issues/19
$class->setConstants($ref->getConstants());
return $class;
}
示例3: mockImpl
protected static function mockImpl($type_, array $args_ = [])
{
$type = new \ReflectionClass($type_);
if ($type->isFinal()) {
throw new Exception_IllegalArgument('mock/factory', 'Can not mock final class.');
}
$mtime = @filemtime($type->getFileName());
$classMock = 'Mock_' . str_replace('\\', '_', $type->getNamespaceName()) . '_' . $type->getShortName() . "_{$mtime}";
if (false === @class_exists($classMock)) {
if (null === self::$m_tmpPath) {
self::$m_tmpPath = (string) Test_Runner::get()->getTempPath();
}
$fileName = self::$m_tmpPath . "/{$classMock}.php";
if (false === @file_exists($fileName)) {
$source = self::weaveMock($classMock, new \ReflectionClass('Components\\Mock'), $type);
if (false === @file_put_contents($fileName, $source, 0644)) {
throw new Exception_IllegalState('mock/factory', sprintf('Unable to create mock [type: %1$s, path: %2$s].', $type_, $fileName));
}
}
require_once $fileName;
}
$classMock = "Components\\{$classMock}";
if (0 < count($args_)) {
$refl = new \ReflectionClass($classMock);
$mock = $refl->newInstanceArgs($args_);
} else {
$mock = new $classMock();
}
$mock->mockType = $type;
return $mock;
}
示例4: 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;
}
示例5: fromReflection
public static function fromReflection(\ReflectionClass $ref)
{
$class = new static();
$class->setName($ref->name)->setAbstract($ref->isAbstract())->setFinal($ref->isFinal())->setConstants($ref->getConstants());
if (null === self::$phpParser) {
if (!class_exists('Doctrine\\Common\\Annotations\\PhpParser')) {
self::$phpParser = false;
} else {
self::$phpParser = new PhpParser();
}
}
if (false !== self::$phpParser) {
$class->setUseStatements(self::$phpParser->parseClass($ref));
}
if ($docComment = $ref->getDocComment()) {
$class->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment));
}
foreach ($ref->getMethods() as $method) {
$class->setMethod(static::createMethod($method));
}
foreach ($ref->getProperties() as $property) {
$class->setProperty(static::createProperty($property));
}
return $class;
}
示例6: 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;
}
示例7: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$reflection = new \ReflectionClass($metadata->getClass('model'));
$translatableInterface = TranslatableInterface::class;
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = $translatable ? TranslatableResourceRepository::class : EntityRepository::class;
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
if ($metadata->hasParameter('translation')) {
$translatableRepositoryInterface = TranslatableResourceRepositoryInterface::class;
$translationConfig = $metadata->getParameter('translation');
if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]);
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例8: testAnnotations
/**
* Testing annotations.
*
* @test
* @covers \Bairwell\Hydrator\Annotations\From
*/
public function testAnnotations()
{
$sut = new From();
$reflection = new \ReflectionClass($sut);
$this->assertTrue($reflection->isFinal());
$properties = $reflection->getDefaultProperties();
$expectedProperties = ['sources' => [], 'field' => null, 'conditions' => []];
foreach ($expectedProperties as $k => $v) {
$this->assertArrayHasKey($k, $properties);
$this->assertEquals($v, $properties[$k]);
}
$comments = $reflection->getDocComment();
$expected = preg_quote('@Annotation');
$results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches);
$this->assertEquals(1, $results);
$expected = preg_quote('@Target({"PROPERTY"})');
$this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
//
$property = $reflection->getProperty('sources');
$comments = $property->getDocComment();
$expected = '@var\\s+array';
$this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
$expected = '@Required';
$this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
// field
$property = $reflection->getProperty('field');
$comments = $property->getDocComment();
$expected = '@var\\s+string';
$this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
// conditions
$property = $reflection->getProperty('conditions');
$comments = $property->getDocComment();
$expected = '@var\\s+array';
$this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
}
示例9: getTitle
/**
* @return string
*/
public function getTitle()
{
if ($this->_classReflector->isInterface()) {
$prefix = 'Interface';
} elseif ($this->_classReflector->isFinal()) {
$prefix = 'Final class';
} elseif ($this->_classReflector->isAbstract()) {
$prefix = 'Abstract class';
} else {
$prefix = 'Class';
}
$rstClassName = str_replace("\\", "\\\\", $this->_className);
$rstTitle = "{$prefix} **{$rstClassName}**" . PHP_EOL;
$rstTitle .= str_repeat('=', strlen($rstTitle) - strlen(PHP_EOL)) . PHP_EOL . PHP_EOL;
return $rstTitle;
}
示例10: isFinal
private function isFinal($inheritedClass)
{
if (!class_exists($inheritedClass)) {
return false;
}
$klass = new \ReflectionClass($inheritedClass);
return $klass->isFinal();
}
示例11: addProvider
protected function addProvider(ContainerBuilder $container, $providerClass, $modelName)
{
$providerReflection = new \ReflectionClass($providerClass);
$definition = new Definition($providerClass);
$definition->setArguments([new Reference(sprintf('%s.repository.%s', $this->applicationName, $modelName)), new Reference(sprintf('%s.factory.%s', $this->applicationName, $modelName))]);
$definition->setLazy(!$providerReflection->isFinal());
$container->setDefinition(sprintf('%s.provider.%s', $this->applicationName, $modelName), $definition);
}
示例12: filterOutAbstractClasses
/**
* Filter out Interceptors defined for abstract classes
*
* @param string[] $interceptedEntities
* @return string[]
*/
private function filterOutAbstractClasses($interceptedEntities)
{
$interceptedEntitiesFiltered = [];
foreach ($interceptedEntities as $interceptorClass) {
$interceptedEntity = substr($interceptorClass, 0, -12);
$reflectionInterceptedEntity = new \ReflectionClass($interceptedEntity);
if (!$reflectionInterceptedEntity->isAbstract() && !$reflectionInterceptedEntity->isFinal()) {
$interceptedEntitiesFiltered[] = $interceptorClass;
}
}
return $interceptedEntitiesFiltered;
}
示例13: __construct
/**
* Create a new doc reader
* @param $class
*/
public function __construct($class)
{
$reflection = new ReflectionClass($class);
self::read($reflection->getDocComment(), $this->tags, $this->comments);
$this->isFinal = $reflection->isFinal();
$this->name = $reflection->getName();
$this->file = $reflection->getFileName();
$this->method_comments = array();
$this->method_tags = array();
foreach ($reflection->getMethods() as $method) {
self::read($method->getDocComment(), $this->method_tags[$method->getName()], $this->method_comments[$method->getName()]);
}
}
示例14: createClassMock
/**
* Generates a Mock Object class with all Mockery methods whose
* intent is basically to provide the mock object with the same
* class type hierarchy as a typical instance of the class being
* mocked.
*
* @param string $className
* @param string $mockName
* @param string $allowFinal
*/
public static function createClassMock($className, $mockName = null, $allowFinal = false)
{
if (is_null($mockName)) {
$mockName = uniqid('Mockery_');
}
$class = new \ReflectionClass($className);
$definition = '';
if ($class->isFinal() && !$allowFinal) {
throw new \Mockery\Exception('The class ' . $className . ' is marked final and its methods' . ' cannot be replaced. Classes marked final can be passed in' . 'to \\Mockery::mock() as instantiated objects to create a' . ' partial mock, but only if the mock is not subject to type' . ' hinting checks.');
} elseif ($class->isFinal()) {
$className = '\\Mockery\\Mock';
}
$hasFinalMethods = false;
$methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
$protected = $class->getMethods(\ReflectionMethod::IS_PROTECTED);
foreach ($methods as $method) {
if ($method->isFinal() && !$allowFinal) {
throw new \Mockery\Exception('The method ' . $method->getName() . ' is marked final and it is not possible to generate a ' . 'mock object with such a method defined. You should instead ' . 'pass an instance of this object to Mockery to create a ' . 'partial mock.');
} elseif ($method->isFinal()) {
$className = '\\Mockery\\Mock';
$hasFinalMethods = true;
}
}
if ($class->isInterface()) {
$inheritance = ' implements ' . $className . ', \\Mockery\\MockInterface';
} elseif ($class->isFinal() || $hasFinalMethods) {
$inheritance = ' extends ' . $className;
} else {
$inheritance = ' extends ' . $className . ' implements \\Mockery\\MockInterface';
}
$definition .= 'class ' . $mockName . $inheritance . PHP_EOL . '{' . PHP_EOL;
if (!$class->isFinal() && !$hasFinalMethods) {
$definition .= self::applyMockeryTo($class, $methods);
$definition .= self::stubAbstractProtected($protected);
}
$definition .= PHP_EOL . '}';
eval($definition);
return $mockName;
}
示例15: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$modelClass = $metadata->getClass('model');
$repositoryClass = in_array(TranslatableInterface::class, class_implements($modelClass)) ? TranslatableRepository::class : new Parameter('sylius.mongodb.odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}