Skip to content

Commit

Permalink
Remove unused code and refactor Geolocator service construction
Browse files Browse the repository at this point in the history
Removed commented out, unused code from the GeoLocatorSubscriber class to tidy up the file. Refactored service construction in the GeolocatorAbstract class to better handle non-existent classes, and significantly enhance the readability of the code.

These changes were made in order to adhere to modern PHP code style, enhance maintainability, and improve the reliability of the system. The refactoring provides better exception handling and makes the code cleaner, reducing unnecessary clutter.
  • Loading branch information
Xorg committed Nov 27, 2023
1 parent 8dafb07 commit 8e7d22e
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/Pattern/geolocatorAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,23 @@ protected function getRealIp( ): ?string
{

// https://api.ipify.org?format=json
$api = "https://api.ipify.org?format=json";
// todo: problem in same cas to get real ip !!!
$data = $this->senApi( $api );
$ip = json_decode($data, false, 512, JSON_THROW_ON_ERROR);
return $ip->ip;
// // in dev mode mock
// if ( $this->kernel->getEnvironment() === 'dev') {
// // for test Bulgary "156.146.55.226"
// return $this->neoxBag->getIpLocalDev() ;
// }
//
// $request = $this->requestStack->getCurrentRequest();
// $ip = $request->getClientIp();
//
// if ($request->headers->has('X-Real-IP')) {
// return $request->headers->get('X-Real-IP');
// }
// $api = "https://api.ipify.org?format=json";
// // todo: problem in same cas to get real ip !!!
// $data = $this->senApi( $api );
// $ip = json_decode($data, false, 512, JSON_THROW_ON_ERROR);
// return $ip->ip;
// in dev mode mock
if ( $this->kernel->getEnvironment() === 'dev') {
// for test Bulgary "156.146.55.226"
return $this->neoxBag->getIpLocalDev() ;
}

$request = $this->requestStack->getCurrentRequest();
$ip = $request->getClientIp();

if ($request->headers->has('x-real-ip')) {
return $request->headers->get('x-real-ip');
}
//
// if ($request->headers->has('CF-Connecting-IP')) {
// $ip = $request->headers->get('CF-Connecting-IP');
Expand All @@ -229,8 +229,8 @@ protected function getRealIp( ): ?string
// $ips = explode(',', $request->headers->get('X-Forwarded-For'), 2);
// $ip = trim($ips[0]); // The left-most IP address is the original client
// }
//
// return $ip;

return $ip;
}

private function stringContainsSubstringFromArray(string $mainString, array $substringsArray): bool
Expand Down

0 comments on commit 8e7d22e

Please sign in to comment.