-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPost.php
58 lines (46 loc) · 1.24 KB
/
Post.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
<?php
namespace Swiftmade\Blogdown\Models;
use ArrayAccess;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Support\Arrayable;
use Swiftmade\Blogdown\Support\AttributeTypes;
use Swiftmade\Blogdown\Models\Concerns\HasArrayAccess;
class Post implements ArrayAccess, Arrayable
{
use HasArrayAccess;
protected $cache;
protected $data;
public static $casts = [
'date' => AttributeTypes::Date,
'author' => AttributeTypes::Author,
'tags' => AttributeTypes::Tags,
];
public function __construct(array $data)
{
$this->data = $data;
}
public function slug()
{
return Str::slug($this->data['view_name']);
}
public function isDraft()
{
return isset($this->data['draft']) && $this->data['draft'];
}
public function view()
{
return Config::get('blogdown.blog_folder') . '.' . $this->view_name;
}
protected function getAttribute($attribute)
{
$value = $this->data[$attribute] ?? null;
if (! isset(self::$casts[$attribute])) {
return $value;
}
return AttributeTypes::cast(
$value,
self::$casts[$attribute]
);
}
}