-
Notifications
You must be signed in to change notification settings - Fork 0
Fake Protocols
Protocols are an important part of a URL. http
and https
, among many others, are at the forefront of each one.
However, when working within the confine of a framework, it can be tedious to remember the path of specific resources, like images, scripts or style sheets. That's why MFX introduces Fake Protocols.
Fake protocols have the same structure as regular protocols, but they can be translated to actual protocols to easily address specific resources.
For example, MFX defines a mfxjs
fake protocol that, by default, targets vendor/chsxf/mfx/static/js/
. So, when using the URL mfxjs://somescript.js
, MFX will translate it to vendor/chsxf/mfx/static/js/somescripts.js
automatically.
Fake protocols are defined once at startup through the fake_protocols
configuration directive.
'fake_protocols' => [
'js' => 'application/static/js',
'css' => 'application/static/css'
]
Fake protocol are automatically translated when the pages are sent to the browser. However, you may want to translate some URLs manually on occasion.
To that purpose, use the CoreManager::convertFakeProtocols(string $str)
method.
// -- From a route
$templateService = $this->serviceProvider->getTemplateService();
$str = 'My translated URL is mfxjs://test.js';
echo $templateService->convertFakeProtocols($str);
// Will output:
// My translated URL is vendor/chsxf/mfx/static/js/test.js
MFX defines several fake protocols by default, allowing easy access to static files provided by the framework:
Key | Default Path |
---|---|
mfxcss |
vendor/chsxf/mfx/static/css |
mfxjs |
vendor/chsxf/mfx/static/js |
Getting Started | Framework Reference | API Reference | MFX is released under the MIT license