当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionObject::getProperties方法代码示例

本文整理汇总了PHP中ReflectionObject::getProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::getProperties方法的具体用法?PHP ReflectionObject::getProperties怎么用?PHP ReflectionObject::getProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionObject的用法示例。


在下文中一共展示了ReflectionObject::getProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProperties

 /**
  * Retrieve all public properties and their values
  * Although this duplicates get_object_vars(), it
  * is mostly useful for internal calls when we need
  * to filter out the non-public properties.
  *
  * @param bool $publicOnly
  *
  * @return array
  */
 public function getProperties($publicOnly = true)
 {
     $reflection = new \ReflectionObject($this);
     $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
     if (!$publicOnly) {
         $properties = array_merge($properties, $reflection->getProperties(\ReflectionProperty::IS_PROTECTED));
     }
     $data = array();
     foreach ($properties as $property) {
         $name = $property->name;
         $data[$name] = $this->{$name};
     }
     return $data;
 }
开发者ID:lepca,项目名称:AllediaFramework,代码行数:24,代码来源:Object.php

示例2: checkForTravelerIdEdit

 public function checkForTravelerIdEdit(TravelerId $liveTravelerId, TravelerId $travelerId)
 {
     $edit = null;
     $oldAttributes = [];
     $newAttributes = [];
     $reflectedObject = new \ReflectionObject($travelerId);
     $reflectedProperties = $reflectedObject->getProperties();
     foreach ($reflectedProperties as $reflectedProperty) {
         $propertyName = $reflectedProperty->getName();
         if ($propertyName !== 'bin') {
             $reflectedProperty->setAccessible(true);
             $liveValue = $reflectedProperty->getValue($liveTravelerId);
             $value = $reflectedProperty->getValue($travelerId);
             if ($liveValue !== $value) {
                 $oldAttributes[$propertyName] = (is_object($liveValue) and method_exists($liveValue, 'getId')) ? $liveValue->getId() : $liveValue;
                 $newAttributes[$propertyName] = (is_object($value) and method_exists($value, 'getId')) ? $value->getId() : $value;
             }
         }
     }
     if (count($oldAttributes) > 0) {
         $edit = new InventoryTravelerIdEdit();
         $edit->setTravelerId($liveTravelerId);
         $edit->setByUser($this->getUser());
         $edit->setEditedAt(new \DateTime());
         $edit->setOldAttributes($oldAttributes);
         $edit->setNewAttributes($newAttributes);
         $this->getDoctrine()->getManager()->persist($edit);
     }
     return $edit;
 }
开发者ID:belackriv,项目名称:step-inventory,代码行数:30,代码来源:TravelerIdLogMixin.php

