[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/files/engineselector/ -> PhabricatorDefaultFileStorageEngineSelector.php (source)

   1  <?php
   2  
   3  /**
   4   * Default storage engine selector. See
   5   * @{class:PhabricatorFileStorageEngineSelector} and @{article:File Storage
   6   * Technical Documentation} for more information.
   7   */
   8  final class PhabricatorDefaultFileStorageEngineSelector
   9    extends PhabricatorFileStorageEngineSelector {
  10  
  11    /**
  12     * Select viable default storage engines according to configuration. We'll
  13     * select the MySQL and Local Disk storage engines if they are configured
  14     * to allow a given file.
  15     */
  16    public function selectStorageEngines($data, array $params) {
  17      $length = strlen($data);
  18  
  19      $mysql_key = 'storage.mysql-engine.max-size';
  20      $mysql_limit = PhabricatorEnv::getEnvConfig($mysql_key);
  21  
  22      $engines = array();
  23      if ($mysql_limit && $length <= $mysql_limit) {
  24        $engines[] = new PhabricatorMySQLFileStorageEngine();
  25      }
  26  
  27      $local_key = 'storage.local-disk.path';
  28      $local_path = PhabricatorEnv::getEnvConfig($local_key);
  29      if ($local_path) {
  30        $engines[] = new PhabricatorLocalDiskFileStorageEngine();
  31      }
  32  
  33      $s3_key = 'storage.s3.bucket';
  34      if (PhabricatorEnv::getEnvConfig($s3_key)) {
  35        $engines[] = new PhabricatorS3FileStorageEngine();
  36      }
  37  
  38      if ($mysql_limit && empty($engines)) {
  39        // If we return no engines, an exception will be thrown but it will be
  40        // a little vague ("No valid storage engines"). Since this is a default
  41        // case, throw a more specific exception.
  42        throw new Exception(
  43          'This file exceeds the configured MySQL storage engine filesize '.
  44          'limit, but no other storage engines are configured. Increase the '.
  45          'MySQL storage engine limit or configure a storage engine suitable '.
  46          'for larger files.');
  47      }
  48  
  49      return $engines;
  50    }
  51  
  52  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1