Source for file platform.php
Documentation is available at platform.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
// Protect from unauthorized access
* Part of the FOF Platform Abstraction Layer. It implements everything that
* depends on the platform FOF is running under, e.g. the Joomla! CMS front-end,
* the Joomla! CMS back-end, a CLI Joomla! Platform app, a bespoke Joomla!
* Platform / Framework web application and so on.
* This is the abstract class implementing some basic housekeeping functionality
* and provides the static interface to get the appropriate Platform object for
* use in the rest of the framework.
* @package FrameworkOnFramework
abstract class FOFPlatform implements FOFPlatformInterface
* The ordering for this platform class. The lower this number is, the more
* important this class becomes. Most important enabled class ends up being
* Caches the enabled status of this platform class.
* The list of paths where platform class files will be looked for
protected static $paths =
array();
* The platform class instance which will be returned by getInstance
* @var FOFPlatformInterface
protected static $instance =
null;
* Set the error Handling, if possible
* @param integer $level PHP error level (E_ALL)
* @param string $log_level What to do with the error (ignore, callback)
* @param array $options Options for the error handler
* Register a path where platform files will be looked for. These take
* precedence over the built-in platform files.
* @param string $path The path to add
* Unregister a path where platform files will be looked for.
* @param string $path The path to remove
unset
(self::$paths[$pos]);
* Force a specific platform object to be used. If null, nukes the cache
* @param FOFPlatformInterface|null $instance The Platform object to be used
self::$instance =
$instance;
* Find and return the most relevant platform object
* @return FOFPlatformInterface
if (!is_object(self::$instance))
// Get the paths to look into
if (is_array(self::$paths))
$paths =
array_merge(array(__DIR__
), self::$paths);
$paths =
array_unique($paths);
foreach ($paths as $path)
// Get the .php files containing platform classes
$files =
JFolder::files($path, '[a-z0-9]\.php$', false, true, array('interface.php', 'platform.php'));
foreach ($files as $file)
// Get the class name for this platform class
$class_name =
'FOFPlatform' .
ucfirst($base_name);
// Load the file if the class doesn't exist
// If the class still doesn't exist this file didn't
// actually contain a platform class; skip it
// If it doesn't implement FOFPlatformInterface, skip it
// Get an object of this platform
// If it's not enabled, skip it
// Replace self::$instance if this object has a
$current_order =
self::$instance->getOrdering();
$new_order =
$o->getOrdering();
if ($new_order <
$current_order)
// There is no self::$instance already, so use the
// object we just created.
* Returns the ordering of the platform class.
* @see FOFPlatformInterface::getOrdering()
* Is this platform enabled?
* @see FOFPlatformInterface::isEnabled()
* Returns the base (root) directories for a given component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @see FOFPlatformInterface::getComponentBaseDirs()
* @return array A hash array with keys main, alt, site and admin.
* Return a list of the view template directories for this component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @param string $view The name of the view you're looking a
* @param string $layout The layout name to load, e.g. 'default'
* @param string $tpl The sub-template name to load (null by default)
* @param boolean $strict If true, only the specified layout will be
* searched for. Otherwise we'll fall back to
* the 'default' layout if the specified layout
* @see FOFPlatformInterface::getViewTemplateDirs()
public function getViewTemplatePaths($component, $view, $layout =
'default', $tpl =
null, $strict =
false)
* Get application-specific suffixes to use with template paths. This allows
* you to look for view template overrides based on the application version.
* @return array A plain array of suffixes to try in template names
* Return the absolute path to the application's template overrides
* directory for a specific component. We will use it to look for template
* files instead of the regular component directorues. If the application
* does not have such a thing as template overrides return an empty string.
* @param string $component The name of the component for which to fetch the overrides
* @param boolean $absolute Should I return an absolute or relative path?
* @return string The path to the template overrides directory
* Load the translation files for a given component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @see FOFPlatformInterface::loadTranslations()
* Authorise access to the component in the back-end.
* @param string $component The name of the component.
* @see FOFPlatformInterface::authorizeAdmin()
* @return boolean True to allow loading the component, false to halt loading
* Returns the JUser object for the current user
* @param integer $id The ID of the user to fetch
* @see FOFPlatformInterface::getUser()
public function getUser($id =
null)
* Returns the JDocument object which handles this component's response.
* @see FOFPlatformInterface::getDocument()
* This method will try retrieving a variable from the request (input) data.
* @param string $key The user state key for the variable
* @param string $request The request variable name for the variable
* @param FOFInput $input The FOFInput object with the request (input) data
* @param mixed $default The default value. Default: null
* @param string $type The filter type for the variable data. Default: none (no filtering)
* @param boolean $setUserState Should I set the user state with the fetched value?
* @see FOFPlatformInterface::getUserStateFromRequest()
* @return mixed The value of the variable
public function getUserStateFromRequest($key, $request, $input, $default =
null, $type =
'none', $setUserState =
true)
return $input->get($request, $default, $type);
* Load plugins of a specific type. Obviously this seems to only be required
* @param string $type The type of the plugins to be loaded
* @see FOFPlatformInterface::importPlugin()
* Execute plugins (system-level triggers) and fetch back an array with
* @param string $event The event (trigger) name, e.g. onBeforeScratchMyEar
* @param array $data A hash array of data sent to the plugins as part of the trigger
* @see FOFPlatformInterface::runPlugins()
* @return array A simple array containing the resutls of the plugins triggered
* @param string $action The ACL privilege to check, e.g. core.edit
* @param string $assetname The asset name to check, typically the component's name
* @see FOFPlatformInterface::authorise()
* @return boolean True if the user is allowed this action
public function authorise($action, $assetname)
* Is this the administrative section of the component?
* @see FOFPlatformInterface::isBackend()
* Is this the public section of the component?
* @see FOFPlatformInterface::isFrontend()
* Is this a component running in a CLI application?
* @see FOFPlatformInterface::isCli()
* Is AJAX re-ordering supported? This is 100% Joomla!-CMS specific. All
* other platforms should return false and never ask why.
* @see FOFPlatformInterface::supportsAjaxOrdering()
* Performs a check between two versions. Use this function instead of PHP version_compare
* so we can mock it while testing
* @param string $version1 First version number
* @param string $version2 Second version number
* @param string $operator Operator (see version_compare for valid operators)
public function checkVersion($version1, $version2, $operator)
* Saves something to the cache. This is supposed to be used for system-wide
* FOF data, not application data.
* @param string $key The key of the data to save
* @param string $content The actual data to save
* @return boolean True on success
public function setCache($key, $content)
* Retrieves data from the cache. This is supposed to be used for system-side
* FOF data, not application data.
* @param string $key The key of the data to retrieve
* @param string $default The default value to return if the key is not found or the cache is not populated
* @return string The cached value
public function getCache($key, $default =
null)
* Is the global FOF cache enabled?
* Clears the cache of system-wide FOF data. You are supposed to call this in
* your components' installation script post-installation and post-upgrade
* methods or whenever you are modifying the structure of database tables
* accessed by FOF. Please note that FOF's cache never expires and is not
* purged by Joomla!. You MUST use this method to manually purge the cache.
* @return boolean True on success
* @param array $authInfo authentification information
* @return boolean True on success
* @return boolean True on success
Documentation generated on Tue, 19 Nov 2013 15:10:42 +0100 by phpDocumentor 1.4.3