Source of file IPInfoCache.php
Size: 1,293 Bytes - Last Modified: 2021-12-23T10:03:03+00:00
/var/www/docs.ssmods.com/process/src/code/models/IPInfoCache.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | <?php /** * @author Kirk Mayo <kirk.mayo@solnet.co.nz> * * A cache of geo data for a IP address */ class IPInfoCache extends DataObject { public static $defaultDrivers = array( 'GeoIPLegacyDriver' ); private static $db = array( 'IP' => 'Varchar', 'Info' => 'Text' ); public static function setupCache($ip) { $driver = Config::inst()->get('IPInfoCache', 'Driver'); if (!$driver) { foreach (self::$defaultDrivers as $defaultDriver) { if (class_exists($defaultDriver)) { $driver = $defaultDriver; break; } } if (!$driver) { user_error('A driver needs to be specified'); } } $ipService = new $driver(); $dbJson = $ipService->processIP($ip); // do not cache a empty object if ($dbJson) { $cache = IPInfoCache::create(); $cache->IP = $ip; $cache->Info = $dbJson; $cache->write(); } return $ipService->getJSON(); } public function getDetails() { return $this->Info; } public function clearIPCache() { $this->write(false, false, true); } } |