Exemple #1
0
 /**
  * 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;
 }