22namespace Packaged \Dispatch ;
33
44use Composer \Autoload \ClassLoader ;
5+ use Packaged \Config \Provider \ConfigProvider ;
56use Packaged \Dispatch \Resources \AbstractDispatchableResource ;
67use Packaged \Dispatch \Resources \AbstractResource ;
78use Packaged \Dispatch \Resources \DispatchableResource ;
1314
1415class Dispatch
1516{
17+
1618 /**
1719 * @var Dispatch
1820 */
@@ -25,6 +27,10 @@ class Dispatch
2527
2628 protected $ _baseUri ;
2729 protected $ _requireFileHash = false ;
30+ /**
31+ * @var ConfigProvider
32+ */
33+ protected $ _config ;
2834
2935 const RESOURCES_DIR = 'resources ' ;
3036 const VENDOR_DIR = 'vendor ' ;
@@ -58,6 +64,7 @@ public static function destroy()
5864 public function __construct ($ projectRoot , $ baseUri = null , ClassLoader $ loader = null )
5965 {
6066 $ this ->_projectRoot = $ projectRoot ;
67+ $ this ->_config = new ConfigProvider ();
6168 $ this ->_resourceStore = new ResourceStore ();
6269 $ this ->_baseUri = $ baseUri ;
6370 $ this ->_classLoader = $ loader ;
@@ -223,7 +230,8 @@ public function handleRequest(Request $request): Response
223230 return Response::create ("File Not Found " , 404 );
224231 }
225232
226- $ resource = ResourceFactory::getExtensionResource (pathinfo ($ fullPath , PATHINFO_EXTENSION ));
233+ $ ext = pathinfo ($ fullPath , PATHINFO_EXTENSION );
234+ $ resource = ResourceFactory::getExtensionResource ($ ext );
227235 if ($ resource instanceof DispatchableResource)
228236 {
229237 $ resource ->setManager ($ manager );
@@ -236,6 +244,11 @@ public function handleRequest(Request $request): Response
236244 {
237245 $ resource ->setFilePath ($ fullPath );
238246 $ resource ->setContent (file_get_contents ($ fullPath ));
247+
248+ if ($ this ->config ()->has ('ext. ' . $ ext ))
249+ {
250+ $ resource ->setOptions ($ this ->config ()->getSection ('ext. ' . $ ext )->getItems ());
251+ }
239252 }
240253 return ResourceFactory::create ($ resource );
241254 }
@@ -276,6 +289,11 @@ public function store()
276289 return $ this ->_resourceStore ;
277290 }
278291
292+ public function config ()
293+ {
294+ return $ this ->_config ;
295+ }
296+
279297 public function calculateRelativePath ($ filePath )
280298 {
281299 return ltrim (str_replace ($ this ->_projectRoot , '' , $ filePath ), '/ \\' );
0 commit comments