|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPCR\Shell; |
| 4 | + |
| 5 | +use PHPCR\SessionInterface; |
| 6 | +use PHPCR\CredentialsInterface; |
| 7 | + |
| 8 | +class PhpcrSession implements SessionInterface |
| 9 | +{ |
| 10 | + protected $session; |
| 11 | + protected $cwd = '/'; |
| 12 | + |
| 13 | + public function getCwd() |
| 14 | + { |
| 15 | + return $this->cwd; |
| 16 | + } |
| 17 | + |
| 18 | + public function setCwd($cwd) |
| 19 | + { |
| 20 | + $this->cwd = $cwd; |
| 21 | + } |
| 22 | + |
| 23 | + public function chdir($path) |
| 24 | + { |
| 25 | + $cwd = $this->getCwd(); |
| 26 | + |
| 27 | + // absolute path |
| 28 | + if (substr($path, 0, 1) == '/') { |
| 29 | + $newPath = $path; |
| 30 | + } elseif ($path == '..') { |
| 31 | + $newPath = dirname($cwd); |
| 32 | + } else { |
| 33 | + if ($this->cwd == '/') { |
| 34 | + $newPath = sprintf('/%s', $path); |
| 35 | + } else { |
| 36 | + $newPath = sprintf('%s/%s', $cwd, $path); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + // check that path is valid |
| 41 | + $this->getNode($newPath); |
| 42 | + |
| 43 | + $this->setCwd($newPath); |
| 44 | + } |
| 45 | + |
| 46 | + public function getAbsPath($path) |
| 47 | + { |
| 48 | + if (!$path) { |
| 49 | + return $this->getCwd(); |
| 50 | + } |
| 51 | + |
| 52 | + if (substr($path, 0, 1) == '/') { |
| 53 | + $absPath = $path; |
| 54 | + } else { |
| 55 | + $absPath = $this->getCwd() . '/' . $path; |
| 56 | + } |
| 57 | + |
| 58 | + return $absPath; |
| 59 | + } |
| 60 | + |
| 61 | + public function getAbsPaths($paths) |
| 62 | + { |
| 63 | + $newPaths = array(); |
| 64 | + foreach ($paths as $path) { |
| 65 | + $newPaths[] = $this->getAbsPath($path); |
| 66 | + } |
| 67 | + |
| 68 | + return $newPaths; |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + public function __construct(SessionInterface $session) |
| 73 | + { |
| 74 | + $this->session = $session; |
| 75 | + } |
| 76 | + |
| 77 | + public function getRepository() |
| 78 | + { |
| 79 | + return $this->session->getRepository(); |
| 80 | + } |
| 81 | + |
| 82 | + public function getUserID() |
| 83 | + { |
| 84 | + return $this->session->getUserID(); |
| 85 | + } |
| 86 | + |
| 87 | + public function getAttributeNames() |
| 88 | + { |
| 89 | + return $this->session->getAttributeNames(); |
| 90 | + } |
| 91 | + |
| 92 | + public function getAttribute($name) |
| 93 | + { |
| 94 | + return $this->session->getAttribute($name); |
| 95 | + } |
| 96 | + |
| 97 | + public function getWorkspace() |
| 98 | + { |
| 99 | + return $this->session->getWorkspace(); |
| 100 | + } |
| 101 | + |
| 102 | + public function getRootNode() |
| 103 | + { |
| 104 | + return $this->session->getRootNode(); |
| 105 | + } |
| 106 | + |
| 107 | + public function impersonate(CredentialsInterface $credentials) |
| 108 | + { |
| 109 | + return $this->session->impersonate($credentials); |
| 110 | + } |
| 111 | + |
| 112 | + public function getNodeByIdentifier($id) |
| 113 | + { |
| 114 | + return $this->session->getNodeByIdentifier($id); |
| 115 | + } |
| 116 | + |
| 117 | + public function getNodesByIdentifier($ids) |
| 118 | + { |
| 119 | + return $this->session->getNodesByIdentifier($id); |
| 120 | + } |
| 121 | + |
| 122 | + public function getItem($path) |
| 123 | + { |
| 124 | + return $this->session->getItem($this->getAbsPath($path)); |
| 125 | + } |
| 126 | + |
| 127 | + public function getNode($path, $depthHint = -1) |
| 128 | + { |
| 129 | + return $this->session->getNode($this->getAbsPath($path)); |
| 130 | + } |
| 131 | + |
| 132 | + public function getNodes($paths) |
| 133 | + { |
| 134 | + return $this->session->getNodes($this->getAbsPaths($paths)); |
| 135 | + } |
| 136 | + |
| 137 | + public function getProperty($path) |
| 138 | + { |
| 139 | + return $this->session->getProperty($this->getAbsPath($path)); |
| 140 | + } |
| 141 | + |
| 142 | + public function getProperties($paths) |
| 143 | + { |
| 144 | + return $this->session->getProperties($this->getAbsPaths($paths)); |
| 145 | + } |
| 146 | + |
| 147 | + public function itemExists($path) |
| 148 | + { |
| 149 | + return $this->session->itemExists($this->getAbsPath($path)); |
| 150 | + } |
| 151 | + |
| 152 | + public function nodeExists($path) |
| 153 | + { |
| 154 | + return $this->session->nodeExists($this->getAbsPath($path)); |
| 155 | + } |
| 156 | + |
| 157 | + public function propertyExists($path) |
| 158 | + { |
| 159 | + return $this->session->propertyExists($this->getAbsPath($path)); |
| 160 | + } |
| 161 | + |
| 162 | + public function move($srcAbsPath, $destAbsPath) |
| 163 | + { |
| 164 | + return $this->session->move($srcAbsPath, $destAbsPath); |
| 165 | + } |
| 166 | + |
| 167 | + public function removeItem($path) |
| 168 | + { |
| 169 | + return $this->session->removeItem($this->getAbsPath($path)); |
| 170 | + } |
| 171 | + |
| 172 | + public function save() |
| 173 | + { |
| 174 | + return $this->session->save(); |
| 175 | + } |
| 176 | + |
| 177 | + public function refresh($keepChanges) |
| 178 | + { |
| 179 | + return $this->session->refresh($keepChanges); |
| 180 | + } |
| 181 | + |
| 182 | + public function hasPendingChanges() |
| 183 | + { |
| 184 | + return $this->session->hasPendingChanges(); |
| 185 | + } |
| 186 | + |
| 187 | + public function hasPermission($path, $actions) |
| 188 | + { |
| 189 | + return $this->session->hasPermission($this->getAbsPath($path), $actions); |
| 190 | + } |
| 191 | + |
| 192 | + public function checkPermission($path, $actions) |
| 193 | + { |
| 194 | + return $this->session->checkPermission($this->getAbsPath($path), $actions); |
| 195 | + } |
| 196 | + |
| 197 | + public function hasCapability($methodName, $target, array $arguments) |
| 198 | + { |
| 199 | + return $this->session->hasCapability($methodNames, $target, $arguments); |
| 200 | + } |
| 201 | + |
| 202 | + public function importXML($parentAbsPath, $uri, $uuidBehavior) |
| 203 | + { |
| 204 | + return $this->session->importXML($parentAbsPath, $uri, $uuidBehavior); |
| 205 | + } |
| 206 | + |
| 207 | + public function exportSystemView($path, $stream, $skipBinary, $noRecurse) |
| 208 | + { |
| 209 | + return $this->session->exportSystemView($this->getAbsPath($path), $stream, $skipBinary, $noRecurse); |
| 210 | + } |
| 211 | + |
| 212 | + public function exportDocumentView($path, $stream, $skipBinary, $noRecurse) |
| 213 | + { |
| 214 | + return $this->session->exportDocumentView($this->getAbsPath($path), $stream, $skipBinary, $noRecurse); |
| 215 | + } |
| 216 | + |
| 217 | + public function setNamespacePrefix($prefix, $uri) |
| 218 | + { |
| 219 | + return $this->session->setNamespacePrefix($prefix, $uri); |
| 220 | + } |
| 221 | + |
| 222 | + public function getNamespacePrefixes() |
| 223 | + { |
| 224 | + return $this->session->getNamespacePrefixes(); |
| 225 | + } |
| 226 | + |
| 227 | + public function getNamespaceURI($prefix) |
| 228 | + { |
| 229 | + return $this->session->getNamespaceURI($prefix); |
| 230 | + } |
| 231 | + |
| 232 | + public function getNamespacePrefix($uri) |
| 233 | + { |
| 234 | + return $this->session->getNamespacePrefix($uri); |
| 235 | + } |
| 236 | + |
| 237 | + public function logout() |
| 238 | + { |
| 239 | + return $this->session->logout(); |
| 240 | + } |
| 241 | + |
| 242 | + public function isLive() |
| 243 | + { |
| 244 | + return $this->session->isLive(); |
| 245 | + } |
| 246 | + |
| 247 | + public function getAccessControlManager() |
| 248 | + { |
| 249 | + return $this->session->getAccessControlManager(); |
| 250 | + } |
| 251 | + |
| 252 | + public function getRetentionManager() |
| 253 | + { |
| 254 | + return $this->session->getRetentionManager(); |
| 255 | + } |
| 256 | +} |
0 commit comments