forked from neilcrookes/CakePHP-Twitter-API-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtwitter_app_model.php
76 lines (66 loc) · 1.98 KB
/
twitter_app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Plugin base model. Configures all models with regards the database
* configuration (the datasource for the plugin), table to use (none).
*
* @author Neil Crookes <[email protected]>
* @link http://www.neilcrookes.com
* @copyright (c) 2010 Neil Crookes
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*/
class TwitterAppModel extends AppModel {
/**
* The datasource all models in the plugin use.
*
* @var string
*/
public $useDbConfig = 'twitter';
/**
* The models in the plugin get data from the web service, so they don't need
* a table.
*
* @var string
*/
public $useTable = false;
/**
* Methods in the models result in HTTP requests using the HttpSocket. So
* rather than do all the heavy lifting in the datasource, we set the various
* params of the request in the individual model methods. This ties the model
* to the data layer, but these models are especially for this datasource.
*
* @var array
*/
public $request = array();
/**
* Adds the datasource to the connection manager if it's not already there,
* which it won't be if you've not added it to your app/config/database.php
* file.
*
* @param $id
* @param $table
* @param $ds
*/
public function __construct($id = false, $table = null, $ds = null) {
$sources = ConnectionManager::sourceList();
if (!in_array('twitter', $sources)) {
ConnectionManager::create('twitter', array('datasource' => 'Twitter.TwitterSource'));
}
parent::__construct($id, $table, $ds);
}
/**
* Merges passed config with datasource existing config and returns the merged
* array.
*
* @param array $config
* @return array
*/
public function setDataSourceConfig($config = array()) {
$ds = $this->getDataSource($this->useDbConfig);
if (!is_array($ds->config)) {
$ds->config = array($ds->config);
}
$ds->config = array_merge($ds->config, $config);
return $ds->config;
}
}
?>