示例3: isEmpty

 public function isEmpty()
 {
     //testing attributes, the easier place to find something
     foreach ($this->attributes as $attr) {
         if (!empty($attr)) {
             return false;
         }
     }
     //if didn't returned, let's try custom properties
     $obj = new ReflectionObject($this);
     foreach ($obj->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
         if ($property->getDeclaringClass()->name == $obj->name) {
             $value = $property->getValue($this);
             if (!empty($value)) {
                 return false;
             }
         }
     }
     //nothing? so, trying getters
     foreach ($obj->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
         if ($method->getDeclaringClass()->name == $obj->name && strpos($method->name, 'get') === 0 && $method->getNumberOfRequiredParameters() == 0) {
             $value = $method->invoke($this);
             if (!empty($value)) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:nurirahmat,项目名称:Yii-Extensions,代码行数:29,代码来源:ActiveRecord.php

示例4: checkForSalesItemEdit

 public function checkForSalesItemEdit(SalesItem $salesItem, SalesItemDataTransferObject $dto)
 {
     $edit = null;
     $oldAttributes = [];
     $newAttributes = [];
     $reflectedObject = new \ReflectionObject($salesItem);
     $reflectedProperties = $reflectedObject->getProperties();
     foreach ($reflectedProperties as $reflectedProperty) {
         $propertyName = $reflectedProperty->getName();
         if ($propertyName !== 'bin' and property_exists($dto, $propertyName)) {
             $reflectedProperty->setAccessible(true);
             $liveValue = $reflectedProperty->getValue($salesItem);
             $value = $dto->{$propertyName};
             if ($liveValue !== $value) {
                 $oldAttributes[$propertyName] = (is_object($liveValue) and method_exists($liveValue, 'getId')) ? $liveValue->getId() : $liveValue;
                 $newAttributes[$propertyName] = (is_object($value) and method_exists($value, 'getId')) ? $value->getId() : $value;
             }
         }
     }
     if (count($oldAttributes) > 0) {
         $edit = new InventorySalesItemEdit();
         $edit->setSalesItem($salesItem);
         $edit->setByUser($this->getUser());
         $edit->setEditedAt(new \DateTime());
         $edit->setOldAttributes($oldAttributes);
         $edit->setNewAttributes($newAttributes);
         $this->getDoctrine()->getManager()->persist($edit);
     }
     return $edit;
 }
开发者ID:belackriv,项目名称:step-inventory,代码行数:30,代码来源:SalesItemLogMixin.php

示例5: pickle

 private function pickle($o, $maxLevel = FIRELOGGER_MAX_PICKLE_DEPTH)
 {
     if ($maxLevel == 0) {
         // see http://us3.php.net/manual/en/language.types.string.php#73524
         if (!is_object($o) || method_exists($o, '__toString')) {
             return (string) $o;
         }
         return get_class($o);
     }
     if (is_object($o)) {
         $data = array();
         $r = new ReflectionObject($o);
         $props = $r->getProperties();
         foreach ($props as $prop) {
             $name = $prop->getName();
             $prop->setAccessible(true);
             // http://schlitt.info/opensource/blog/0581_reflecting_private_properties.html
             $val = $prop->getValue($o);
             $data[$name] = $this->pickle($val, $maxLevel - 1);
         }
         return $data;
     }
     if (is_array($o)) {
         $data = array();
         foreach ($o as $k => $v) {
             $data[$k] = $this->pickle($v, $maxLevel - 1);
         }
         return $data;
     }
     // TODO: investigate other complex cases
     return $o;
 }
开发者ID:evodanh,项目名称:firelogger4php,代码行数:32,代码来源:firelogger.php

示例6: tearDown

 protected function tearDown()
 {
     //Close & unsets
     if (is_object($this->em)) {
         $this->em->getConnection()->close();
         $this->em->close();
     }
     unset($this->em);
     unset($this->container);
     unset($this->kern);
     unset($this->client);
     //Nettoyage des mocks
     //http://kriswallsmith.net/post/18029585104/faster-phpunit
     $refl = new \ReflectionObject($this);
     foreach ($refl->getProperties() as $prop) {
         if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
             $prop->setAccessible(true);
             $prop->setValue($this, null);
         }
     }
     //Nettoyage du garbage
     if (!gc_enabled()) {
         gc_enable();
     }
     gc_collect_cycles();
     //Parent
     parent::tearDown();
 }
开发者ID:Reallymute,项目名称:IRMApplicative,代码行数:28,代码来源:CarmaWebTestCase.php

示例7: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($object, $format = null, array $context = array())
 {
     $reflectionObject = new \ReflectionObject($object);
     $attributes = array();
     foreach ($reflectionObject->getProperties() as $property) {
         if (in_array($property->name, $this->ignoredAttributes)) {
             continue;
         }
         // Override visibility
         if (!$property->isPublic()) {
             $property->setAccessible(true);
         }
         $attributeValue = $property->getValue($object);
         if (array_key_exists($property->name, $this->callbacks)) {
             $attributeValue = call_user_func($this->callbacks[$property->name], $attributeValue);
         }
         if (null !== $attributeValue && !is_scalar($attributeValue)) {
             if (!$this->serializer instanceof NormalizerInterface) {
                 throw new LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $property->name));
             }
             $attributeValue = $this->serializer->normalize($attributeValue, $format);
         }
         $attributes[$property->name] = $attributeValue;
     }
     return $attributes;
 }
