[PropertyInfo] Add hassers for accessors prefixes
This commit is contained in:
parent
c44a894258
commit
03bce5e50c
@ -34,7 +34,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public static $defaultAccessorPrefixes = array('is', 'can', 'get');
|
public static $defaultAccessorPrefixes = array('is', 'can', 'get', 'has');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -178,7 +178,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
return array($this->extractFromReflectionType($reflectionType));
|
return array($this->extractFromReflectionType($reflectionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($prefix, array('is', 'can'))) {
|
if (in_array($prefix, array('is', 'can', 'has'))) {
|
||||||
return array(new Type(Type::BUILTIN_TYPE_BOOL));
|
return array(new Type(Type::BUILTIN_TYPE_BOOL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ class PhpDocExtractorTest extends TestCase
|
|||||||
array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null),
|
array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null),
|
||||||
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
|
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
|
||||||
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
|
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
|
||||||
array('g', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
|
array('g', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
|
||||||
|
array('array', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
|
||||||
array('donotexist', null, null, null),
|
array('donotexist', null, null, null),
|
||||||
array('staticGetter', null, null, null),
|
array('staticGetter', null, null, null),
|
||||||
array('staticSetter', null, null, null),
|
array('staticSetter', null, null, null),
|
||||||
|
@ -40,7 +40,7 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
'collection',
|
'collection',
|
||||||
'B',
|
'B',
|
||||||
'Guid',
|
'Guid',
|
||||||
'g',
|
'array',
|
||||||
'emptyVar',
|
'emptyVar',
|
||||||
'foo',
|
'foo',
|
||||||
'foo2',
|
'foo2',
|
||||||
@ -56,6 +56,7 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
'd',
|
'd',
|
||||||
'e',
|
'e',
|
||||||
'f',
|
'f',
|
||||||
|
'g',
|
||||||
),
|
),
|
||||||
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
|
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
|
||||||
);
|
);
|
||||||
@ -196,10 +197,12 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
array('d', true),
|
array('d', true),
|
||||||
array('e', false),
|
array('e', false),
|
||||||
array('f', false),
|
array('f', false),
|
||||||
|
array('g', true),
|
||||||
array('Id', true),
|
array('Id', true),
|
||||||
array('id', true),
|
array('id', true),
|
||||||
array('Guid', true),
|
array('Guid', true),
|
||||||
array('guid', false),
|
array('guid', false),
|
||||||
|
array('guid', false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,6 +229,7 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
array('d', false),
|
array('d', false),
|
||||||
array('e', true),
|
array('e', true),
|
||||||
array('f', true),
|
array('f', true),
|
||||||
|
array('g', false),
|
||||||
array('Id', false),
|
array('Id', false),
|
||||||
array('Guid', true),
|
array('Guid', true),
|
||||||
array('guid', false),
|
array('guid', false),
|
||||||
|
@ -66,7 +66,7 @@ class Dummy extends ParentDummy
|
|||||||
*
|
*
|
||||||
* @var array|null
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
public $g;
|
public $array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should not be removed.
|
* This should not be removed.
|
||||||
|
@ -75,4 +75,11 @@ class ParentDummy
|
|||||||
public function removeF(\DateTime $f)
|
public function removeF(\DateTime $f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool|null
|
||||||
|
*/
|
||||||
|
public function hasG()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user