Skip to content

Commit d1ffca1

Browse files
committed
Trying to use reflection to add logging for objects.
1 parent 96c9fc7 commit d1ffca1

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

lib/net/authorize/api/controller/base/ApiOperationBase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public function executeWithApiResponse($endPoint = \net\authorize\api\constants\
111111
public function execute($endPoint = \net\authorize\api\constants\ANetEnvironment::CUSTOM)
112112
{
113113
$this->beforeExecute();
114-
114+
// $this->logger->debugFormat("Request object :%s", $this->apiRequest);
115+
$this->logger->debug($this->apiRequest);
115116
$this->logger->info("Request Serialization Begin");
116117
$xmlRequest = $this->serializer->serialize($this->apiRequest, 'xml');
117118
$this->logger->info("Request Serialization End");

lib/net/authorize/util/Log.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,55 @@ private function maskSensitiveXmlString($rawString){
5151
$maskedString = preg_replace($patterns, $replacements, $rawString);
5252
return $maskedString;
5353
}
54+
private function maskSensitiveProperties ($obj)
55+
{
56+
$reflectObj = new \ReflectionObject($obj);
57+
// //echo "reflection object name: " . $reflectObj->getName();
58+
// if($reflectObj->getName()=="name"){
59+
// return;
60+
// }
61+
$props = $reflectObj->getParentClass()->getProperties();
62+
print_r($props);
63+
foreach($props as $i => $prop){
64+
$prop->setAccessible(true);
65+
//
66+
// echo "propValue: " ;
67+
print_r($prop->getValue($obj));
68+
// print_r($propValue);
69+
70+
if(is_object($prop->getValue($obj))){
71+
echo "Is object\n";
72+
$prop->setValue($obj, null);
73+
// $prop->setValue($obj, $this->maskSensitiveProperties($prop->getValue($obj)));
74+
}
75+
else{
76+
echo "leaf value: " ; $prop->getValue($obj);
77+
}
5478

79+
// var_dump($obj);
80+
}
81+
//NULL even obj disp>layed print_r(get_object_vars($obj));
82+
// print_r($obj);
83+
//NULL even obj displayed print_r(get_class_vars(get_class($obj)));
84+
echo "************************";
85+
print_r($obj);
86+
print_r('size...'.count($props));
87+
return $obj;
88+
// echo"var_dump-------";
89+
// var_dump($reflectObj);
90+
// echo"var_dump-------";
91+
// return $reflectObj;
92+
}
5593
private function getMasked($raw)
56-
{
94+
{ //always returns string
5795
$messageType = gettype($raw);
5896
$message="";
5997
if ($messageType == "string") {
6098
$message = $this->maskSensitiveXmlString($raw);
6199
}
100+
else if($messageType == "object"){
101+
$message = print_r($this->maskSensitiveProperties($raw), true); //object to string
102+
}
62103
return $message;
63104
}
64105
public function debug($logMessage, $flags=FILE_APPEND)

0 commit comments

Comments
 (0)