Skip to content

Commit ea66203

Browse files
committed
Changed public interfaces to match standards.
1 parent bb49845 commit ea66203

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

class.IP2Proxy.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Database {
3232
*
3333
* @var string
3434
*/
35-
const VERSION = '1.1.0';
35+
const VERSION = '1.1.1';
3636

3737
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3838
// Error field constants ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -451,12 +451,26 @@ class Database {
451451
/**
452452
* Constructor
453453
*
454+
* @access public
455+
*/
456+
public function __construct() {
457+
}
458+
459+
/**
460+
* Destructor
461+
*
462+
* @access public
463+
*/
464+
public function __destruct() {
465+
}
466+
467+
/**
454468
* @access public
455469
* @param string $file Filename of the BIN database to load
456470
* @param int $mode Caching mode (one of FILE_IO, MEMORY_CACHE, or SHARED_MEMORY)
457471
* @throws \Exception
458472
*/
459-
public function __construct($file = null, $mode = self::FILE_IO, $defaultFields = self::ALL) {
473+
public function open($file = null, $mode = self::FILE_IO, $defaultFields = self::ALL) {
460474
// find the referred file and its size
461475
$rfile = self::findFile($file);
462476
$size = filesize($rfile);
@@ -569,11 +583,11 @@ public function __construct($file = null, $mode = self::FILE_IO, $defaultFields
569583
}
570584

571585
/**
572-
* Destructor
586+
* Close
573587
*
574588
* @access public
575589
*/
576-
public function __destruct() {
590+
public function close() {
577591
switch ($this->mode) {
578592
case self::FILE_IO:
579593
// free the file pointer
@@ -595,12 +609,11 @@ public function __destruct() {
595609
/**
596610
* Tear down a shared memory segment created for the given file
597611
*
598-
* @access public
599-
* @static
612+
* @access protected
600613
* @param string $file Filename of the BIN database whise segment must be deleted
601614
* @throws \Exception
602615
*/
603-
public static function shmTeardown($file) {
616+
protected function shmTeardown($file) {
604617
// verify the shmop extension is loaded
605618
if (!extension_loaded('shmop')) {
606619
throw new \Exception(__CLASS__ . ": Please make sure your PHP setup has the 'shmop' extension enabled.", self::EXCEPTION_NO_SHMOP);
@@ -1159,11 +1172,11 @@ public function getPackageVersion() {
11591172
/**
11601173
* Return this database's available fields
11611174
*
1162-
* @access public
1175+
* @access protected
11631176
* @param boolean $asNames Whether to return the mapped names intead of numbered constants
11641177
* @return array
11651178
*/
1166-
public function getFields($asNames = false) {
1179+
protected function getFields($asNames = false) {
11671180
$result = array_keys(array_filter(self::$columns, function ($field) {
11681181
return 0 !== $field[$this->type];
11691182
}));

example.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22
require 'class.IP2Proxy.php';
33

4-
$db = new \IP2Proxy\Database('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
4+
$db = new \IP2Proxy\Database();
5+
$db->open('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
56

67
$countryCode = $db->getCountryShort('1.0.241.135');
78
echo '<p><strong>Country Code: </strong>' . $countryCode . '</p>';
@@ -28,4 +29,6 @@
2829

2930
echo '<pre>';
3031
print_r($records);
31-
echo '</pre>';
32+
echo '</pre>';
33+
34+
$db->close();

0 commit comments

Comments
 (0)