本文整理汇总了PHP中ReflectionClass::getProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getProperties方法的具体用法?PHP ReflectionClass::getProperties怎么用?PHP ReflectionClass::getProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addComplexType
/**
* Add a complex type by recursivly using all the class properties fetched via Reflection.
*
* @param string $type Name of the class to be specified
* @return string XSD Type for the given PHP type
*/
public function addComplexType($type)
{
if (!class_exists($type)) {
throw new \Zend\Soap\WSDL\Exception(sprintf('Cannot add a complex type %s that is not an object or where ' . 'class could not be found in \'DefaultComplexType\' strategy.', $type));
}
$dom = $this->getContext()->toDomDocument();
$class = new \ReflectionClass($type);
$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $type);
$all = $dom->createElement('xsd:all');
foreach ($class->getProperties() as $property) {
if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) {
/**
* @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
* node for describing other classes used as attribute types for current class
*/
$element = $dom->createElement('xsd:element');
$element->setAttribute('name', $property->getName());
$element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
$all->appendChild($element);
}
}
$complexType->appendChild($all);
$this->getContext()->getSchema()->appendChild($complexType);
$this->getContext()->addType($type);
return "tns:{$type}";
}
示例2: readInterface
/**
* Derives properties from constructor, public instance variables, getters and setters.
*
* @param object|null $object If provided, dynamic (run-time) variables are read as well
* @return \watoki\collections\Map|Property[] indexed by property name
*/
public function readInterface($object = null)
{
$properties = new Map();
if ($this->class->getConstructor()) {
foreach ($this->class->getConstructor()->getParameters() as $parameter) {
$this->accumulate($properties, new property\ConstructorProperty($this->factory, $this->class->getConstructor(), $parameter));
}
}
$declaredProperties = array();
foreach ($this->class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
if (!$property->isStatic()) {
$declaredProperties[] = $property->name;
$this->accumulate($properties, new property\InstanceVariableProperty($this->factory, $property));
}
}
if (is_object($object)) {
foreach ($object as $name => $value) {
if (!in_array($name, $declaredProperties)) {
$this->accumulate($properties, new property\DynamicProperty($this->factory, new \ReflectionClass($object), $name));
}
}
}
foreach ($this->class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
if (property\AccessorProperty::isAccessor($method) && !$method->isStatic()) {
$this->accumulate($properties, new property\AccessorProperty($this->factory, $method));
}
}
return $properties;
}
示例3: obj2Array
private function obj2Array($obj)
{
$toRtn = array();
$reflect = new \ReflectionClass(get_class($obj));
$reflect->getProperties();
foreach ($reflect->getProperties() as $property) {
$result = null;
if ($property->isPrivate() || $property->isProtected()) {
$getter = 'get' . ucfirst($property->getName());
if ($reflect->hasMethod($getter)) {
$result = $obj->{$getter}();
}
} else {
$result = $property->getValue($obj);
}
if (is_object($result)) {
$toRtn[$property->getName()] = $this->obj2Array($result);
} elseif (is_array($result)) {
$toRtn[$property->getName()] = $this->prepare($result);
} else {
$toRtn[$property->getName()] = $result;
}
}
return $toRtn;
}
示例4: getAsArray
/**
* @param string $columnName
*
* @return array
*/
public function getAsArray($columnName = null)
{
if ($columnName) {
$this->rewind();
$obj = $this->current();
if ($obj) {
if (!$this->reflection) {
$this->reflection = new \ReflectionClass($this->current());
}
if ($this->columnMap === null) {
$this->columnMap = [];
foreach ($this->reflection->getProperties() as $property) {
$this->columnMap[$property->getName()] = $property;
}
}
}
}
$this->rewind();
$arr = [];
while ($this->valid()) {
if ($columnName && !empty($this->columnMap[$columnName])) {
$obj = $this->current();
/**
* @var \ReflectionProperty $test
*/
$this->columnMap[$columnName]->setAccessible(true);
$arr[] = $this->columnMap[$columnName]->getValue($obj);
} else {
$arr[] = $this->current();
}
$this->next();
}
return $arr;
}
示例5: 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);
}
示例6: _parseProperties
protected function _parseProperties()
{
$props = $this->_class->getProperties();
foreach ($props as $prop) {
$this->_properties[] = new AnnotatedProperty($prop);
}
}
示例7: construct
/**
* Construct and return Array-Object
* @param String $class
* @return Array
*/
public static function construct($class)
{
// If is already an object return the object
// If not create an instance of the object bypassing a possible
// class constructor
if (is_object($class)) {
$instantiatedClass = $class;
$class = get_class($class);
} else {
$instantiatedClass = self::instantiate($class);
}
// Clean arrays
$properties = array('protected' => array(), 'public' => array());
$methods = array('protected' => array(), 'public' => array());
// Reflection get properties and methods names (public and protected)
$reflect = new \ReflectionClass($instantiatedClass);
$reflectedClass = array('properties' => array('protected' => $reflect->getProperties(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getProperties(\ReflectionProperty::IS_PUBLIC)), 'methods' => array('protected' => $reflect->getMethods(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getMethods(\ReflectionProperty::IS_PUBLIC)));
// Properties foreach's
foreach ($reflectedClass['properties']['protected'] as $prop) {
$properties['protected'][] = $prop->name;
}
foreach ($reflectedClass['properties']['public'] as $prop) {
$properties['public'][] = $prop->name;
}
// Methods foreach's
foreach ($reflectedClass['methods']['protected'] as $method) {
$methods['protected'][] = $method->name;
}
foreach ($reflectedClass['methods']['public'] as $method) {
$methods['public'][] = $method->name;
}
// Return Array-Object
return array('name' => $class, 'object' => $instantiatedClass, 'methods' => $methods, 'properties' => $properties);
}
示例8: __set
/**
* Access to undeclared property.
* @throws LogicException
*/
public function __set($name, $value)
{
$rc = new \ReflectionClass($this);
$items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
$hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean \${$t}?" : '.';
throw new LogicException("Attempt to write to undeclared property {$rc->getName()}::\${$name}{$hint}");
}
示例9: getParentProperties
/**
* @param \ReflectionClass $reflectionClass
*
* @return \ReflectionProperty[]
*/
private function getParentProperties(\ReflectionClass $reflectionClass)
{
$parent = $reflectionClass->getParentClass();
if ($parent != null) {
return array_merge($reflectionClass->getProperties(), $this->getParentProperties($parent));
}
return $reflectionClass->getProperties();
}
示例10: getProperties
/**
* Gets the properties of the object provided.
*
* @param int $filter
*
* @return array
*/
public function getProperties($filter = \ReflectionProperty::IS_PUBLIC)
{
$properties = array();
$reflectionProperties = $this->reflectionEntity->getProperties($filter);
foreach ($reflectionProperties as $property) {
$properties[] = new Property($property->name, $property->isStatic());
}
return $properties;
}
示例11: getClassProperties
/**
* Gets an array of class properties through a reflection class instance
*
* @param \ReflectionClass $class
* @return array
*/
public function getClassProperties(\ReflectionClass $class)
{
$classProperties = [];
$classProperties['constant'] = $class->getConstants();
$classProperties['private'] = $class->getProperties(\ReflectionProperty::IS_PRIVATE);
$classProperties['protected'] = $class->getProperties(\ReflectionProperty::IS_PROTECTED);
$classProperties['public'] = $class->getProperties(\ReflectionProperty::IS_PUBLIC);
$classProperties['static'] = $class->getProperties(\ReflectionProperty::IS_STATIC);
return $classProperties;
}
示例12: entityProperties
public function entityProperties()
{
$fields = array();
$reflection = new \ReflectionClass($this->entityClass);
$reflection->getProperties();
foreach ($reflection->getProperties() as $key => $property) {
$fields[$key] = $property->getName();
}
return $fields;
}
示例13: getPropertiesWithAnnotation
/**
* Returns an array containing the names of all properties containing a particular annotation.
*
* @param string $annotation
*
* @return array
*/
public function getPropertiesWithAnnotation($annotation)
{
$properties = array();
foreach ($this->clazz->getProperties() as $property) {
$annotations = $this->getPropertyAnnotations($property->getName());
if (array_key_exists($annotation, $annotations)) {
$properties[] = $property->getName();
}
}
return $properties;
}
示例14: __construct
/**
* @param string $classname The class to inspect
* @param Reader $reader The annotation reader
* @throws ClassNotFoundException
*/
public function __construct($classname, Reader $reader)
{
try {
$this->className = $classname;
$this->reader = $reader;
$this->reflectionClass = new \ReflectionClass($classname);
$this->reflectionMethods = $this->reflectionClass->getMethods();
$this->reflectionProperties = $this->reflectionClass->getProperties();
} catch (\Exception $ex) {
throw new ClassNotFoundException(sprintf("cannot find class %s", $classname), $ex->getCode(), $ex);
}
}
示例15: mockInjectedProperties
private static function mockInjectedProperties()
{
/** @var \ReflectionProperty $property */
foreach (self::$reflectedClass->getProperties() as $property) {
if (Nette\DI\PhpReflection::parseAnnotation($property, 'inject') !== NULL || Nette\DI\PhpReflection::parseAnnotation($property, 'autowire') !== NULL) {
if ($mockedParameterClass = Nette\DI\PhpReflection::parseAnnotation($property, 'var')) {
$mockedParameterClass = Nette\DI\PhpReflection::expandClassName($mockedParameterClass, Nette\DI\PhpReflection::getDeclaringClass($property));
}
self::setProperty($mockedParameterClass, $property);
}
}
}