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\Model\UploadPref;
13: use rsanchez\Deep\Repository\UploadPrefRepositoryInterface;
14:
15: /**
16: * Repository of all UploadPrefs
17: */
18: class ConfigUploadPrefRepository implements UploadPrefRepositoryInterface
19: {
20: /**
21: * Array of UploadPrefs keyed by id
22: * @var array
23: */
24: protected $uploadPrefsById = array();
25:
26: /**
27: * Constructor
28: *
29: * @param \rsanchez\Deep\Model\UploadPref $model
30: */
31: public function __construct(array $uploadPrefs)
32: {
33: foreach ($uploadPrefs as $id => $config) {
34: $uploadPref = new UploadPref();
35:
36: $uploadPref->name = $config['name'];
37: $uploadPref->server_path = $config['server_path'];
38: $uploadPref->url = $config['url'];
39:
40: $this->uploadPrefsById[$id] = $uploadPref;
41: }
42: }
43:
44: /**
45: * Alias to getUploadPrefById
46: * @var int $id
47: * @return \rsanchez\Deep\Model\UploadPref|null
48: */
49: public function find($id)
50: {
51: return $this->getUploadPrefById($id);
52: }
53:
54: /**
55: * Get single UploadPref by ID
56: * @var int $id
57: * @return \rsanchez\Deep\Model\UploadPref|null
58: */
59: public function getUploadPrefById($id)
60: {
61: return array_key_exists($id, $this->uploadPrefsById) ? $this->uploadPrefsById[$id] : null;
62: }
63: }
64: