/** * @return Websource * @throws \oat\tao\model\websource\WebsourceNotFound */ protected function getAccessProvider() { if (is_null($this->accessProvider)) { $this->accessProvider = WebsourceManager::singleton()->getWebsource($this->getOption(self::OPTION_ACCESS_PROVIDER)); } return $this->accessProvider; }
/** * Used to instantiate new AccessProviders * * @param string $fileSystem * @param array $customConfig * @return \tao_models_classes_fsAccess_AccessProvider */ protected static function spawn($fileSystemId, $customConfig = array()) { $customConfig[self::OPTION_FILESYSTEM_ID] = $fileSystemId; $customConfig[self::OPTION_ID] = uniqid(); $websource = new static($customConfig); WebsourceManager::singleton()->addWebsource($websource); return $websource; }
/** * @return tao_models_classes_service_FileStorage */ public static function singleton() { if (is_null(self::$instance)) { $config = common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getConfig(self::CONFIG_KEY); $privateFs = new core_kernel_fileSystem_FileSystem($config['private']); $publicFs = new core_kernel_fileSystem_FileSystem($config['public']); $accessProvider = WebsourceManager::singleton()->getWebsource($config['provider']); self::$instance = new self($privateFs, $publicFs, $accessProvider); } return self::$instance; }
/** * @dataProvider fileAccessProviders */ public function testAccessProviders(Websource $access) { $this->assertInstanceOf('oat\\tao\\model\\websource\\Websource', $access); $id = $access->getId(); $fromManager = WebsourceManager::singleton()->getWebsource($id); $this->assertInstanceOf('oat\\tao\\model\\websource\\Websource', $fromManager); $url = $access->getAccessUrl('img' . DIRECTORY_SEPARATOR . 'tao.png'); $this->assertTrue(file_exists($access->getFileSystem()->getPath() . 'img' . DIRECTORY_SEPARATOR . 'tao.png'), 'reference file not found'); $this->assertUrlHttpCode($url); $url = $access->getAccessUrl('img' . DIRECTORY_SEPARATOR . 'fakeFile_thatDoesNotExist.png'); $this->assertFalse(file_exists($access->getFileSystem()->getPath() . 'img' . DIRECTORY_SEPARATOR . 'fakeFile_thatDoesNotExist.png'), 'reference file should not be found'); $this->assertUrlHttpCode($url, '404'); $url = $access->getAccessUrl('img' . DIRECTORY_SEPARATOR); $this->assertUrlHttpCode($url . 'tao.png'); $url = $access->getAccessUrl('css' . DIRECTORY_SEPARATOR); $this->assertUrlHttpCode($url . 'font/tao/tao.woff'); $url = $access->getAccessUrl(''); $this->assertUrlHttpCode($url . 'img/tao.png'); WebsourceManager::singleton()->removeWebsource($access); try { WebsourceManager::singleton()->getWebsource($id); $this->fail('No exception thrown'); } catch (common_Exception $e) { // all good } }
/** * @param $theme * @return mixed */ private function updatePath($theme) { $websource = WebsourceManager::singleton()->getWebsource($this->get(ThemeRegistry::WEBSOURCE)); if (strpos($theme['path'], ThemeRegistry::WEBSOURCE) === 0) { $webUrl = $websource->getAccessUrl(substr($theme['path'], strlen(ThemeRegistry::WEBSOURCE))); $theme['path'] = $webUrl; } else { $theme['path'] = ROOT_URL . $theme['path']; } return $theme; }
public function accessFile() { list($extension, $module, $action, $code, $filePath) = explode('/', tao_helpers_Request::getRelativeUrl(), 5); list($key, $subPath) = explode(' ', base64_decode($code), 2); $source = WebsourceManager::singleton()->getWebsource($key); if ($source instanceof ActionWebSource) { $path = $source->getFileSystem()->getPath() . $subPath . (empty($filePath) ? '' : DIRECTORY_SEPARATOR . $filePath); tao_helpers_Http::returnFile($path); } }
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; }
public function testGetAvailableTheme() { ThemeRegistry::getRegistry()->createTarget('itemsTest', 'base'); ThemeRegistry::getRegistry()->createTarget('testsTest', 'base'); ThemeRegistry::getRegistry()->registerTheme('blackOnLightMagenta', 'Black on Light Magenta', 'blackOnLightMagenta', array('itemsTest')); ThemeRegistry::getRegistry()->registerTheme('lightBlueOnDarkBlue', 'Light Blue on Dark Blue', 'lightBlueOnDarkBlue', array('itemsTest', 'testsTest')); ThemeRegistry::getRegistry()->registerTheme('blackAndWhite', 'Black and White', ThemeRegistry::WEBSOURCE . 'test', array('itemsTest')); ThemeRegistry::getRegistry()->registerTheme('blackRedWhite', 'Black, Red and White', 'blackRedWhite', array('itemsTest')); ThemeRegistry::getRegistry()->unregisterTheme('blackRedWhite'); $themes_json = ThemeRegistry::getRegistry()->getAvailableThemes(); $this->assertJson($themes_json); $themes = json_decode($themes_json, true); $this->assertInternalType('array', $themes); $this->assertArrayNotHasKey(ThemeRegistry::WEBSOURCE, $themes); $this->assertArrayHasKey('itemsTest', $themes); $this->assertArrayHasKey('testsTest', $themes); $this->assertEquals(ROOT_URL . 'base', $themes['itemsTest']['base']); $this->assertEquals(ROOT_URL . 'base', $themes['testsTest']['base']); $this->assertArrayHasKey('available', $themes['itemsTest']); $this->assertArrayHasKey('available', $themes['testsTest']); $websource = WebsourceManager::singleton()->getWebsource(ThemeRegistry::getRegistry()->get(ThemeRegistry::WEBSOURCE)); $expected_themes = array('itemsTest' => array('blackOnLightMagenta' => array('type' => 'simple', 'path' => 'blackOnLightMagenta'), 'lightBlueOnDarkBlue' => array('type' => 'simple', 'path' => 'lightBlueOnDarkBlue'), 'blackAndWhite' => array('type' => 'websource', 'path' => $websource->getAccessUrl('test'))), 'testsTest' => array('lightBlueOnDarkBlue' => array('type' => 'simple', 'path' => 'lightBlueOnDarkBlue'))); foreach ($themes as $targetId => $target) { if (!array_key_exists($targetId, $expected_themes)) { continue; //default themes } $this->assertEquals(count($expected_themes[$targetId]), count($target['available'])); foreach ($target['available'] as $theme) { $this->assertArrayHasKey($theme['id'], $expected_themes[$targetId]); $path = $expected_themes[$targetId][$theme['id']]['path']; //add base path if simple if ($expected_themes[$targetId][$theme['id']]['type'] == 'simple') { $path = ROOT_URL . $path; } $this->assertEquals($theme['path'], $path); } } }
protected function getAccessProvider() { return WebsourceManager::singleton()->getWebsource($this->getOption(self::OPTION_WEBSOURCE)); }
/** * Get the resolved absolute URL for a stylesheet * * @param string $path * @return string */ private function resolveStylesheetUrl($path) { $websource = WebsourceManager::singleton()->getWebsource($this->get(ThemeRegistry::WEBSOURCE)); if (strpos($path, ThemeRegistry::WEBSOURCE) === 0) { return $websource->getAccessUrl(substr($path, strlen(ThemeRegistry::WEBSOURCE))); } else { // normalizing makes sure that whatever\\comes/in gets/out/properly return ROOT_URL . FsUtils::normalizePath($path); } }