You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Preview;
  27. use OCP\Files\File;
  28. use OCP\Files\IRootFolder;
  29. use OCP\Files\SimpleFS\ISimpleFile;
  30. use OCP\IConfig;
  31. use OCP\IImage;
  32. use OCP\Image as OCPImage;
  33. use OCP\Preview\IProvider;
  34. use OCP\Preview\IProviderV2;
  35. /**
  36. * Very small wrapper class to make the generator fully unit testable
  37. */
  38. class GeneratorHelper {
  39. /** @var IRootFolder */
  40. private $rootFolder;
  41. /** @var IConfig */
  42. private $config;
  43. public function __construct(IRootFolder $rootFolder, IConfig $config) {
  44. $this->rootFolder = $rootFolder;
  45. $this->config = $config;
  46. }
  47. /**
  48. * @param IProviderV2 $provider
  49. * @param File $file
  50. * @param int $maxWidth
  51. * @param int $maxHeight
  52. *
  53. * @return bool|IImage
  54. */
  55. public function getThumbnail(IProviderV2 $provider, File $file, $maxWidth, $maxHeight) {
  56. return $provider->getThumbnail($file, $maxWidth, $maxHeight);
  57. }
  58. /**
  59. * @param ISimpleFile $maxPreview
  60. * @return IImage
  61. */
  62. public function getImage(ISimpleFile $maxPreview) {
  63. $image = new OCPImage();
  64. $image->loadFromData($maxPreview->getContent());
  65. return $image;
  66. }
  67. /**
  68. * @param callable $providerClosure
  69. * @return IProviderV2
  70. */
  71. public function getProvider($providerClosure) {
  72. $provider = $providerClosure();
  73. if ($provider instanceof IProvider) {
  74. $provider = new ProviderV1Adapter($provider);
  75. }
  76. return $provider;
  77. }
  78. }