本文整理汇总了PHP中OCP\IURLGenerator类的典型用法代码示例。如果您正苦于以下问题:PHP IURLGenerator类的具体用法?PHP IURLGenerator怎么用?PHP IURLGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IURLGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: htmlError
/**
* @param IURLGenerator $urlGenerator
* @param string $appName
* @param \Exception $exception
*
* @return RedirectResponse
*/
public function htmlError($urlGenerator, $appName, Exception $exception)
{
$message = $exception->getMessage();
$code = $this->getHttpStatusCode($exception);
$url = $urlGenerator->linkToRoute($appName . '.page.error_page', ['code' => $code]);
$response = new RedirectResponse($url);
$response->addCookie('galleryErrorMessage', $message);
return $response;
}
示例2: toCollection
public function toCollection(IURLGenerator $urlGenerator, $userFolder)
{
$nodes = $userFolder->getById($this->getFileId());
if (count($nodes) == 0) {
throw new \OCP\Files\NotFoundException();
}
// get the first valid node
$node = $nodes[0];
$path = $node->getPath();
$relativePath = $userFolder->getRelativePath($path);
return array('title' => $this->getTitle(), 'number' => $this->getNumber(), 'artistId' => $this->getArtistId(), 'albumId' => $this->getAlbumId(), 'files' => array($this->getMimetype() => $urlGenerator->getAbsoluteUrl('remote.php/webdav' . $relativePath)), 'id' => $this->getId());
}
示例3: format
/**
* @param IEvent $event
* @param string $parameter The parameter to be formatted
* @return string The formatted parameter
*/
public function format(IEvent $event, $parameter)
{
$param = $this->fixLegacyFilename($parameter);
// If the activity is about the very same file, we use the current path
// for the link generation instead of the one that was saved.
$fileId = '';
if (is_array($param)) {
$fileId = key($param);
$param = $param[$fileId];
$info = $this->infoCache->getInfoById($this->user, $fileId, $param);
} elseif ($event->getObjectType() === 'files' && $event->getObjectName() === $param) {
$fileId = $event->getObjectId();
$info = $this->infoCache->getInfoById($this->user, $fileId, $param);
} else {
$info = $this->infoCache->getInfoByPath($this->user, $param);
}
if ($info['is_dir']) {
$linkData = ['dir' => $info['path']];
} else {
$parentDir = substr_count($info['path'], '/') === 1 ? '/' : dirname($info['path']);
$fileName = basename($info['path']);
$linkData = ['dir' => $parentDir, 'scrollto' => $fileName];
}
if ($info['view'] !== '') {
$linkData['view'] = $info['view'];
}
$param = trim($param, '/');
$fileLink = $this->urlGenerator->linkToRouteAbsolute('files.view.index', $linkData);
return '<file link="' . $fileLink . '" id="' . Util::sanitizeHTML($fileId) . '">' . Util::sanitizeHTML($param) . '</file>';
}
示例4: testIndexWithIE8RedirectAndViewAndDirDefined
public function testIndexWithIE8RedirectAndViewAndDirDefined()
{
$this->request->expects($this->once())->method('isUserAgent')->with(['/MSIE 8.0/'])->will($this->returnValue(true));
$this->urlGenerator->expects($this->once())->method('linkToRoute')->with('files.view.index')->will($this->returnValue('/apps/files/'));
$expected = new RedirectResponse('/apps/files/#?dir=MyDir&view=MyView');
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
}
示例5: testFormat
/**
* @dataProvider dataFormat
*
* @param string $user
* @param string $parameter
* @param bool $isDir
* @param array $info
* @param bool $allowHtml
* @param bool $verbose
* @param string $expected
*/
public function testFormat($user, $parameter, $isDir, array $info, $allowHtml, $verbose, $expected)
{
/** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */
$event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
if (!empty($info)) {
$event->expects($this->once())->method('getObjectType')->willReturn('files');
$event->expects($this->once())->method('getObjectName')->willReturn($parameter);
$event->expects($this->once())->method('getObjectId')->willReturn(42);
}
$this->urlGenerator->expects($allowHtml ? $this->once() : $this->never())->method('linkTo')->with('files', 'index.php', $this->anything())->willReturnCallback(function ($app, $file, $parameters) {
$paramList = [];
foreach ($parameters as $key => $value) {
$paramList[] = $key . '=' . urlencode($value);
}
return $app . '/' . $file . '?' . implode('&', $paramList);
});
$formatter = $this->getFormatter(['fixLegacyFilename'], $user);
$formatter->expects($this->once())->method('fixLegacyFilename')->willReturnArgument(0);
if (!empty($info)) {
$this->infoCache->expects($this->once())->method('getInfoById')->with($user, 42, $parameter)->willReturn($info);
} else {
$this->infoCache->expects($this->once())->method('getInfoByPath')->with($user, $parameter)->willReturn(['path' => $parameter, 'is_dir' => $isDir, 'exists' => true, 'view' => '']);
}
$this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose));
}
示例6: show
/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function show()
{
try {
$user = $this->activityManager->getCurrentUserId();
$userLang = $this->config->getUserValue($user, 'core', 'lang');
// Overwrite user and language in the helper
$l = Util::getL10N('activity', $userLang);
$l->forceLanguage($userLang);
$this->helper->setL10n($l);
$this->helper->setUser($user);
$description = (string) $l->t('Personal activity feed for %s', $user);
$activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
} catch (\UnexpectedValueException $e) {
$l = Util::getL10N('activity');
$description = (string) $l->t('Your feed URL is invalid');
$activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
}
$response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
$response->addHeader('Content-Type', 'application/rss+xml');
} else {
$response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
}
return $response;
}
示例7: execute
/**
* {@inheritdoc }
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
$privateKeyPath = $input->getOption('privateKey');
$keyBundlePath = $input->getOption('certificate');
if (is_null($path) || is_null($privateKeyPath) || is_null($keyBundlePath)) {
$documentationUrl = $this->urlGenerator->linkToDocs('developer-code-integrity');
$output->writeln('This command requires the --path, --privateKey and --certificate.');
$output->writeln('Example: ./occ integrity:sign-app --path="/Users/lukasreschke/Programming/myapp/" --privateKey="/Users/lukasreschke/private/myapp.key" --certificate="/Users/lukasreschke/public/mycert.crt"');
$output->writeln('For more information please consult the documentation: ' . $documentationUrl);
return null;
}
$privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
$keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
if ($privateKey === false) {
$output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
return null;
}
if ($keyBundle === false) {
$output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
return null;
}
$rsa = new RSA();
$rsa->loadKey($privateKey);
$x509 = new X509();
$x509->loadX509($keyBundle);
$x509->setPrivateKey($rsa);
$this->checker->writeAppSignature($path, $x509, $rsa);
$output->writeln('Successfully signed "' . $path . '"');
}
示例8: setRSSToken
public function setRSSToken($rssToken)
{
if ($rssToken) {
$this->rssLink = $this->URLGenerator->getAbsoluteURL($this->URLGenerator->linkToRoute('activity.rss', array('token' => $rssToken)));
} else {
$this->rssLink = '';
}
}
示例9: logout
/**
* @NoAdminRequired
* @UseSession
*
* @return RedirectResponse
*/
public function logout()
{
$loginToken = $this->request->getCookie('oc_token');
if (!is_null($loginToken)) {
$this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken);
}
$this->userSession->logout();
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
}
示例10: getPreviewLink
/**
* @param string $path
* @param bool $isDir
* @return string
*/
protected function getPreviewLink($path, $isDir)
{
if ($isDir) {
return $this->urlGenerator->linkTo('files', 'index.php', array('dir' => $path));
} else {
$parentDir = substr_count($path, '/') === 1 ? '/' : dirname($path);
$fileName = basename($path);
return $this->urlGenerator->linkTo('files', 'index.php', array('dir' => $parentDir, 'scrollto' => $fileName));
}
}
示例11: testLogoutWithToken
public function testLogoutWithToken()
{
$this->request->expects($this->once())->method('getCookie')->with('oc_token')->willReturn('MyLoginToken');
$user = $this->getMock('\\OCP\\IUser');
$user->expects($this->once())->method('getUID')->willReturn('JohnDoe');
$this->userSession->expects($this->once())->method('getUser')->willReturn($user);
$this->config->expects($this->once())->method('deleteUserValue')->with('JohnDoe', 'login_token', 'MyLoginToken');
$this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute')->with('core.login.showLoginForm')->willReturn('/login');
$expected = new RedirectResponse('/login');
$this->assertEquals($expected, $this->loginController->logout());
}
示例12: getLinkList
/**
* Get all items for the users we want to send an email to
*
* @return array Notification data (user => array of rows from the table)
*/
public function getLinkList()
{
$topEntries = [['id' => 'all', 'name' => (string) $this->l->t('All Activities'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList')]];
if ($this->user && $this->userSettings->getUserSetting($this->user, 'setting', 'self')) {
$topEntries[] = ['id' => 'self', 'name' => (string) $this->l->t('Activities by you'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'self'))];
$topEntries[] = ['id' => 'by', 'name' => (string) $this->l->t('Activities by others'), 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'by'))];
}
$additionalEntries = $this->activityManager->getNavigation();
$topEntries = array_merge($topEntries, $additionalEntries['top']);
return array('top' => $topEntries, 'apps' => $additionalEntries['apps']);
}
示例13: parse
/**
* @param string $file the xml file to be loaded
* @return null|array where null is an indicator for an error
*/
public function parse($file)
{
if (!file_exists($file)) {
return null;
}
libxml_use_internal_errors(true);
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($file);
libxml_disable_entity_loader($loadEntities);
if ($xml == false) {
libxml_clear_errors();
return null;
}
$array = $this->xmlToArray($xml);
if (is_null($array)) {
return null;
}
if (!array_key_exists('info', $array)) {
$array['info'] = array();
}
if (!array_key_exists('remote', $array)) {
$array['remote'] = array();
}
if (!array_key_exists('public', $array)) {
$array['public'] = array();
}
if (!array_key_exists('types', $array)) {
$array['types'] = array();
}
if (array_key_exists('documentation', $array) && is_array($array['documentation'])) {
foreach ($array['documentation'] as $key => $url) {
// If it is not an absolute URL we assume it is a key
// i.e. admin-ldap will get converted to go.php?to=admin-ldap
if (!$this->httpHelper->isHTTPURL($url)) {
$url = $this->urlGenerator->linkToDocs($url);
}
$array['documentation'][$key] = $url;
}
}
if (array_key_exists('types', $array)) {
if (is_array($array['types'])) {
foreach ($array['types'] as $type => $v) {
unset($array['types'][$type]);
if (is_string($type)) {
$array['types'][] = $type;
}
}
} else {
$array['types'] = array();
}
}
return $array;
}
示例14: testAppNavigation
public function testAppNavigation()
{
$this->navigationManager->expects($this->once())->method('add')->willReturnCallback(function ($closure) {
$this->assertInstanceOf('\\Closure', $closure);
$navigation = $closure();
$this->assertInternalType('array', $navigation);
$this->assertCount(5, $navigation);
$this->assertSame(['id' => 'announcementcenter', 'order' => 10, 'href' => '/apps/announcementcenter/announcement', 'icon' => '/apps/announcementcenter/img/announcementcenter.svg', 'name' => 'Announcements'], $navigation);
});
$this->urlGenerator->expects($this->once())->method('linkToRoute')->with('announcementcenter.page.index')->willReturn('/apps/announcementcenter/announcement');
$this->urlGenerator->expects($this->once())->method('imagePath')->with('announcementcenter', 'announcementcenter.svg')->willReturn('/apps/announcementcenter/img/announcementcenter.svg');
$this->languageFactory->expects($this->once())->method('get')->with('announcementcenter')->willReturn($this->language);
include __DIR__ . '/../../appinfo/app.php';
}
示例15: redirectToErrorPage
/**
* Redirects the client to an error page
*
* @param string $message
* @param int $code
*
* @return RedirectResponse
*/
private function redirectToErrorPage($message, $code)
{
$url = $this->urlGenerator->linkToRoute($this->appName . '.page.error_page', ['code' => $code]);
$response = new RedirectResponse($url);
$response->addCookie('galleryErrorMessage', $message);
return $response;
}