/** * * @return array */ public function fileAccessProviders() { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); if (is_null(self::$fileSystem)) { $serviceManager = ServiceManager::getServiceManager(); $fsm = $serviceManager->get(FileSystemService::SERVICE_ID); $fsId = core_kernel_uri_UriService::singleton()->generateUri(); $fsm->registerLocalFileSystem($fsId, $ext->getConstant('DIR_VIEWS')); $serviceManager->register(FileSystemService::SERVICE_ID, $fsm); self::$fileSystem = new core_kernel_fileSystem_FileSystem($fsId); } return array(array(DirectWebSource::spawnWebsource(self::$fileSystem->getUri(), $ext->getConstant('BASE_WWW'))), array(TokenWebSource::spawnWebsource(self::$fileSystem->getUri(), self::$fileSystem->getPath())), array(ActionWebSource::spawnWebsource(self::$fileSystem->getUri()))); }
/** * Get the absolute path to the directory where the file is stored. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @return string A path. */ public function getAbsolutePath() { $returnValue = (string) ''; $props = $this->getPropertiesValues(array(new core_kernel_classes_Property(PROPERTY_FILE_FILEPATH), new core_kernel_classes_Property(PROPERTY_FILE_FILENAME), new core_kernel_classes_Property(PROPERTY_FILE_FILESYSTEM))); if (!isset($props[PROPERTY_FILE_FILEPATH]) || count($props[PROPERTY_FILE_FILEPATH]) == 0) { throw new common_Exception('filepath missing for file ' . $this->getUri()); } if (!isset($props[PROPERTY_FILE_FILENAME]) || count($props[PROPERTY_FILE_FILENAME]) == 0) { throw new common_Exception('filename missing for file ' . $this->getUri()); } if (!isset($props[PROPERTY_FILE_FILESYSTEM]) || count($props[PROPERTY_FILE_FILESYSTEM]) == 0) { throw new common_Exception('filesource missing for file ' . $this->getUri()); } $relFilePath = (string) current($props[PROPERTY_FILE_FILEPATH]); $fileName = (string) current($props[PROPERTY_FILE_FILENAME]); $fileSystem = new core_kernel_fileSystem_FileSystem(current($props[PROPERTY_FILE_FILESYSTEM])); $path = $fileSystem->getPath(); if (!empty($relFilePath)) { $path .= $relFilePath . DIRECTORY_SEPARATOR; } if (empty($fileName)) { //IF the resource is a folder resource, the absolute filepath should respect a specific format without slash as last char $returnValue = rtrim($path, DIRECTORY_SEPARATOR); } else { $returnValue = $path . $fileName; } return (string) $returnValue; }
private function migrateFsAccess() { $tao = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); $config = $tao->getConfig('filesystemAccess'); if (is_array($config)) { foreach ($config as $id => $string) { list($class, $id, $fsUri, $jsconfig) = explode(' ', $string, 4); $config = json_decode($jsconfig, true); $options = array(TokenWebSource::OPTION_ID => $id, TokenWebSource::OPTION_FILESYSTEM_ID => $fsUri); switch ($class) { case 'tao_models_classes_fsAccess_TokenAccessProvider': $fs = new \core_kernel_fileSystem_FileSystem($fsUri); $options[TokenWebSource::OPTION_PATH] = $fs->getPath(); $options[TokenWebSource::OPTION_SECRET] = $config['secret']; $options[TokenWebSource::OPTION_TTL] = (int) ini_get('session.gc_maxlifetime'); $websource = new TokenWebSource($options); break; case 'tao_models_classes_fsAccess_ActionAccessProvider': $websource = new ActionWebSource($options); break; case 'tao_models_classes_fsAccess_DirectAccessProvider': $options[DirectWebSource::OPTION_URL] = $config['accessUrl']; $websource = new DirectWebSource($options); break; default: throw \common_Exception('unknown implementation ' . $class); } WebsourceManager::singleton()->addWebsource($websource); } } else { throw \common_Exception('Error reading former filesystem access configuration'); } return true; }