I would like to extend the gantry5 library files in Joomla, specifically the Platform class which can found in the file src/classes/Gantry/Framework/Platform.php. I want to be able to extend this file so I can add additional domains to the finder function so that that Gantry5 particles can be used with other components such as Hikashop.
Reading the documentation https://docs.gantry.org/gantry5/advanced/file-overrides it says:
PHP classes found in /libraries/gantry5 can also be overridden, but as they need to be autoloaded, this requires some additional manual intervention involving adding a loader for classes.
Can anyone expand on how a loader for the class overrides should be implemented?
Not sure if this was the way the Gantry 5 developers had in mind, but in the Joomla libraries folder where you can find the gantry5 library files, I created a folder called overrides in which I put the new platform.php file (with the changes I required) and the new finder and content loader files.
I then changed 3 lines in the gantry5 library composer.json file.
"autoload": {
"psr-4": {
"Gantry\\": "src/classes/Gantry"
}
},
to
"autoload": {
"psr-4": {
"Gantry\\": "src/classes/Gantry"
},
"exclude-from-classmap": ["src/classes/Gantry/Framework/Platform.php"],
"classmap": ["overrides"]
},
I then ran "composer dump-autoload" when I was in the folder with the gantry5 library composer.json file from the command line. This created all the necessary autoload files, while excluding the origin platform file from the classmap.
However I'm sure that when I update Gantry5, the files I have created will be deleted and it will be necessary to update the composer.json file again.