Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service.php « service - github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f9704b23f4c33b1a0d3e991014b659eb42ecb91d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
 * ownCloud - gallery
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Olivier Paroz <owncloud@interfasys.ch>
 *
 * @copyright Olivier Paroz 2014-2015
 */

namespace OCA\Gallery\Service;

use OCP\Files\Node;
use OCP\ILogger;

use OCA\Gallery\Environment\Environment;

/**
 * Contains methods which all services will need
 *
 * @package OCA\Gallery\Service
 */
abstract class Service {

	/**
	 * @var string
	 */
	protected $appName;
	/**
	 * @var Environment
	 */
	protected $environment;
	/**
	 * @var ILogger
	 */
	protected $logger;

	/**
	 * Constructor
	 *
	 * @param string $appName
	 * @param Environment $environment
	 * @param ILogger $logger
	 */
	public function __construct(
		$appName,
		Environment $environment,
		ILogger $logger
	) {
		$this->appName = $appName;
		$this->environment = $environment;
		$this->logger = $logger;
	}

	/**
	 * Returns the node matching the given ID
	 *
	 * @param int $nodeId ID of the resource to locate
	 *
	 * @return Node
	 * @throws NotFoundServiceException
	 */
	public function getResourceFromId($nodeId) {
		try {
			$node = $this->environment->getResourceFromId($nodeId);

			// Making extra sure that we can actually do something with the file
			if (!$node->getMimetype() || !$node->isReadable()) {
				throw new NotFoundServiceException("Can't access the file");
			}

			return $node;
		} catch (\Exception $exception) {
			throw new NotFoundServiceException($exception->getMessage());
		}
	}

}