JoomlaFolder Adapter
This is a custom adapter extends the local flysystem adapter. The goal is to ease dealing with Joomla files providing some prefixes that allow paths that are easy to remember and allows files to be moved around without changing your PHP code.
1. Usage
This adapter is loaded by default by the FileServer
class so you don’t need to specifically load it if you use FileServer
.
Usage through FileServer
This adapter is loaded by default by the FileServer
class so you don’t need to specifically load it if you use FileServer
like:
JLoader::import('flysystem.library');
use Phproberto\Joomla\Flysystem\FileServer;
$files = FileServer::instance();
// Admin file. Stored in administrator/manifests/libraries/joomla.xml
echo $files->read('admin://manifests/libraries/joomla.xml');
// Cache file. Stored in cache/error.php
echo $files->read('cache://error.php');
// Image file. Stored in /images/joomla_black.png
echo $files->read('image://joomla_black.png');
// Log file. Stored in /administrator/logs/error.php
echo $files->read('log://error.php');
// Layout file. Stored in /layouts/joomla/system/message.php
echo $files->read('layout://joomla/system/message.php');
// Library file. Stored in /libraries/joomla/filesystem/file.php
echo $files->read('library://joomla/filesystem/file.php');
// Media file. Stored in /media/jui/css/bootstrap.css
echo $files->read('media://jui/css/bootstrap.css');
// Module file. Stored in /modules/mod_menu/mod_menu.xml
echo $files->read('module://mod_menu/mod_menu.xml');
// Plugin file. Stored in /plugins/content/vote/vote.xml
echo $files->read('plugin://content/vote/vote.xml');
// Site file. Stored in /htaccess.txt
echo $files->read('site://htaccess.txt');
// Temp file. Stored in /tmp/index.html
echo $files->read('tmp://index.html');
Custom usage
Let’s say that you want to provide an adapter that access files on a specific joomla folder. You can use relative paths like:
JLoader::import('flysystem.library');
use Phproberto\Joomla\Flysystem\Filesystem;
use Phproberto\Joomla\Flysystem\Adapter\JoomlaFolder;
// This will use JPATH_SITE . /media/com_sample/images as source folder
$images = new Filesystem(new JoomlaFolder('media/com_sample/images'));
// Check if JPATH_SITE . /media/com_sample/images/sample-image.jpg exists
if ($images->has('sample-image.jpg'))
{
echo "It exists!";
}
2. Events
Global events.
These events allow to perform common actions for all the adapters with a single entry point.
onFlysystemBeforeLoadAdapter Called before an AdapterInterface instance is created.
/**
* Triggered before adapter has been loaded.
*
* @param AdapterInterface $adapter Adapter being instatiated
*
* @return void
*/
public function onFlysystemBeforeLoadAdapter(AdapterInterface $adapter)
onFlysystemAfterLoadAdapter Called after an AdapterInterface instance has been created.
/**
* Triggered after adapter has been loaded.
*
* @param AdapterInterface $adapter Adapter being instatiated
*
* @return void
*/
public function onFlysystemAfterLoadAdapter(AdapterInterface $adapter)
Custom events
onFlysystemBeforeLoadJoomlaFolderAdapter Called before an JoomlaFolder adapter instance has been created.
/**
* Triggered before adapter has been loaded.
*
* @param JoomlaFolder $adapter Adapter being instatiated
* @param string $path Path being loaded
* @param string $config Configuration for the adapter
*
* @return void
*/
public function onFlysystemBeforeLoadJoomlaFolderAdapter(JoomlaFolder $adapter, string &$path, array &$config)
onFlysystemAfterLoadJoomlaFolderAdapter Called after an JoomlaFolder adapter instance has been created.
/**
* Triggered after adapter has been loaded.
*
* @param JoomlaFolder $adapter Adapter being instatiated.
* @param string $path Path being loaded.
* @param string $config Configuration for the adapter.
*
* @return void
*/
public function onFlysystemAfterLoadJoomlaFolderAdapter(JoomlaFolder $adapter, string $path, array $config)