1: <?php
2: namespace Dropbox;
3:
4: /**
5: * An enum for the two categories of Dropbox API apps: {@link FullDropbox} and
6: * {@link AppFolder}.
7: */
8: final class AccessType
9: {
10: /**
11: * Some Dropbox API HTTP endpoints require the app access type to be embedded in the URL.
12: * This field holds the exact string that needs to be embedded in the URL.
13: *
14: * @var string
15: */
16: private $urlPart;
17:
18: /**
19: * @param string $urlPart
20: */
21: private function __construct($urlPart)
22: {
23: $this->urlPart = $urlPart;
24: }
25:
26: // Shared instances.
27: /** @var AccessType */
28: private static $fullDropbox;
29: /** @var AccessType */
30: private static $appFolder;
31:
32: /**
33: * Returns the "full Dropbox" access type, which is for apps that want access to
34: * a user's entire Dropbox.
35: *
36: * @return AccessType
37: */
38: static function FullDropbox()
39: {
40: if (self::$fullDropbox === null) self::$fullDropbox = new AccessType("dropbox");
41: return self::$fullDropbox;
42: }
43:
44: /**
45: * Returns the "app folder" access type, which is for apps only access their own
46: * app-specific folder within the user's Dropbox.
47: *
48: * @return AccessType
49: */
50: static function AppFolder()
51: {
52: if (self::$appFolder === null) self::$appFolder = new AccessType("sandbox");
53: return self::$appFolder;
54: }
55:
56: /**
57: * @internal
58: *
59: * @return string
60: */
61: function getUrlPart()
62: {
63: return $this->urlPart;
64: }
65:
66: /**
67: * Use this to check that a function argument is of type <code>AccessType</code>
68: *
69: * @internal
70: */
71: static function checkArg($argName, $argValue)
72: {
73: if (!($argValue instanceof self)) Checker::throwError($argName, $argValue, __CLASS__);
74: }
75:
76: /**
77: * Use this to check that a function argument is either <code>AccessType</code> or of type
78: * <code>AppInfo</code>.
79: *
80: * @internal
81: */
82: static function checkArgOrNull($argName, $argValue)
83: {
84: if ($argValue === null) return;
85: if (!($argValue instanceof self)) Checker::throwError($argName, $argValue, __CLASS__);
86: }
87: }
88: