1: <?php
2:
3: /**
4: * Deep
5: *
6: * @package rsanchez\Deep
7: * @author Rob Sanchez <info@robsanchez.com>
8: */
9:
10: namespace rsanchez\Deep\Repository;
11:
12: use rsanchez\Deep\Collection\UploadPrefCollection;
13: use rsanchez\Deep\Model\UploadPref;
14: use rsanchez\Deep\Repository\AbstractDeferredRepository;
15: use rsanchez\Deep\Repository\UploadPrefRepositoryInterface;
16:
17: /**
18: * Repository of all UploadPrefs
19: */
20: class UploadPrefRepository extends AbstractDeferredRepository implements UploadPrefRepositoryInterface
21: {
22: /**
23: * Array of UploadPrefs keyed by id
24: * @var array
25: */
26: protected $uploadPrefsById = array();
27:
28: /**
29: * Constructor
30: *
31: * @param \rsanchez\Deep\Model\UploadPref $model
32: */
33: public function __construct(UploadPref $model)
34: {
35: parent::__construct($model);
36: }
37:
38: /**
39: * {@inheritdoc}
40: */
41: protected function boot()
42: {
43: parent::boot();
44:
45: foreach ($this->collection as $uploadPref) {
46: $this->uploadPrefsById[$uploadPref->id] = $uploadPref;
47: }
48: }
49:
50: /**
51: * Alias to getUploadPrefById
52: * @var int $id
53: * @return \rsanchez\Deep\Model\UploadPref|null
54: */
55: public function find($id)
56: {
57: return $this->getUploadPrefById($id);
58: }
59:
60: /**
61: * Get single UploadPref by ID
62: * @var int $id
63: * @return \rsanchez\Deep\Model\UploadPref|null
64: */
65: public function getUploadPrefById($id)
66: {
67: $this->boot();
68:
69: return array_key_exists($id, $this->uploadPrefsById) ? $this->uploadPrefsById[$id] : null;
70: }
71:
72: /**
73: * Get Collection of all UploadPrefs
74: *
75: * @return \rsanchez\Deep\Collection\UploadPrefCollection
76: */
77: public function getUploadPrefs()
78: {
79: $this->boot();
80:
81: return $this->collection;
82: }
83: }
84: