44
55use Exception ;
66use Illuminate \Http \Resources \Json \JsonResource ;
7- use Illuminate \Session \Store ;
87use Illuminate \Support \Facades \Storage ;
98use Illuminate \Support \Str ;
109use Juampi92 \APIResources \Exceptions \ResourceNotFoundException ;
1110use Juampi92 \APIResources \Exceptions \WrongConfigurationException ;
11+ use Juampi92 \APIResources \Resolvers \ResolverFactory ;
1212
1313class APIResourceManager
1414{
@@ -170,40 +170,9 @@ public function getBasePath(): string
170170 return $ this ->path ;
171171 }
172172
173- /**
174- * Returns the classname of the versioned resource,
175- * or it's latest version if it doesn't exist.
176- *
177- * Throws an exception if it cannot find it.
178- *
179- * @param string $classname
180- *
181- * @return string
182- * @throws ResourceNotFoundException
183- */
184- public function resolveClassname (string $ classname )
173+ public function getResourcesPath (): string
185174 {
186- $ path = $ this ->parseClassname ($ classname );
187-
188- // Check if the resource was found
189- if (class_exists ($ path )) {
190- return $ path ;
191- }
192-
193- // If we are on the latest version, stop searching
194- if ($ this ->isLatest ()) {
195- throw new Exceptions \ResourceNotFoundException ($ classname , $ path );
196- }
197-
198- // Search on the latest version
199- $ path = $ this ->parseClassname ($ classname , true );
200-
201- // If still does not exists, fail
202- if (! class_exists ($ path )) {
203- throw new Exceptions \ResourceNotFoundException ($ classname , $ path );
204- }
205-
206- return $ path ;
175+ return $ this ->resources ;
207176 }
208177
209178 /**
@@ -212,6 +181,7 @@ public function resolveClassname(string $classname)
212181 * @param bool $forceLatest Set to true if last version is required
213182 *
214183 * @return class-string<JsonResource>
184+ * @deprecated
215185 */
216186 protected function parseClassname (string $ classname , bool $ forceLatest = false ): string
217187 {
@@ -255,26 +225,15 @@ protected function resolveClassnameFromFilesystem(string $classname, string $ver
255225 */
256226 public function resolve (string $ classname ): APIResource
257227 {
258- $ path = $ this ->resolveClassname ($ classname );
259-
260- // Check if the resource was found
261- if (! class_exists ($ path )) {
262-
263- // If we are on the latest version, stop searching
264- if ($ this ->isLatest ()) {
265- throw new Exceptions \ResourceNotFoundException ($ classname , $ path );
266- }
267-
268- // Search on the latest version
269- $ path = $ this ->resolveClassname ($ classname , true );
270-
271- // If still does not exists, fail
272- if (! class_exists ($ path )) {
273- throw new Exceptions \ResourceNotFoundException ($ classname , $ path );
274- }
275- }
228+ return ResolverFactory::make ($ classname )->run ();
229+ }
276230
277- return new APIResource ($ path );
231+ /**
232+ * @throws ResourceNotFoundException
233+ */
234+ public function resolveClassname (string $ classname ): string
235+ {
236+ return ResolverFactory::make ($ classname )->dryRun ();
278237 }
279238
280239 /**
0 commit comments