当前位置: 首页>>代码示例>>PHP>>正文


PHP PhabricatorFile::setContentHash方法代码示例

本文整理汇总了PHP中PhabricatorFile::setContentHash方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorFile::setContentHash方法的具体用法?PHP PhabricatorFile::setContentHash怎么用?PHP PhabricatorFile::setContentHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhabricatorFile的用法示例。


在下文中一共展示了PhabricatorFile::setContentHash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: newFromFileData

 public static function newFromFileData($data, array $params = array())
 {
     $selector = PhabricatorEnv::newObjectFromConfig('storage.engine-selector');
     $engines = $selector->selectStorageEngines($data, $params);
     if (!$engines) {
         throw new Exception("No valid storage engines are available!");
     }
     $data_handle = null;
     $engine_identifier = null;
     $exceptions = array();
     foreach ($engines as $engine) {
         $engine_class = get_class($engine);
         try {
             // Perform the actual write.
             $data_handle = $engine->writeFile($data, $params);
             if (!$data_handle || strlen($data_handle) > 255) {
                 // This indicates an improperly implemented storage engine.
                 throw new PhabricatorFileStorageConfigurationException("Storage engine '{$engine_class}' executed writeFile() but did " . "not return a valid handle ('{$data_handle}') to the data: it " . "must be nonempty and no longer than 255 characters.");
             }
             $engine_identifier = $engine->getEngineIdentifier();
             if (!$engine_identifier || strlen($engine_identifier) > 32) {
                 throw new PhabricatorFileStorageConfigurationException("Storage engine '{$engine_class}' returned an improper engine " . "identifier '{$engine_identifier}': it must be nonempty " . "and no longer than 32 characters.");
             }
             // We stored the file somewhere so stop trying to write it to other
             // places.
             break;
         } catch (Exception $ex) {
             if ($ex instanceof PhabricatorFileStorageConfigurationException) {
                 // If an engine is outright misconfigured (or misimplemented), raise
                 // that immediately since it probably needs attention.
                 throw $ex;
             }
             // If an engine doesn't work, keep trying all the other valid engines
             // in case something else works.
             phlog($ex);
             $exceptions[] = $ex;
         }
     }
     if (!$data_handle) {
         throw new PhutilAggregateException("All storage engines failed to write file:", $exceptions);
     }
     $file_name = idx($params, 'name');
     $file_name = self::normalizeFileName($file_name);
     // If for whatever reason, authorPHID isn't passed as a param
     // (always the case with newFromFileDownload()), store a ''
     $authorPHID = idx($params, 'authorPHID');
     $file = new PhabricatorFile();
     $file->setName($file_name);
     $file->setByteSize(strlen($data));
     $file->setAuthorPHID($authorPHID);
     $file->setContentHash(PhabricatorHash::digest($data));
     $file->setStorageEngine($engine_identifier);
     $file->setStorageHandle($data_handle);
     // TODO: This is probably YAGNI, but allows for us to do encryption or
     // compression later if we want.
     $file->setStorageFormat(self::STORAGE_FORMAT_RAW);
     if (isset($params['mime-type'])) {
         $file->setMimeType($params['mime-type']);
     } else {
         $tmp = new TempFile();
         Filesystem::writeFile($tmp, $data);
         $file->setMimeType(Filesystem::getMimeType($tmp));
     }
     $file->save();
     return $file;
 }
开发者ID:ramons03,项目名称:phabricator,代码行数:66,代码来源:PhabricatorFile.php


注:本文中的PhabricatorFile::setContentHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。