1 | <?php |
||
49 | class Repository implements RepositoryInterface |
||
50 | { |
||
51 | /** |
||
52 | * Apparat base URL |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $url = null; |
||
57 | /** |
||
58 | * Adapter strategy |
||
59 | * |
||
60 | * @var AdapterStrategyInterface |
||
61 | */ |
||
62 | protected $adapterStrategy = null; |
||
63 | /** |
||
64 | * Instance specific object cache |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $objectCache = []; |
||
69 | |||
70 | /******************************************************************************* |
||
71 | * PUBLIC METHODS |
||
72 | *******************************************************************************/ |
||
73 | |||
74 | /** |
||
75 | * Repository constructor |
||
76 | * |
||
77 | * @param string $url Apparat base URL |
||
78 | * @param array $config Adapter strategy configuration |
||
79 | */ |
||
80 | 12 | public function __construct( |
|
81 | $url, |
||
82 | array $config |
||
83 | ) { |
||
84 | 12 | $this->url = rtrim('/'.$url, '/'); |
|
85 | 12 | $this->adapterStrategy = Kernel::create(Service::class)->getAdapterStrategyFactory()->createFromConfig($config); |
|
86 | 8 | } |
|
87 | |||
88 | /** |
||
89 | * Find objects by selector |
||
90 | * |
||
91 | * @param SelectorInterface $selector Object selector |
||
92 | * @return Collection Object collection |
||
93 | */ |
||
94 | 7 | public function findObjects(SelectorInterface $selector) |
|
98 | |||
99 | /** |
||
100 | * Add an object to the repository |
||
101 | * |
||
102 | * @param ObjectInterface $object Object |
||
103 | * @return boolean Success |
||
104 | */ |
||
105 | public function addObject(ObjectInterface $object) |
||
109 | |||
110 | /** |
||
111 | * Delete and object from the repository |
||
112 | * |
||
113 | * @param ObjectInterface $object Object |
||
114 | * @return boolean Success |
||
115 | */ |
||
116 | public function deleteObject(ObjectInterface $object) |
||
120 | |||
121 | /** |
||
122 | * Update an object in the repository |
||
123 | * |
||
124 | * @param ObjectInterface $object Object |
||
125 | * @return bool Success |
||
126 | */ |
||
127 | public function updateObject(ObjectInterface $object) |
||
131 | |||
132 | /** |
||
133 | * Load an object from this repository |
||
134 | * |
||
135 | * @param PathInterface $path Object path |
||
136 | * @return ObjectInterface Object |
||
137 | */ |
||
138 | 16 | public function loadObject(PathInterface $path) |
|
153 | |||
154 | /** |
||
155 | * Return the repository's adapter strategy |
||
156 | * |
||
157 | * @return AdapterStrategyInterface Adapter strategy |
||
158 | */ |
||
159 | 6 | public function getAdapterStrategy() |
|
163 | |||
164 | /** |
||
165 | * Return the repository URL (relative to Apparat base URL) |
||
166 | * |
||
167 | * @return string Repository URL |
||
168 | */ |
||
169 | 2 | public function getUrl() |
|
173 | } |
||
174 |