开发者ID:Chaireeee,项目名称:chaireeee,代码行数:29,代码来源:PropertyNormalizer.php

示例8: normalize

 /**
  * {@inheritdoc}
  *
  * @throws CircularReferenceException
  */
 public function normalize($object, $format = null, array $context = array())
 {
     if ($this->isCircularReference($object, $context)) {
         return $this->handleCircularReference($object);
     }
     $reflectionObject = new \ReflectionObject($object);
     $attributes = array();
     $allowedAttributes = $this->getAllowedAttributes($object, $context, true);
     foreach ($reflectionObject->getProperties() as $property) {
         if (in_array($property->name, $this->ignoredAttributes)) {
             continue;
         }
         if (false !== $allowedAttributes && !in_array($property->name, $allowedAttributes)) {
             continue;
         }
         // Override visibility
         if (!$property->isPublic()) {
             $property->setAccessible(true);
         }
         $attributeValue = $property->getValue($object);
         if (isset($this->callbacks[$property->name])) {
             $attributeValue = call_user_func($this->callbacks[$property->name], $attributeValue);
         }
         if (null !== $attributeValue && !is_scalar($attributeValue)) {
             $attributeValue = $this->serializer->normalize($attributeValue, $format, $context);
         }
         $propertyName = $property->name;
         if ($this->nameConverter) {
             $propertyName = $this->nameConverter->normalize($propertyName);
         }
         $attributes[$propertyName] = $attributeValue;
     }
     return $attributes;
 }
开发者ID:ruian,项目名称:symfony,代码行数:39,代码来源:PropertyNormalizer.php

示例9: reflect

 public function reflect($object = null)
 {
     if ($object == null) {
         $object = $this;
     }
     $reflection = new \ReflectionObject($object);
     $properties = $reflection->getProperties();
     $fields = [];
     foreach ($properties as $property) {
         $name = $property->getName();
         if ($name == 'bot_name') {
             continue;
         }
         if (!$property->isPrivate()) {
             $array_of_obj = false;
             $array_of_array_obj = false;
             if (is_array($object->{$name})) {
                 $array_of_obj = true;
                 $array_of_array_obj = true;
                 foreach ($object->{$name} as $elm) {
                     if (!is_object($elm)) {
                         //echo $name . " not array of object \n";
                         $array_of_obj = false;
                         //break;
                     }
                     if (is_array($elm)) {
                         foreach ($elm as $more_net) {
                             if (!is_object($more_net)) {
                                 $array_of_array_obj = false;
                             }
                         }
                     }
                 }
             }
             if (is_object($object->{$name})) {
                 $fields[$name] = $this->reflect($object->{$name});
             } elseif ($array_of_obj) {
                 foreach ($object->{$name} as $elm) {
                     $fields[$name][] = $this->reflect($elm);
                 }
             } elseif ($array_of_array_obj) {
                 foreach ($object->{$name} as $elm) {
                     $temp = null;
                     foreach ($elm as $obj) {
                         $temp[] = $this->reflect($obj);
                     }
                     $fields[$name][] = $temp;
                 }
             } else {
                 $property->setAccessible(true);
                 $value = $property->getValue($object);
                 if (is_null($value)) {
                     continue;
                 }
                 $fields[$name] = $value;
             }
         }
     }
     return $fields;
 }
开发者ID:juananpe,项目名称:php-telegram-bot,代码行数:60,代码来源:Entity.php

示例10: wrapClosures

 /**
  * Recursively traverses and wraps all Closure objects within the value.
  *
  * NOTE: THIS MAY NOT WORK IN ALL USE CASES, SO USE AT YOUR OWN RISK.
  *
  * @param mixed $data Any variable that contains closures.
  * @param SerializerInterface $serializer The serializer to use.
  */
 public static function wrapClosures(&$data, SerializerInterface $serializer)
 {
     if ($data instanceof \Closure) {
         // Handle and wrap closure objects.
         $reflection = new \ReflectionFunction($data);
         if ($binding = $reflection->getClosureThis()) {
             self::wrapClosures($binding, $serializer);
             $scope = $reflection->getClosureScopeClass();
             $scope = $scope ? $scope->getName() : 'static';
             $data = $data->bindTo($binding, $scope);
         }
         $data = new SerializableClosure($data, $serializer);
     } elseif (is_array($data) || $data instanceof \stdClass || $data instanceof \Traversable) {
         // Handle members of traversable values.
         foreach ($data as &$value) {
             self::wrapClosures($value, $serializer);
         }
     } elseif (is_object($data) && !$data instanceof \Serializable) {
         // Handle objects that are not already explicitly serializable.
         $reflection = new \ReflectionObject($data);
         if (!$reflection->hasMethod('__sleep')) {
             foreach ($reflection->getProperties() as $property) {
                 if ($property->isPrivate() || $property->isProtected()) {
                     $property->setAccessible(true);
                 }
                 $value = $property->getValue($data);
                 self::wrapClosures($value, $serializer);
                 $property->setValue($data, $value);
             }
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:40,代码来源:Serializer.php

示例11: hydrate

 /**
  * 
  * Hydrates object
  * 
  * @param object|string $object
  * @param array $data
  * @return object
  * @throws RuntimeException
  */
 public static function hydrate($object, array $data = [])
 {
     if (false === is_object($object)) {
         throw new RuntimeException('First parameter of hydrate must be object.');
     }
     if (false === is_object($object)) {
         return null;
     }
     /** @var \ReflectionObject $reflection reflection object of given model */
     $reflection = new \ReflectionObject($object);
     /** @var \ReflectionProperty[] $properties */
     $properties = $reflection->getProperties();
     /**
      * iterate through all fields
      * and fill array for checking
      */
     foreach ($data as $field => $value) {
         $fieldName = preg_replace('/[^A-Za-z]/', '', $field);
         $data[strtolower($fieldName)] = $value;
     }
     /** @var ReflectionProperty $property */
     foreach ($properties as $property) {
         if (false === $property->isPublic()) {
             $property->setAccessible(true);
         }
         $name = preg_replace('/[^A-Za-z]/', '', strtolower($property->getName()));
         if (isset($data[$name])) {
             $property->setValue($object, $data[$name]);
         }
     }
     return $object;
 }
开发者ID:aleksandarzivanovic,项目名称:vibe,代码行数:41,代码来源:Hydrator.php

示例12: serialize

 /**
  * @param $object
  * @param string $format
  * @return array|string
  */
 public static function serialize($object, $format = "array")
 {
     $attributes = array();
     if (is_array($object)) {
         foreach ($object as $obj) {
             $attributes[] = self::serialize($obj, $format);
         }
     } else {
         $reflectionObject = new \ReflectionObject($object);
         foreach ($reflectionObject->getProperties() as $property) {
             if ($property->isStatic()) {
                 continue;
             }
             if (!$property->isPublic()) {
                 $property->setAccessible(true);
             }
             $attributeValue = $property->getValue($object);
             $propertyName = $property->name;
             if (is_object($attributeValue)) {
                 $attributeValue = self::serialize($attributeValue);
             }
             $attributes[$propertyName] = $attributeValue;
         }
         if ($format == "json") {
             return json_encode($attributes);
         }
     }
     return $attributes;
 }
开发者ID:frnks,项目名称:meister,代码行数:34,代码来源:Data.php

示例13: resolveDependencies

 /**
  * Resolve the dependencies of the object
  *
  * @param mixed $object Object in which to resolve dependencies
  * @throws Annotations\AnnotationException
  */
 public function resolveDependencies($object)
 {
     if (is_null($object)) {
         return;
     }
     // Fetch the object's properties
     $reflectionClass = new \ReflectionObject($object);
     $properties = $reflectionClass->getProperties();
     // For each property
     foreach ($properties as $property) {
         // Look for DI annotations
         $injectAnnotation = null;
         $valueAnnotation = null;
         $propertyAnnotations = $this->getAnnotationReader()->getPropertyAnnotations($property);
         foreach ($propertyAnnotations as $annotation) {
             if ($annotation instanceof Inject) {
                 $injectAnnotation = $annotation;
             }
             if ($annotation instanceof Value) {
                 $valueAnnotation = $annotation;
             }
         }
         // If both @Inject and @Value annotation, exception
         if ($injectAnnotation && $valueAnnotation) {
             throw new AnnotationException(get_class($object) . "::" . $property->getName() . " can't have both @Inject and @Value annotations");
         } elseif ($injectAnnotation) {
             $this->resolveInject($property, $object, $injectAnnotation->lazy);
         } elseif ($valueAnnotation) {
             $this->resolveValue($property, $valueAnnotation->key, $object);
         }
     }
 }
开发者ID:hawkingwan,项目名称:phpBeanstalkdAdmin,代码行数:38,代码来源:DependencyManager.php

示例14: reflect

 public function reflect($object)
 {
     $reflection = new \ReflectionObject($object);
     $properties = $reflection->getProperties();
     $fields = [];
     foreach ($properties as $property) {
         $name = $property->getName();
         if ($name == 'bot_name') {
             continue;
         }
         if (!$property->isPrivate()) {
             if (is_object($object->{$name})) {
                 $fields[$name] = $this->reflect($object->{$name});
             } else {
                 $property->setAccessible(true);
                 $value = $property->getValue($object);
                 if (is_null($value)) {
                     continue;
                 }
                 $fields[$name] = $value;
             }
         }
     }
     return $fields;
 }
开发者ID:KelvinVenancio,项目名称:php-telegram-bot,代码行数:25,代码来源:Entity.php

示例15: produceHumanReadableOutputForObject

 public static function produceHumanReadableOutputForObject($object, $depth, $isTruncatingRecursion, $level, array $previousSplObjectHashes)
 {
     if (false == is_object($object)) {
         throw new \UnexpectedValueException(sprintf("Expected parameter '%s' to be an Object. Found: %s", '$object', gettype($object)));
     }
     $reflection = new \ReflectionObject($object);
     $properties = $reflection->getProperties();
     $objectValuesString = "";
     foreach ($properties as $property) {
         $property->setAccessible(true);
         $propertyValue = $property->getValue($object);
         $replacementValue = self::prepareRecursively($propertyValue, $depth - 1, $isTruncatingRecursion, $level + 1, $previousSplObjectHashes);
         $exposure = "";
         if ($property->isPrivate()) {
             $exposure = "private";
         } elseif ($property->isProtected()) {
             $exposure = "protected";
         } else {
             $exposure = "public";
         }
         if ($property->isStatic()) {
             $exposure .= " static";
         }
         $objectValuesString .= str_repeat(self::INDENTATION_CHARACTERS, $level + 1) . str_replace(["%PROPERTY_EXPOSURE%", "%PROPERTY_NAME%", "%PROPERTY_VALUE%"], [$exposure, $property->getName(), trim($replacementValue)], "%PROPERTY_EXPOSURE% \$%PROPERTY_NAME% = %PROPERTY_VALUE%");
         if (is_scalar($propertyValue) || is_null($propertyValue)) {
             $objectValuesString .= ";";
         }
         $objectValuesString .= PHP_EOL;
     }
     $hash = spl_object_hash($object);
     return str_repeat(self::INDENTATION_CHARACTERS, $level) . get_class($object) . " Object &{$hash}" . PHP_EOL . str_repeat(self::INDENTATION_CHARACTERS, $level) . "{" . PHP_EOL . $objectValuesString . str_repeat(self::INDENTATION_CHARACTERS, $level) . "}" . PHP_EOL;
 }
开发者ID:kafoso,项目名称:tools,代码行数:32,代码来源:PlainTextFormatter.php


注:本文中的ReflectionObject::getProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。