Closed ghost closed 3 years ago
I tested it via this test (if you want to I can add it to repository):
File: tests/OnResponseTest.phpt
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use MetzWeb\Instagram\Instagram;
$apiKey = '';
$token = '';
$logData = [];
$instagram = new Instagram($apiKey);
$instagram->setAccessToken($token);
$instagram->onResponse[] = function ($apiCall, array $params, $method, $jsonData) use (&$logData) {
$logData = [
'apiCall' => $apiCall,
'params' => $params,
'method' => $method,
'jsonData' => $jsonData,
];
};
$instagram->getUserMedia();
if ($logData['apiCall'] !== 'https://api.instagram.com/v1/users/self/media/recent?access_token=261457396.55621d5.b1763002ff49447d86a1977500c04506&') {
print_r($logData['apiCall']);
die ("Assert 'apiCall' FAILED!\n");
}
if ($logData['params'] !== []) {
print_r($logData['params']);
die ("Assert 'params' FAILED!\n");
}
if ($logData['method'] !== 'GET') {
print_r($logData['method']);
die ("Assert 'params' FAILED!\n");
}
print_r($logData['jsonData']);
Hey,
i added this event-logic on the class, because I found hard to make logging possible.
I do it this way, because I wanted to avoid inheritance as bad practice and composition (via decorator for example) is not easily possible because of missing interface. Also, it would be extremely weird to wrap all those public method in some
LoggingInstagramDecorator
.