-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseController.php
More file actions
80 lines (71 loc) · 1.93 KB
/
BaseController.php
File metadata and controls
80 lines (71 loc) · 1.93 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
<?php
declare(strict_types=1);
namespace Effectra\Core\Controller;
use Effectra\Core\Application;
use Effectra\Core\Cache\AppCache;
use Effectra\Core\Utils\Collection;
use Effectra\Core\Contracts\ModelInterface;
use Effectra\Core\Validator;
use Psr\Cache\CacheItemPoolInterface;
use Psr\SimpleCache\CacheInterface;
use Psr\Log\LoggerInterface;
/**
* Class BaseController
*
* The base controller class for controllers in the Effectra\Core\Controller namespace.
* It provides common functionality and dependencies used by controllers.
*/
class BaseController
{
/**
* The model associated with the controller.
*
* @var ModelInterface|null
*/
protected ?ModelInterface $model = null;
/**
* The cache instance used by the controller.
*
* @var CacheInterface|CacheItemPoolInterface
*/
protected CacheInterface|CacheItemPoolInterface $cache;
/**
* The collection object used by the controller.
*
* @var \ArrayAccess|\Countable|\IteratorAggregate
*/
protected \ArrayAccess|\Countable|\IteratorAggregate $collection;
/**
* The validator instance used by the controller.
*
* @var Validator
*/
protected Validator $validate;
/**
* The logger instance used by the controller.
*
* @var LoggerInterface
*/
protected LoggerInterface $log;
/**
* Create a new BaseController instance.
*
* Initializes the collection, validator, cache, and logger dependencies.
*/
public function __construct()
{
$this->collection = new Collection();
$this->validate = new Validator();
$this->cache = AppCache::getDriver();
$this->log = Application::log();
}
/**
* Set the model for the controller.
*
* @param ModelInterface $model The model instance to set.
*/
public function setModel(ModelInterface $model): void
{
$this->model = $model;
}
}