/** * Returns a file instance based on the specified path. The path can be in the following formats: * - Scheme path: local:/mydir/myfile * - Encoded path: {0}/myfile * - Default scheme path: /myfile * * @param string $path Path to get the file system instance for. * @param string $childPath Path to the child of specified parent path. * @return MOXMAN_Vfs_IFile File instance from the specified path. */ public function getFile($path, $childPath = "") { // Verfiy that the path doesn't have any abnormalities $path = MOXMAN_Util_Sanitize::path($path); $childPath = MOXMAN_Util_Sanitize::childPath($childPath); if ($this->fileSystems) { $this->createFileSystems(); // Is a http URL then ask each file systems URL resolver for a file if (preg_match('/^https?:\\/\\//', $path)) { $file = null; foreach ($this->fileSystems as $fileSystem) { $urlResolver = $fileSystem->getFileUrlResolver(); if ($urlResolver) { $file = $urlResolver->getFile($path); if ($file) { break; } } } return $file; } if ($childPath) { $path = MOXMAN_Util_PathUtils::combine($path, $childPath); } // Decode {num} with root path $matches = array(); if (preg_match('/^\\{([0-9]+)\\}/', $path, $matches)) { $rootIdx = intval($matches[1]); if (!isset($this->fileSystems[$rootIdx])) { throw new MOXMAN_Exception("Could not decode {" . $rootIdx . "} with a root path. Index not found."); } $path = str_replace("{" . $rootIdx . "}", $this->fileSystems[$rootIdx]->getRootPath(), $path); } // Parse scheme like db, zip, $matches = array(); $scheme = ""; if (preg_match('/^([a-z0-9]+):\\/\\/(.+)$/', $path, $matches)) { $scheme = $matches[1]; //$pathPart = $matches[2]; //$pathPart = substr($pathPart, 0, 1) !== "/" ? "/" . $pathPart : $pathPart; } // Get file from one of the file systems foreach ($this->fileSystems as $fileSystem) { if (!$scheme || $fileSystem->getScheme() === $scheme) { // Check if it matches the absolute root if (strpos($path, $fileSystem->getRootPath()) === 0) { $file = $fileSystem->getFile($path); return $file; } // Check if path matches the public root $rootPrefix = $fileSystem->getRootName(); if ($rootPrefix !== '/') { $rootPrefix = '/' . $rootPrefix; } if ($path === $rootPrefix) { return $fileSystem->getRootFile(); } if ($rootPrefix !== '/') { $rootPrefix .= '/'; } // Check if path matches the beginning of public root if (strpos($path, $rootPrefix) === 0) { $filePath = MOXMAN_Util_PathUtils::combine($fileSystem->getRootPath(), substr($path, strlen($rootPrefix))); $file = $fileSystem->getFile($filePath); return $file; } } } } // Could not resolve path no file system returned a file throw new MOXMAN_Exception("Could not resolve path: " . $path); }