本文整理汇总了PHP中ReflectionProperty::getDeclaringClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::getDeclaringClass方法的具体用法?PHP ReflectionProperty::getDeclaringClass怎么用?PHP ReflectionProperty::getDeclaringClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::getDeclaringClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defaultValue
public function defaultValue()
{
if ($this->property->isDefault()) {
$defaultProperties = $this->property->getDeclaringClass()->getDefaultProperties();
return $defaultProperties[$this->property->getName()];
}
return null;
}
示例2: 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();
}
示例3: 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}" : '');
}
示例4: 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);
}
示例5: getDeclaringClassName
private function getDeclaringClassName($propertyName)
{
$reflection = new ReflectionProperty(get_class($this), $propertyName);
$declaringClass = $reflection->getDeclaringClass();
$className = $declaringClass->getName();
return $className;
}
示例6: getTypeOfProperty
private function getTypeOfProperty(\ReflectionProperty $prop)
{
if (preg_match('/^[\\s\\/*]*@var\\s+(\\S+)/m', $prop->getDocComment(), $matches)) {
return $this->getFullNameOfType($matches[1], $prop->getDeclaringClass());
}
return;
}
示例7: 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;
}
示例8: getDeclaringClass
/**
* Get declaring class reflection object
*
* @return ClassReflection
*/
public function getDeclaringClass()
{
$phpReflection = parent::getDeclaringClass();
$zendReflection = new ClassReflection($phpReflection->getName());
unset($phpReflection);
return $zendReflection;
}
示例9: getSetter
/**
* @param \ReflectionProperty $property
*
* @return \ReflectionMethod|null
*/
public function getSetter(\ReflectionProperty $property)
{
$setter = sprintf(static::SETTER_FORMAT, ucfirst($property->getName()));
$class = $property->getDeclaringClass();
if ($class->hasMethod($setter)) {
return $class->getMethod($setter);
}
}
示例10: getXmlNamespace
public function getXmlNamespace()
{
$namespace = $this->_parseAnnotation($this->property->getDocComment(), 'xmlNamespace');
if (!$namespace && $this->configuration) {
$value = $this->getValue();
if (is_object($this->getValue())) {
$classMeta = new ClassMetadata($this->getValue(), $this->configuration);
$namespace = $classMeta->getXmlNamespace();
} elseif (is_array($value) && count($value) > 0) {
$classMeta = new ClassMetadata($this->getValue()[0], $this->configuration);
$namespace = $classMeta->getXmlNamespace();
} else {
$classNamespace = $this->property->getDeclaringClass()->getNamespaceName();
$namespace = $this->configuration->getXmlNamespace($classNamespace);
}
}
return $namespace;
}
示例11: getDeclaringClass
/**
* Returns the declaring class.
*
* @return ezcReflectionClass
*/
public function getDeclaringClass()
{
if ($this->reflectionSource instanceof ReflectionProperty) {
return new ezcReflectionClass($this->reflectionSource->getDeclaringClass());
} else {
$class = parent::getDeclaringClass();
return new ezcReflectionClass($class->getName());
}
}
示例12: setValue
/**
* {@inheritDoc}
*/
public function setValue(\ReflectionProperty $property, $object, $value)
{
$propertyName = $property->getName();
$declaringClass = $property->getDeclaringClass();
$setterName = sprintf('set%s', ucfirst($propertyName));
if (!$declaringClass->hasMethod($setterName)) {
throw new \RuntimeException('No setter found for "' . $propertyName . '"');
}
$declaringClass->getMethod($setterName)->invoke($object, $value);
}
示例13: asInstance
/**
* @param object|NULL
* @return AccessBase $this
*/
public function asInstance($object)
{
if (is_object($object)) {
if ($this->reflection instanceof ReflectionClass) {
$class = $this->reflection->getName();
} else {
$class = $this->reflection->getDeclaringClass()->getName();
}
if (!$object instanceof $class) {
throw new Exception('Must be instance of accessible class.');
}
} else {
if ($object !== NULL) {
throw new Exception('Instance must be object or NULL.');
}
}
$this->instance = $object;
return $this;
}
示例14: match
public static function match(\ReflectionProperty $property, $matches = array())
{
$comment = static::get($property->getDeclaringClass()->getName(), $property->getName());
foreach ($matches as $match) {
if (preg_match("|{$match}|", $comment)) {
return true;
}
}
return false;
}
示例15: from
/**
* @return self
*/
public static function from(\ReflectionProperty $from)
{
$prop = new static($from->getName());
$defaults = $from->getDeclaringClass()->getDefaultProperties();
$prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
$prop->static = $from->isStatic();
$prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
$prop->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
return $prop;
}