本文整理汇总了PHP中F0FPlatform::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP F0FPlatform::instance方法的具体用法?PHP F0FPlatform::instance怎么用?PHP F0FPlatform::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类F0FPlatform
的用法示例。
在下文中一共展示了F0FPlatform::instance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
/**
* Find and return the most relevant platform object
*
* @return F0FPlatformInterface
*/
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' => 'F0FIntegration' . 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 F0FPlatformInterface, skip it
if (!class_implements($class_name, 'F0FPlatformInterface')) {
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;
}