Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 03145a5

Browse files
committed
ENH: refs #236. Add style tests and fix style in api models
1 parent 34c5a02 commit 03145a5

File tree

10 files changed

+86
-84
lines changed

10 files changed

+86
-84
lines changed

modules/api/models/AppDao.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
/** Api App Dao */
34
class Api_AppDao extends MIDAS_GlobalDao
45
{
56

modules/api/models/AppModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3+
/** App model for api module */
34
class Api_AppModel extends MIDASModel
45
{
5-
public $moduleName='api';
6-
6+
public $moduleName = 'api';
77
}
88
?>
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<?php
22
abstract class Api_TokenModelBase extends Api_AppModel
33
{
4+
/** constructor */
45
public function __construct()
56
{
67
parent::__construct();
78
$this->_name = 'api_token';
89
$this->_key = 'token_id';
910

10-
$this->_mainData= array(
11-
'token_id'=> array('type'=>MIDAS_DATA),
12-
'userapi_id'=> array('type'=>MIDAS_DATA),
13-
'token'=> array('type'=>MIDAS_DATA),
14-
'expiration_date'=> array('type'=>MIDAS_DATA),
15-
'userapi' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Userapi','module' => 'api', 'parent_column' => 'userapi_id', 'child_column' => 'userapi_id'),
11+
$this->_mainData = array(
12+
'token_id' => array('type' => MIDAS_DATA),
13+
'userapi_id' => array('type' => MIDAS_DATA),
14+
'token' => array('type' => MIDAS_DATA),
15+
'expiration_date' => array('type' => MIDAS_DATA),
16+
'userapi' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Userapi', 'module' => 'api', 'parent_column' => 'userapi_id', 'child_column' => 'userapi_id'),
1617
);
1718
$this->initialize(); // required
1819
} // end __construct()
19-
20-
abstract function cleanExpired();
21-
20+
21+
abstract function cleanExpired();
22+
2223
} // end class AssetstoreModelBase
2324
?>
Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?php
22
abstract class Api_UserapiModelBase extends Api_AppModel
33
{
4+
/** constructor */
45
public function __construct()
56
{
67
parent::__construct();
78
$this->_name = 'api_userapi';
89
$this->_key = 'userapi_id';
910

10-
$this->_mainData= array(
11-
'userapi_id'=> array('type'=>MIDAS_DATA),
12-
'user_id'=> array('type'=>MIDAS_DATA),
13-
'apikey'=> array('type'=>MIDAS_DATA),
14-
'application_name'=> array('type'=>MIDAS_DATA),
15-
'token_expiration_time'=> array('type'=>MIDAS_DATA),
16-
'creation_date'=> array('type'=>MIDAS_DATA),
11+
$this->_mainData = array(
12+
'userapi_id' => array('type' => MIDAS_DATA),
13+
'user_id' => array('type' => MIDAS_DATA),
14+
'apikey' => array('type' => MIDAS_DATA),
15+
'application_name' => array('type' => MIDAS_DATA),
16+
'token_expiration_time' => array('type' => MIDAS_DATA),
17+
'creation_date' => array('type' => MIDAS_DATA),
1718
'user' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'User', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
1819
);
1920
$this->initialize(); // required
2021
} // end __construct()
2122

22-
abstract function createKeyFromEmailPassword($appname,$email,$password);
23-
abstract function getByAppAndEmail($appname,$email);
24-
abstract function getByAppAndUser($appname,$userDao);
25-
abstract function getToken($email,$apikey,$appname);
23+
abstract function createKeyFromEmailPassword($appname, $email, $password);
24+
abstract function getByAppAndEmail($appname, $email);
25+
abstract function getByAppAndUser($appname, $userDao);
26+
abstract function getToken($email, $apikey, $appname);
2627
abstract function getUserapiFromToken($token);
2728
abstract function getByUser($userDao);
2829

@@ -43,14 +44,14 @@ function createDefaultApiKey($userDao)
4344
->where('application_name = ?', 'Default'));
4445
foreach($rowset as $row)
4546
{
46-
$userApiDao= $this->initDao('Userapi', $row, 'api');
47+
$userApiDao = $this->initDao('Userapi', $row, 'api');
4748
$this->delete($userApiDao);
4849
}
4950

5051
// Save new default key
5152
$key = md5($userDao->getEmail().$userDao->getPassword().'Default');
52-
$this->loadDaoClass('UserapiDao','api');
53-
$userApiDao=new Api_UserapiDao();
53+
$this->loadDaoClass('UserapiDao', 'api');
54+
$userApiDao = new Api_UserapiDao();
5455
$userApiDao->setUserId($userDao->getKey());
5556
$userApiDao->setApplicationName('Default');
5657
$userApiDao->setApikey($key);
@@ -59,16 +60,16 @@ function createDefaultApiKey($userDao)
5960
$this->save($userApiDao);
6061
}
6162

62-
/** Create a new API key */
63-
function createKey($userDao,$applicationname,$tokenexperiationtime)
63+
/** Create a new API key */
64+
function createKey($userDao, $applicationname, $tokenexperiationtime)
6465
{
6566
if(!$userDao instanceof UserDao || !is_string($applicationname) || !is_string($tokenexperiationtime) || empty($applicationname))
6667
{
6768
throw new Zend_Exception("Error parameter");
6869
}
6970

7071
// Check that the applicationname doesn't exist for this user
71-
$userapiDao=$this->getByAppAndUser($applicationname, $userDao);
72+
$userapiDao = $this->getByAppAndUser($applicationname, $userDao);
7273
if(!empty($userapiDao))
7374
{
7475
return false;
@@ -80,22 +81,18 @@ function createKey($userDao,$applicationname,$tokenexperiationtime)
8081
$length = 40;
8182

8283
// seed with microseconds
83-
function make_seed_recoverpass()
84-
{
85-
list($usec, $sec) = explode(' ', microtime());
86-
return (float) $sec + ((float) $usec * 100000);
87-
}
88-
srand(make_seed_recoverpass());
84+
list($usec, $sec) = explode(' ', microtime());
85+
srand((float) $sec + ((float) $usec * 100000));
8986

9087
$key = "";
91-
$max=strlen($keychars)-1;
92-
for ($i=0; $i<$length; $i++)
88+
$max = strlen($keychars) - 1;
89+
for($i = 0; $i < $length; $i++)
9390
{
9491
$key .= substr($keychars, rand(0, $max), 1);
9592
}
9693

97-
$this->loadDaoClass('UserapiDao','api');
98-
$userApiDao=new Api_UserapiDao();
94+
$this->loadDaoClass('UserapiDao', 'api');
95+
$userApiDao = new Api_UserapiDao();
9996
$userApiDao->setUserId($userDao->getKey());
10097
$userApiDao->setApikey($key);
10198
$userApiDao->setApplicationName($applicationname);
@@ -104,7 +101,7 @@ function make_seed_recoverpass()
104101

105102
$this->save($userApiDao);
106103
return $userApiDao;
107-
}//end createKey
104+
}
108105

109-
} // end class AssetstoreModelBase
106+
}
110107
?>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
/** Dao for the api token */
23
class Api_TokenDao extends AppDao
34
{
4-
public $_model='Token';
5-
public $_module='api';
5+
public $_model = 'Token';
6+
public $_module = 'api';
67
}
78
?>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
/** Dao for user api key */
23
class Api_UserapiDao extends AppDao
34
{
4-
public $_model='Userapi';
5-
public $_module='api';
5+
public $_model = 'Userapi';
6+
public $_module = 'api';
67
}
78
?>

modules/api/models/pdo/TokenModel.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
2-
//App::import("Vendor",'Sanitize');
2+
33
require_once BASE_PATH.'/modules/api/models/base/TokenModelBase.php';
44

5+
/** Api token model implementation */
56
class Api_TokenModel extends Api_TokenModelBase
67
{
7-
8+
/** Remove all expired api tokens */
89
function cleanExpired()
910
{
10-
$sql =$this->database->select()->where('expiration_date < ?', date("c"));
11+
$sql = $this->database->select()->where('expiration_date < ?', date("c"));
1112
$rowset = $this->database->fetchAll($sql);
12-
foreach ($rowset as $row)
13+
foreach($rowset as $row)
1314
{
14-
$tmpDao= $this->initDao('Token', $row,'api');
15+
$tmpDao = $this->initDao('Token', $row, 'api');
1516
parent::delete($tmpDao);
1617
}
1718
}

0 commit comments

Comments
 (0)