You are here

function flysystem_stream_wrappers in Flysystem 7

Implements hook_stream_wrappers().

File

./flysystem.module, line 118
Provides access to various filesystem backends using Flysystem.

Code

function flysystem_stream_wrappers() {
  $wrappers = array();

  // Code below stolen from https://www.drupal.org/project/amazons3.
  // This hook is called before hook_init(), so we have to manually register
  // the autoloader. We also need to handle module upgrades where
  // composer_manager might not be enabled yet.
  if (!module_exists('composer_manager')) {
    return $wrappers;
  }

  // If the module has been enabled, but the user didn't update composer
  // libraries, prevent failing entirely.
  try {
    composer_manager_register_autoloader();
  } catch (RuntimeException $e) {
    watchdog('flysystem', 'The Composer autoloader could not be registered. Run drush composer-rebuild and drush composer-manager update to update your vendor directory.');
    watchdog_exception('flysystem', $e);
    return $wrappers;
  }
  if (!flysystem_dependencies_check()) {
    watchdog('flysystem', 'The Flysystem dependencies are not installed correctly. Make sure all module updates have run. Otherwise, run drush composer-rebuild and drush composer-manager update to update your vendor directory.');
    return $wrappers;
  }
  foreach (variable_get('flysystem', array()) as $scheme => $settings) {
    $wrappers[$scheme] = array(
      'name' => t('Flysystem: @scheme', array(
        '@scheme' => $scheme,
      )),
      'class' => 'Drupal\\flysystem\\FlysystemBridge',
      'description' => t('Flysystem: @scheme', array(
        '@scheme' => $scheme,
      )),
      'type' => STREAM_WRAPPERS_WRITE_VISIBLE,
    );
  }
  return $wrappers;
}