Skip to content

Commit 1ff8e8e

Browse files
author
Matt Oakes
committed
Added phpdoc comments
1 parent 4936653 commit 1ff8e8e

File tree

6 files changed

+292
-21
lines changed

6 files changed

+292
-21
lines changed

lastfmapi/class/apibase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/**
3+
* File that contains all base methods used by all api calls
4+
* @package base
5+
*/
26
/**
37
* Stores the methods used by all api calls
48
* @package base

lastfmapi/class/cache.php

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
11
<?php
2-
2+
/**
3+
* Stores the caching methods
4+
* @package base
5+
*/
6+
/**
7+
* Allows access to the caching methods to cache data when api calls are made
8+
* @package base
9+
*/
310
class lastfmApiCache {
11+
/**
12+
* Stores the batabase class
13+
* @var class
14+
*/
415
private $db;
16+
/**
17+
* Stores the batabase type
18+
* @var string
19+
*/
520
private $type;
21+
/**
22+
* Stores the error details
23+
* @var array
24+
*/
625
public $error;
26+
/**
27+
* Stores the path to the sqlite database
28+
* @var string
29+
*/
730
private $path;
31+
/**
32+
* Stores the amount of time to cahce for
33+
* @var integer
34+
*/
835
private $cache_length;
36+
/**
37+
* Stores the config array
38+
* @var array
39+
*/
940
private $config;
41+
/**
42+
* States if caching is enabled or not
43+
* @var boolean
44+
*/
1045
private $enabled;
1146

47+
/**
48+
* Run when the class is created
49+
* @param array $config The config array
50+
* @uses lastfmApiDatabase
51+
*/
1252
function __construct($config) {
1353
$this->config = $config;
1454

@@ -47,6 +87,11 @@ function __construct($config) {
4787
}
4888
}
4989

90+
/**
91+
* Internal method to chack if caching is enabled
92+
* @access private
93+
* @return void
94+
*/
5095
private function check_if_enabled() {
5196
if ( $this->config['enabled'] == true && function_exists('sqlite_open') ) {
5297
$this->enabled = true;
@@ -56,6 +101,11 @@ private function check_if_enabled() {
56101
}
57102
}
58103

104+
/**
105+
* Internal method to check if the table exists
106+
* @access private
107+
* @return void
108+
*/
59109
private function check_table_exists() {
60110
if ( $this->type == 'sqlite' ) {
61111
$query = "SELECT count(*) FROM sqlite_master WHERE name='cache'";
@@ -80,6 +130,11 @@ private function check_table_exists() {
80130
}
81131
}
82132

133+
/**
134+
* Internal method to create the table if it doesn't exist
135+
* @access private
136+
* @return void
137+
*/
83138
private function create_table() {
84139
if ( $this->type == 'sqlite' ) {
85140
$auto_increase = '';
@@ -97,6 +152,12 @@ private function create_table() {
97152
}
98153
}
99154

155+
/**
156+
* Searches the database for the cahce date. Returns an array if it exists or false if it doesn't
157+
* @access public
158+
* @param array $unique_vars Array of variables that are unique to this piece of cached data
159+
* @return string
160+
*/
100161
public function get($unique_vars) {
101162
if ( $this->enabled == true ) {
102163
$query = "SELECT expires, body FROM cache WHERE unique_vars='".htmlentities(serialize($unique_vars))."' LIMIT 1";
@@ -126,6 +187,13 @@ public function get($unique_vars) {
126187
}
127188
}
128189

190+
/**
191+
* Adds new cache data to the database
192+
* @access public
193+
* @param array $unique_vars Array of variables that are unique to this piece of cached data
194+
* @param string $body The contents of the cache to put into the database
195+
* @return boolean
196+
*/
129197
public function set($unique_vars, $body) {
130198
if ( $this->enabled == true ) {
131199
if ( $this->type == 'sqlite' ) {
@@ -148,6 +216,12 @@ public function set($unique_vars, $body) {
148216
}
149217
}
150218

219+
/**
220+
* Internal method to delete unneeded cache data
221+
* @access private
222+
* @param array $unique_vars Array of variables that are unique to this piece of cached data
223+
* @return boolean
224+
*/
151225
private function del($unique_vars) {
152226
$query = "DELETE FROM cache WHERE unique_vars='".htmlentities(serialize($unique_vars))."'";
153227
if ( $this->db->query($query) ) {
@@ -159,6 +233,11 @@ private function del($unique_vars) {
159233
}
160234
}
161235

236+
/**
237+
* Internal method to show all cached data (used for debugging)
238+
* @access private
239+
* @return boolean
240+
*/
162241
private function show_all() {
163242
$query = "SELECT expires, body FROM cache";
164243
if ( $result = $this->db->query($query) ) {

lastfmapi/class/mysql.php

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
<?php
2-
2+
/**
3+
* Stores the mysql database methods
4+
* @package base
5+
*/
6+
/**
7+
* Allows access to the mysql database using a standard database class
8+
* @package base
9+
*/
310
class lastfmApiDatabase {
4-
var $host;
5-
var $dbUser;
6-
var $dbPass;
7-
var $dbName;
8-
var $dbConn;
9-
var $error;
11+
/**
12+
* Stores the host name
13+
* @var string
14+
*/
15+
private $host;
16+
/**
17+
* Stores the username
18+
* @var string
19+
*/
20+
private $dbUser;
21+
/**
22+
* Stores the password
23+
* @var string
24+
*/
25+
private $dbPass;
26+
/**
27+
* Stores the database name
28+
* @var string
29+
*/
30+
private $dbName;
31+
/**
32+
* Stores the connection status
33+
* @var boolean
34+
*/
35+
public $dbConn;
36+
/**
37+
* Stores the error details
38+
* @var array
39+
*/
40+
public $error;
1041

42+
/**
43+
* Run when the class is created. Sets up the variables
44+
* @param string $host Database host address
45+
* @param string $dbUser Database username
46+
* @param string $dbPass Database password
47+
* @param string $dbName Database name
48+
* @return void
49+
*/
1150
function __construct($host,$dbUser,$dbPass,$dbName) {
1251
$this->host = $host;
1352
$this->dbUser = $dbUser;
@@ -17,7 +56,11 @@ function __construct($host,$dbUser,$dbPass,$dbName) {
1756
$this->connectToDb();
1857
}
1958

20-
function connectToDb () {
59+
/**
60+
* Internal command to connect to the database
61+
* @return void
62+
*/
63+
private function connectToDb () {
2164
if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) {
2265
$this->handleError();
2366
return false;
@@ -28,11 +71,21 @@ function connectToDb () {
2871
}
2972
}
3073

31-
function handleError () {
74+
/**
75+
* Internal command to handle errors and populate the error variable
76+
* @return void
77+
*/
78+
private function handleError () {
3279
$this->error = mysql_error($this->dbConn);
3380
}
3481

35-
function query($sql) {
82+
/**
83+
* Command which runs queries. Returns a class on success and flase on error
84+
* @param string $sql The SQL query to run
85+
* @return class
86+
* @uses lastfmApiDatabase_result
87+
*/
88+
public function query($sql) {
3689
if ( !$queryResource = mysql_query($sql, $this->dbConn) ) {
3790
echo mysql_error();
3891
$this->handleError();
@@ -45,16 +98,38 @@ function query($sql) {
4598
}
4699
}
47100

101+
/**
102+
* A class which allows interaction with results when a query is run by lastfmApiDatabase
103+
* @package base
104+
*/
48105
class lastfmApiDatabase_result {
106+
/**
107+
* Stores the mysql class
108+
* @var class
109+
*/
49110
var $mysql;
111+
/**
112+
* Stores the query
113+
* @var class
114+
*/
50115
var $query;
51116

117+
/**
118+
* Run when the class is created. Sets up the variables
119+
* @param class $mysql The mysql class
120+
* @param class $query The query
121+
* @return void
122+
*/
52123
function lastfmApiDatabase_result(&$mysql,$query) {
53124
$this->mysql = &$mysql;
54125
$this->query = $query;
55126
}
56127

57-
function fetch () {
128+
/**
129+
* Fetches the next result
130+
* @return array
131+
*/
132+
public function fetch () {
58133
if ( $row = mysql_fetch_array($this->query) ) {
59134
return $row;
60135
}
@@ -67,6 +142,10 @@ function fetch () {
67142
}
68143
}
69144

145+
/**
146+
* Fetches all the results
147+
* @return array
148+
*/
70149
function fetchAll() {
71150
$result = array();
72151
while ( $row = mysql_fetch_array($this->query) ) {
@@ -75,6 +154,10 @@ function fetchAll() {
75154
return $result;
76155
}
77156

157+
/**
158+
* Shows the number of results
159+
* @return integer
160+
*/
78161
function size () {
79162
return mysql_num_rows($this->query);
80163
}

lastfmapi/class/socket.php

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
<?php
2-
2+
/**
3+
* Stores the socket methods
4+
* @package base
5+
*/
6+
/**
7+
* Allows access to the socket methods using a standard class
8+
* @package base
9+
*/
310
class lastfmApiSocket {
4-
var $handle;
5-
var $connection;
6-
var $host;
7-
var $port;
11+
/**
12+
* Stores the socket handler
13+
* @var class
14+
*/
15+
private $handle;
16+
/**
17+
* Stores the host name
18+
* @var string
19+
*/
20+
private $host;
21+
/**
22+
* Stores the port number
23+
* @var integer
24+
*/
25+
private $port;
826

27+
/**
28+
* Stores the error string
29+
* @var string
30+
*/
931
public $error_string;
32+
/**
33+
* Stores the error number
34+
* @var integer
35+
*/
1036
public $error_number;
1137

38+
/**
39+
* Run when the class is created. Sets the variables
40+
* @param string $host The host name
41+
* @param integer $port The port number
42+
* @return boolean
43+
*/
1244
function lastfmApiSocket ($host, $port) {
1345
// Set class variables
1446
$this->host = $host;
@@ -25,6 +57,12 @@ function lastfmApiSocket ($host, $port) {
2557
}
2658
}
2759

60+
/**
61+
* Send data through the socket and listen for a return
62+
* @param string $msg Data to send
63+
* @param string $type The type of data to return (array or string)
64+
* @return string|array
65+
*/
2866
function send ($msg, $type = '') {
2967
// Send message over connection
3068
fwrite($this->handle, $msg);
@@ -57,6 +95,10 @@ function send ($msg, $type = '') {
5795

5896
}
5997

98+
/**
99+
* Closes the connection
100+
* @return boolean
101+
*/
60102
function close () {
61103
// Close connection
62104
fclose($this->handle);

0 commit comments

Comments
 (0)