本文整理汇总了PHP中ReflectionProperty::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::getName方法的具体用法?PHP ReflectionProperty::getName怎么用?PHP ReflectionProperty::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: match
/**
* {@inheritdoc}
*/
public function match(\ReflectionProperty $property, $givenName)
{
if (array_key_exists($property->getName(), $this->map)) {
return $this->map[$property->getName()] === $givenName;
}
return false;
}
示例2: __construct
/**
* @param \ReflectionProperty $accessedProperty
* @param string $nameSuffix
*/
public function __construct(ReflectionProperty $accessedProperty, $nameSuffix)
{
$this->accessedProperty = $accessedProperty;
$originalName = $this->accessedProperty->getName();
$name = UniqueIdentifierGenerator::getIdentifier($originalName . $nameSuffix);
parent::__construct(Class_::MODIFIER_PRIVATE, array(new PropertyProperty($name)));
}
示例3: defaultValue
public function defaultValue()
{
if ($this->property->isDefault()) {
$defaultProperties = $this->property->getDeclaringClass()->getDefaultProperties();
return $defaultProperties[$this->property->getName()];
}
return null;
}
示例4: getDeclaringClass
/**
* Returns declaring class or trait.
* @return \ReflectionClass
*/
public static function getDeclaringClass(\ReflectionProperty $prop)
{
foreach ($prop->getDeclaringClass()->getTraits() as $trait) {
if ($trait->hasProperty($prop->getName())) {
return self::getDeclaringClass($trait->getProperty($prop->getName()));
}
}
return $prop->getDeclaringClass();
}
示例5: isKey
/**
* Has the class in annotation this property as key?
*
* @return boolean
*/
public function isKey()
{
if ($this->isKey === null) {
foreach ($this->getAnnotationClass()->getAll('key') as $key) {
if ($key == $this->property->getName()) {
return true;
}
}
}
return $this->isKey;
}
示例6: resolvePropertyMetadata
/**
* Generic class property resolver.
*
* @param \ReflectionProperty $property
* @param ClassMetadata $classMetadata
*
* @return PropertyMetadata Resolved property metadata
*/
protected function resolvePropertyMetadata(\ReflectionProperty $property, ClassMetadata $classMetadata) : PropertyMetadata
{
// Create method metadata instance
$propertyMetadata = $classMetadata->propertiesMetadata[$property->getName()] ?? new PropertyMetadata($classMetadata);
$propertyMetadata->name = $property->getName();
$propertyMetadata->modifiers = $property->getModifiers();
$propertyMetadata->isPublic = $property->isPublic();
$propertyMetadata->typeHint = $this->getCommentTypeHint(is_string($property->getDocComment()) ? $property->getDocComment() : '');
// Store property metadata to class metadata
return $classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata;
}
示例7: exportCode
/**
* Exports the PHP code
*
* @return string
*/
public function exportCode()
{
$default_properties = $this->_property->getDeclaringClass()->getDefaultProperties();
$modifiers = \Reflection::getModifierNames($this->_property->getModifiers());
$default_value = null;
if (array_key_exists($this->_property->getName(), $default_properties)) {
$default_value = $default_properties[$this->_property->getName()];
if (!is_numeric($default_value)) {
$default_value = "'{$default_value}'";
}
}
return sprintf('%s $%s%s;', join(' ', $modifiers), $this->_property->getName(), !is_null($default_value) ? " = {$default_value}" : '');
}
示例8: getPropertyIdentifier
public static function getPropertyIdentifier(\ReflectionProperty $reflectionProperty, $className)
{
$key = null;
if ($reflectionProperty->isPrivate()) {
$key = '\\0' . $className . '\\0' . $reflectionProperty->getName();
} elseif ($reflectionProperty->isProtected()) {
$key = '' . "" . '*' . "" . $reflectionProperty->getName();
} elseif ($reflectionProperty->isPublic()) {
$key = $reflectionProperty->getName();
}
if (null === $key) {
throw new \InvalidArgumentException('Unable to detect property visibility');
}
return $key;
}
示例9: getPropertyClass
/**
* Parse the docblock of the property to get the class of the var annotation.
*
* @param \ReflectionProperty $property
*
* @throws AnnotationException Non exists class.
*
* @return null|ObjectDefinition
*/
public function getPropertyClass(\ReflectionProperty $property)
{
$propertyComment = $property->getDocComment();
if (!preg_match('/@var\\s+([^\\s\\(\\*\\/]+)/', $propertyComment, $matches)) {
return;
}
$className = end($matches);
if (!is_string($className) || in_array($className, static::$ignoredTypes)) {
return;
}
$classWithNamespace = $className;
if ($this->namespaceExists($classWithNamespace) === false) {
$classWithNamespace = $this->namespace . '\\' . $className;
}
if (!$this->classExists($classWithNamespace)) {
$declaringClass = $property->getDeclaringClass();
throw new AnnotationException(sprintf('The @var annotation on %s::%s contains a non existent class "%s"', $declaringClass->name, $property->getName(), $className));
}
$createNewObject = function ($propertyComment, $className, $classWithNamespace) {
$classParameters = $this->propertyClassParameters($propertyComment, $className);
if (is_array($classParameters)) {
$values = [];
foreach ($classParameters as $value) {
$values[] = static::parseValue($value);
}
$object = new ObjectDefinition($classWithNamespace, $className);
$object->setConstructorInjection($values);
return $object;
}
return new $classWithNamespace();
};
return $createNewObject($propertyComment, $className, $classWithNamespace);
}
示例10: resolveProperty
/**
* {@inheritdoc}
* @throws PropertyDefinitionNotFoundException
*/
public function resolveProperty(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionProperty $reflectionProperty)
{
$propertyName = $reflectionProperty->getName();
if ($classDefinition->hasProperty($propertyName)) {
$classDefinition->getProperty($propertyName)->defineDependency(new ServiceReference($this->value['value']));
}
}
示例11: getNativePropertyType
/**
* @param ReflectionProperty
* @param array (string => string)
* @param string
* @return string
*/
public function getNativePropertyType(ReflectionProperty $prop, &$defaults, &$type)
{
$name = $prop->getName();
if ($doc = trim($prop->getDocComment(), " \t\r\n*/")) {
if (preg_match('/@var[ \\t]+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\s*(:?\\[[\\s0-9]*\\]|)/', $doc, $m)) {
if ($m[2]) {
$type = 'arr';
} else {
$type = substr(strtolower($m[1]), 0, 3);
if ($type == 'mix') {
$type = 'str';
} elseif (!in_array($type, self::$phpTypes)) {
$type = 'obj';
}
}
}
}
if (!$type) {
$type = substr(gettype(self::referenceObj($prop->getDeclaringClass()->getName())->{$name}), 0, 3);
}
$nativeType = $this->nativeTypes[$type == 'str' ? strlen('' . $defaults[$name]) > 255 ? 'tex' : 'str' : $type];
if (!$nativeType) {
throw new IllegalTypeException('Unstorable type: ' . $type . ' for property: ' . $name);
}
return $nativeType;
}
示例12: getPropertyLine
/**
* @param \ReflectionProperty $property
* @return int
*/
public static function getPropertyLine(\ReflectionProperty $property)
{
$class = $property->getDeclaringClass();
$context = 'file';
$contextBrackets = 0;
foreach (token_get_all(file_get_contents($class->getFileName())) as $token) {
if ($token === '{') {
$contextBrackets += 1;
} elseif ($token === '}') {
$contextBrackets -= 1;
}
if (!is_array($token)) {
continue;
}
if ($token[0] === T_CLASS) {
$context = 'class';
$contextBrackets = 0;
} elseif ($context === 'class' && $contextBrackets === 1 && $token[0] === T_VARIABLE) {
if ($token[1] === '$' . $property->getName()) {
return $token[2];
}
}
}
return NULL;
}
示例13: reflectProperty
function reflectProperty($class, $property)
{
$propInfo = new ReflectionProperty($class, $property);
echo "**********************************\n";
echo "Reflecting on property {$class}::{$property}\n\n";
echo "__toString():\n";
var_dump($propInfo->__toString());
echo "export():\n";
var_dump(ReflectionProperty::export($class, $property, true));
echo "export():\n";
var_dump(ReflectionProperty::export($class, $property, false));
echo "getName():\n";
var_dump($propInfo->getName());
echo "isPublic():\n";
var_dump($propInfo->isPublic());
echo "isPrivate():\n";
var_dump($propInfo->isPrivate());
echo "isProtected():\n";
var_dump($propInfo->isProtected());
echo "isStatic():\n";
var_dump($propInfo->isStatic());
$instance = new $class();
if ($propInfo->isPublic()) {
echo "getValue():\n";
var_dump($propInfo->getValue($instance));
$propInfo->setValue($instance, "NewValue");
echo "getValue() after a setValue():\n";
var_dump($propInfo->getValue($instance));
}
echo "\n**********************************\n";
}
示例14: getName
public function getName()
{
if (isset($this->_name)) {
return $this->_name;
}
return parent::getName();
}
示例15: getPropertyParserBuilder
private function getPropertyParserBuilder(\ReflectionProperty $property)
{
$propertyParserBuilder = new PropertyParserBuilder($property->getName());
foreach ($this->annotationReader->getAnnotationsFromProperty($property) as $propertyAnnotation) {
$this->annotationParserFactory->getAnnotationParserFor($propertyAnnotation)->execute($propertyAnnotation, $propertyParserBuilder);
}
return $propertyParserBuilder;
}