mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
chore: Run rector on lib/private/Template folder and cleanup more typing
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
b58b3750a7
commit
73447618e7
7 changed files with 47 additions and 96 deletions
|
|
@ -67,6 +67,7 @@ $config = RectorConfig::configure()
|
|||
$nextcloudDir . '/status.php',
|
||||
$nextcloudDir . '/version.php',
|
||||
$nextcloudDir . '/lib/private/Share20/ProviderFactory.php',
|
||||
$nextcloudDir . '/lib/private/Template',
|
||||
$nextcloudDir . '/tests',
|
||||
// $nextcloudDir . '/config',
|
||||
// $nextcloudDir . '/lib',
|
||||
|
|
|
|||
|
|
@ -1,39 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
namespace OC\Template;
|
||||
|
||||
use OCP\Defaults;
|
||||
use OCP\IL10N;
|
||||
|
||||
class Base {
|
||||
private $template; // The template
|
||||
private array $vars = [];
|
||||
|
||||
/** @var \OCP\IL10N */
|
||||
private $l10n;
|
||||
|
||||
/** @var Defaults */
|
||||
private $theme;
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @param string $requestToken
|
||||
* @param \OCP\IL10N $l10n
|
||||
* @param string $cspNonce
|
||||
* @param Defaults $theme
|
||||
*/
|
||||
public function __construct($template, $requestToken, $l10n, $theme, $cspNonce) {
|
||||
public function __construct(
|
||||
private string $template,
|
||||
string $requestToken,
|
||||
private IL10N $l10n,
|
||||
private Defaults $theme,
|
||||
string $cspNonce,
|
||||
) {
|
||||
$this->vars = [
|
||||
'cspNonce' => $cspNonce,
|
||||
'requesttoken' => $requestToken,
|
||||
];
|
||||
$this->l10n = $l10n;
|
||||
$this->template = $template;
|
||||
$this->theme = $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Template;
|
||||
|
||||
use OC\SystemConfig;
|
||||
|
|
@ -17,43 +20,19 @@ use OCP\IURLGenerator;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class JSCombiner {
|
||||
/** @var IAppData */
|
||||
protected $appData;
|
||||
protected ICache $depsCache;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
protected $urlGenerator;
|
||||
|
||||
/** @var ICache */
|
||||
protected $depsCache;
|
||||
|
||||
/** @var SystemConfig */
|
||||
protected $config;
|
||||
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/** @var ICacheFactory */
|
||||
private $cacheFactory;
|
||||
|
||||
public function __construct(IAppData $appData,
|
||||
IURLGenerator $urlGenerator,
|
||||
ICacheFactory $cacheFactory,
|
||||
SystemConfig $config,
|
||||
LoggerInterface $logger) {
|
||||
$this->appData = $appData;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->cacheFactory = $cacheFactory;
|
||||
public function __construct(
|
||||
protected IAppData $appData,
|
||||
protected IURLGenerator $urlGenerator,
|
||||
protected ICacheFactory $cacheFactory,
|
||||
protected SystemConfig $config,
|
||||
protected LoggerInterface $logger,
|
||||
) {
|
||||
$this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $root
|
||||
* @param string $file
|
||||
* @param string $app
|
||||
* @return bool
|
||||
*/
|
||||
public function process($root, $file, $app) {
|
||||
public function process(string $root, string $file, string $app): bool {
|
||||
if ($this->config->getValue('debug') || !$this->config->getValue('installed')) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -76,12 +55,7 @@ class JSCombiner {
|
|||
return $this->cache($path, $fileName, $folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param ISimpleFolder $folder
|
||||
* @return bool
|
||||
*/
|
||||
protected function isCached($fileName, ISimpleFolder $folder) {
|
||||
protected function isCached(string $fileName, ISimpleFolder $folder): bool {
|
||||
$fileName = str_replace('.json', '.js', $fileName);
|
||||
|
||||
if (!$folder->fileExists($fileName)) {
|
||||
|
|
@ -126,13 +100,7 @@ class JSCombiner {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $fileName
|
||||
* @param ISimpleFolder $folder
|
||||
* @return bool
|
||||
*/
|
||||
protected function cache($path, $fileName, ISimpleFolder $folder) {
|
||||
protected function cache(string $path, string $fileName, ISimpleFolder $folder): bool {
|
||||
$deps = [];
|
||||
$fullPath = $path . '/' . $fileName;
|
||||
$data = json_decode(file_get_contents($fullPath));
|
||||
|
|
@ -183,12 +151,7 @@ class JSCombiner {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param string $fileName
|
||||
* @return string
|
||||
*/
|
||||
public function getCachedJS($appName, $fileName) {
|
||||
public function getCachedJS(string $appName, string $fileName): string {
|
||||
$tmpfileLoc = explode('/', $fileName);
|
||||
$fileName = array_pop($tmpfileLoc);
|
||||
$fileName = str_replace('.json', '.js', $fileName);
|
||||
|
|
@ -197,12 +160,9 @@ class JSCombiner {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $root
|
||||
* @param string $file
|
||||
* @return string[]
|
||||
*/
|
||||
public function getContent($root, $file) {
|
||||
/** @var array $data */
|
||||
public function getContent(string $root, string $file): array {
|
||||
$data = json_decode(file_get_contents($root . '/' . $file));
|
||||
if (!is_array($data)) {
|
||||
return [];
|
||||
|
|
@ -226,7 +186,7 @@ class JSCombiner {
|
|||
*
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function resetCache() {
|
||||
public function resetCache(): void {
|
||||
$this->cacheFactory->createDistributed('JS-')->clear();
|
||||
$appDirectory = $this->appData->getDirectoryListing();
|
||||
foreach ($appDirectory as $folder) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OC\Template;
|
||||
|
||||
use OCP\IConfig;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class ResourceLocator {
|
||||
|
|
@ -23,7 +24,7 @@ abstract class ResourceLocator {
|
|||
|
||||
public function __construct(
|
||||
protected LoggerInterface $logger,
|
||||
\OCP\IConfig $config,
|
||||
IConfig $config,
|
||||
) {
|
||||
$this->mapping = [
|
||||
\OC::$SERVERROOT => \OC::$WEBROOT
|
||||
|
|
|
|||
|
|
@ -1,30 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
namespace OC\Template;
|
||||
|
||||
class ResourceNotFoundException extends \LogicException {
|
||||
protected $resource;
|
||||
protected $webPath;
|
||||
|
||||
/**
|
||||
* @param string $resource
|
||||
* @param string $webPath
|
||||
*/
|
||||
public function __construct($resource, $webPath) {
|
||||
public function __construct(
|
||||
protected string $resource,
|
||||
protected string $webPath,
|
||||
) {
|
||||
parent::__construct('Resource not found');
|
||||
$this->resource = $resource;
|
||||
$this->webPath = $webPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcePath() {
|
||||
public function getResourcePath(): string {
|
||||
return $this->webPath . '/' . $this->resource;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OC\Template;
|
||||
|
||||
use OC\SystemConfig;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
|
@ -79,7 +80,7 @@ class TemplateManager implements ITemplateManager {
|
|||
$this->eventDispatcher->dispatchTyped($event);
|
||||
print($response->render());
|
||||
} catch (\Throwable $e1) {
|
||||
$logger = \OCP\Server::get(LoggerInterface::class);
|
||||
$logger = Server::get(LoggerInterface::class);
|
||||
$logger->error('Rendering themed error page failed. Falling back to un-themed error page.', [
|
||||
'app' => 'core',
|
||||
'exception' => $e1,
|
||||
|
|
@ -112,8 +113,8 @@ class TemplateManager implements ITemplateManager {
|
|||
$debug = false;
|
||||
http_response_code($statusCode);
|
||||
try {
|
||||
$debug = (bool)Server::get(\OC\SystemConfig::class)->getValue('debug', false);
|
||||
$serverLogsDocumentation = Server::get(\OC\SystemConfig::class)->getValue('documentation_url.server_logs', '');
|
||||
$debug = (bool)Server::get(SystemConfig::class)->getValue('debug', false);
|
||||
$serverLogsDocumentation = Server::get(SystemConfig::class)->getValue('documentation_url.server_logs', '');
|
||||
$request = Server::get(IRequest::class);
|
||||
$content = $this->getTemplate('', 'exception', 'error', false);
|
||||
$content->assign('errorClass', get_class($exception));
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
namespace Test\Template;
|
||||
|
||||
use OC\SystemConfig;
|
||||
use OC\Template\ResourceLocator;
|
||||
use OC\Template\ResourceNotFoundException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ class ResourceLocatorTest extends \Test\TestCase {
|
|||
$locator->expects($this->once())
|
||||
->method('doFindTheme')
|
||||
->with('foo');
|
||||
/** @var \OC\Template\ResourceLocator $locator */
|
||||
/** @var ResourceLocator $locator */
|
||||
$locator->find(['foo']);
|
||||
}
|
||||
|
||||
|
|
@ -69,13 +70,13 @@ class ResourceLocatorTest extends \Test\TestCase {
|
|||
$this->logger->expects($this->exactly(2))
|
||||
->method('debug')
|
||||
->with($this->stringContains('map/foo'));
|
||||
/** @var \OC\Template\ResourceLocator $locator */
|
||||
/** @var ResourceLocator $locator */
|
||||
$locator->find(['foo']);
|
||||
}
|
||||
|
||||
public function testAppendIfExist(): void {
|
||||
$locator = $this->getResourceLocator('theme');
|
||||
/** @var \OC\Template\ResourceLocator $locator */
|
||||
/** @var ResourceLocator $locator */
|
||||
$method = new \ReflectionMethod($locator, 'appendIfExist');
|
||||
$method->setAccessible(true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue