|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the m1\vars library |
|
5
|
|
|
* |
|
6
|
|
|
* (c) m1 <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @package m1/vars |
|
12
|
|
|
* @version 0.1.0 |
|
13
|
|
|
* @author Miles Croxford <[email protected]> |
|
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
|
15
|
|
|
* @license http://github.com/m1/vars/blob/master/LICENSE |
|
16
|
|
|
* @link http://github.com/m1/vars/blob/master/README.MD Documentation |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace M1\Vars\Loader; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The abstract loader for loaders to be based on |
|
23
|
|
|
* |
|
24
|
|
|
* @since 0.1.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class AbstractLoader |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* The content from the entity |
|
30
|
|
|
* |
|
31
|
|
|
* @var mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $content; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The passed entity to be loaded |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $entity; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The supported extensions |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
public static $supported = array(); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Construct the loader with the passed entity |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $entity The passed entity |
|
53
|
|
|
*/ |
|
54
|
58 |
|
public function __construct($entity) |
|
55
|
|
|
{ |
|
56
|
58 |
|
$this->entity = $entity; |
|
57
|
58 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* The function what loads the content from the entity |
|
61
|
|
|
* |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
*/ |
|
64
|
|
|
abstract public function load(); |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Checks whether the loader supports the file extension |
|
68
|
|
|
* |
|
69
|
|
|
* @return bool Does the loader support the file |
|
70
|
|
|
*/ |
|
71
|
57 |
|
public function supports() |
|
72
|
|
|
{ |
|
73
|
57 |
|
$extension = pathinfo($this->entity, PATHINFO_EXTENSION); |
|
74
|
57 |
|
return in_array($extension, static::$supported); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Sets what the loader supports |
|
79
|
|
|
* |
|
80
|
|
|
* @param array $supports Set the extensions the loader supports |
|
81
|
|
|
*/ |
|
82
|
4 |
|
public function setSupports(array $supports) |
|
83
|
|
|
{ |
|
84
|
4 |
|
static::$supported = $supports; |
|
85
|
4 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the content |
|
89
|
|
|
* |
|
90
|
|
|
* @return mixed The content |
|
91
|
|
|
*/ |
|
92
|
51 |
|
public function getContent() |
|
93
|
|
|
{ |
|
94
|
51 |
|
return $this->content; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|