-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbase.php
More file actions
99 lines (85 loc) · 2 KB
/
Copy pathbase.php
File metadata and controls
99 lines (85 loc) · 2 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php namespace Feather\Core;
use Str;
use Cache;
use Event;
use Eloquent;
use Feather\Config;
class Base extends Eloquent {
/**
* The default connection used by Feather.
*
* @var string
*/
public static $connection = FEATHER_DATABASE;
/**
* Array of cachable items.
*
* @var array
*/
public static $cachable = array(
'place' => array('place', 'place_id'),
'user' => array('user', 'user_id'),
'author' => array('user', 'user_id')
);
/**
* Cache time in minutes.
*
* @var int
*/
const cache_time = 720;
/**
* Log a query that can not or will not be logged by the normal query logger.
*
* @param string $sql
* @param int $time
* @param array $bindings
* @return void
*/
protected static function log($sql, $time, $bindings = array())
{
if(Config::get('laravel: database.profile'))
{
Event::fire('laravel.query', array($sql, $bindings, number_format((microtime(true) - $time) * 1000, 2)));
}
}
/**
* Find a model by its primary key.
*
* @param string $id
* @param array $columns
* @return Model
*/
public function _find($id, $columns = array('*'))
{
$key = explode('\\', get_called_class());
$key = Str::lower(array_pop($key));
if(isset(static::$cachable[$key]))
{
list($group, $foreign) = static::$cachable[$key];
if(Cache::has("{$group}_{$id}"))
{
return Cache::get("{$group}_{$id}");
}
}
return $this->query()->where(static::$key, '=', $id)->first($columns);
}
/**
* Handle the dynamic retrieval of attributes and associations.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if(isset(static::$cachable[$key]) and !isset($this->attributes[$key]) and !isset($this->relationships[$key]))
{
list($group, $foreign) = static::$cachable[$key];
if(Cache::has("{$group}_{$this->$foreign}"))
{
return Cache::get("{$group}_{$this->$foreign}");
}
}
// Of course if it's not in there we'll just continue on as per normal.
return parent::__get($key);
}
}