/** * Find and return the most relevant platform object * * @return FOFPlatformInterface */ public static function getInstance() { if (!is_object(self::$instance)) { // Get the paths to look into $paths = array(__DIR__); if (is_array(self::$paths)) { $paths = array_merge(array(__DIR__), self::$paths); } $paths = array_unique($paths); // Loop all paths JLoader::import('joomla.filesystem.folder'); 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')); if (!empty($files)) { foreach ($files as $file) { // Get the class name for this platform class $base_name = basename($file, '.php'); $class_name = 'FOFPlatform' . ucfirst($base_name); // Load the file if the class doesn't exist if (!class_exists($class_name)) { @(include_once $file); } // If the class still doesn't exist this file didn't // actually contain a platform class; skip it if (!class_exists($class_name)) { continue; } // If it doesn't implement FOFPlatformInterface, skip it if (!class_implements($class_name, 'FOFPlatformInterface')) { continue; } // Get an object of this platform $o = new $class_name(); // If it's not enabled, skip it if (!$o->isEnabled()) { continue; } if (is_object(self::$instance)) { // Replace self::$instance if this object has a // lower order number $current_order = self::$instance->getOrdering(); $new_order = $o->getOrdering(); if ($new_order < $current_order) { self::$instance = null; self::$instance = $o; } } else { // There is no self::$instance already, so use the // object we just created. self::$instance = $o; } } } } } return self::$instance; }
/** * Find and return the most relevant platform object * * @return FOFPlatformInterface */ public static function getInstance() { if (!is_object(self::$instance)) { // Where to look for platform integrations $paths = array(__DIR__ . '/../integration'); if (is_array(self::$paths)) { $paths = array_merge($paths, self::$paths); } // Get a list of folders inside this directory $integrations = array(); foreach ($paths as $path) { if (!is_dir($path)) { continue; } $di = new DirectoryIterator($path); $temp = array(); foreach ($di as $fileSpec) { if (!$fileSpec->isDir()) { continue; } $fileName = $fileSpec->getFilename(); if (substr($fileName, 0, 1) == '.') { continue; } $platformFilename = $path . '/' . $fileName . '/platform.php'; if (!file_exists($platformFilename)) { continue; } $temp[] = array('classname' => 'FOFIntegration' . ucfirst($fileName) . 'Platform', 'fullpath' => $path . '/' . $fileName . '/platform.php'); } $integrations = array_merge($integrations, $temp); } // Loop all paths foreach ($integrations as $integration) { // Get the class name for this platform class $class_name = $integration['classname']; // Load the file if the class doesn't exist if (!class_exists($class_name, false)) { @(include_once $integration['fullpath']); } // If the class still doesn't exist this file didn't // actually contain a platform class; skip it if (!class_exists($class_name, false)) { continue; } // If it doesn't implement FOFPlatformInterface, skip it if (!class_implements($class_name, 'FOFPlatformInterface')) { continue; } // Get an object of this platform $o = new $class_name(); // If it's not enabled, skip it if (!$o->isEnabled()) { continue; } if (is_object(self::$instance)) { // Replace self::$instance if this object has a // lower order number $current_order = self::$instance->getOrdering(); $new_order = $o->getOrdering(); if ($new_order < $current_order) { self::$instance = null; self::$instance = $o; } } else { // There is no self::$instance already, so use the // object we just created. self::$instance = $o; } } } return self::$instance; }