Merge pull request #5389 from nextcloud/enh/noid/constructor

Inprove constructor
This commit is contained in:
Simon L. 2024-10-07 12:49:08 +02:00 committed by GitHub
commit a54cfed53d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 84 additions and 193 deletions

View file

@ -6,12 +6,12 @@ use AIO\Data\ConfigurationManager;
use AIO\Data\DataConst;
use \DateTime;
class AuthManager {
readonly class AuthManager {
private const string SESSION_KEY = 'aio_authenticated';
private ConfigurationManager $configurationManager;
public function __construct(ConfigurationManager $configurationManager) {
$this->configurationManager = $configurationManager;
public function __construct(
private ConfigurationManager $configurationManager
) {
}
public function CheckCredentials(string $password) : bool {

View file

@ -7,87 +7,38 @@ use AIO\Data\ConfigurationManager;
use AIO\Docker\DockerActionManager;
use AIO\ContainerDefinitionFetcher;
class Container {
private string $identifier;
private string $displayName;
private string $containerName;
private string $restartPolicy;
private int $maxShutdownTime;
private ContainerPorts $ports;
private string $internalPorts;
private ContainerVolumes $volumes;
private ContainerEnvironmentVariables $containerEnvironmentVariables;
/** @var string[] */
private array $dependsOn;
/** @var string[] */
private array $secrets;
/** @var string[] */
private array $devices;
/** @var string[] */
private array $capAdd;
private int $shmSize;
private bool $apparmorUnconfined;
/** @var string[] */
private array $backupVolumes;
private array $nextcloudExecCommands;
private bool $readOnlyRootFs;
private array $tmpfs;
private bool $init;
private string $imageTag;
private AioVariables $aioVariables;
private string $documentation;
private DockerActionManager $dockerActionManager;
readonly class Container {
public function __construct(
string $identifier,
string $displayName,
string $containerName,
string $restartPolicy,
int $maxShutdownTime,
ContainerPorts $ports,
string $internalPorts,
ContainerVolumes $volumes,
ContainerEnvironmentVariables $containerEnvironmentVariables,
array $dependsOn,
array $secrets,
array $devices,
array $capAdd,
int $shmSize,
bool $apparmorUnconfined,
array $backupVolumes,
array $nextcloudExecCommands,
bool $readOnlyRootFs,
array $tmpfs,
bool $init,
string $imageTag,
AioVariables $aioVariables,
string $documentation,
DockerActionManager $dockerActionManager
private string $identifier,
private string $displayName,
private string $containerName,
private string $restartPolicy,
private int $maxShutdownTime,
private ContainerPorts $ports,
private string $internalPorts,
private ContainerVolumes $volumes,
private ContainerEnvironmentVariables $containerEnvironmentVariables,
/** @var string[] */
private array $dependsOn,
/** @var string[] */
private array $secrets,
/** @var string[] */
private array $devices,
/** @var string[] */
private array $capAdd,
private int $shmSize,
private bool $apparmorUnconfined,
/** @var string[] */
private array $backupVolumes,
private array $nextcloudExecCommands,
private bool $readOnlyRootFs,
private array $tmpfs,
private bool $init,
private string $imageTag,
private AioVariables $aioVariables,
private string $documentation,
private DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
$this->displayName = $displayName;
$this->containerName = $containerName;
$this->restartPolicy = $restartPolicy;
$this->maxShutdownTime = $maxShutdownTime;
$this->ports = $ports;
$this->internalPorts = $internalPorts;
$this->volumes = $volumes;
$this->containerEnvironmentVariables = $containerEnvironmentVariables;
$this->dependsOn = $dependsOn;
$this->secrets = $secrets;
$this->devices = $devices;
$this->capAdd = $capAdd;
$this->shmSize = $shmSize;
$this->apparmorUnconfined = $apparmorUnconfined;
$this->backupVolumes = $backupVolumes;
$this->nextcloudExecCommands = $nextcloudExecCommands;
$this->readOnlyRootFs = $readOnlyRootFs;
$this->tmpfs = $tmpfs;
$this->init = $init;
$this->imageTag = $imageTag;
$this->aioVariables = $aioVariables;
$this->documentation = $documentation;
$this->dockerActionManager = $dockerActionManager;
}
public function GetIdentifier() : string {

View file

@ -3,17 +3,10 @@
namespace AIO\Container;
class ContainerPort {
public string $port;
public string $ipBinding;
public string $protocol;
public function __construct(
string $port,
string $ipBinding,
string $protocol
public string $port,
public string $ipBinding,
public string $protocol
) {
$this->port = $port;
$this->ipBinding = $ipBinding;
$this->protocol = $protocol;
}
}

View file

@ -3,17 +3,10 @@
namespace AIO\Container;
class ContainerVolume {
public string $name;
public string $mountPoint;
public bool $isWritable;
public function __construct(
string $name,
string $mountPoint,
bool $isWritable
public string $name,
public string $mountPoint,
public bool $isWritable
) {
$this->name = $name;
$this->mountPoint = $mountPoint;
$this->isWritable = $isWritable;
}
}

View file

@ -14,18 +14,11 @@ use AIO\Data\ConfigurationManager;
use AIO\Data\DataConst;
use AIO\Docker\DockerActionManager;
class ContainerDefinitionFetcher
{
private ConfigurationManager $configurationManager;
private \DI\Container $container;
readonly class ContainerDefinitionFetcher {
public function __construct(
ConfigurationManager $configurationManager,
\DI\Container $container
)
{
$this->configurationManager = $configurationManager;
$this->container = $container;
private ConfigurationManager $configurationManager,
private \DI\Container $container
) {
}
public function GetContainerById(string $id): Container
@ -103,7 +96,7 @@ class ContainerDefinitionFetcher
$ports = new ContainerPorts();
if (isset($entry['ports'])) {
foreach ($entry['ports'] as $value) {
foreach ($entry['ports'] as $value) {
$ports->AddPort(
new ContainerPort(
$value['port_number'],
@ -212,7 +205,7 @@ class ContainerDefinitionFetcher
$dependsOn[] = $value;
}
}
$variables = new ContainerEnvironmentVariables();
if (isset($entry['environment'])) {
foreach ($entry['environment'] as $value) {

View file

@ -9,14 +9,10 @@ use AIO\Docker\DockerActionManager;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class ConfigurationController
{
private ConfigurationManager $configurationManager;
readonly class ConfigurationController {
public function __construct(
ConfigurationManager $configurationManager
private ConfigurationManager $configurationManager
) {
$this->configurationManager = $configurationManager;
}
public function SetConfig(Request $request, Response $response, array $args) : Response {

View file

@ -9,21 +9,14 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use AIO\Data\ConfigurationManager;
class DockerController
{
private DockerActionManager $dockerActionManager;
private ContainerDefinitionFetcher $containerDefinitionFetcher;
readonly class DockerController {
private const string TOP_CONTAINER = 'nextcloud-aio-apache';
private ConfigurationManager $configurationManager;
public function __construct(
DockerActionManager $dockerActionManager,
ContainerDefinitionFetcher $containerDefinitionFetcher,
ConfigurationManager $configurationManager
private DockerActionManager $dockerActionManager,
private ContainerDefinitionFetcher $containerDefinitionFetcher,
private ConfigurationManager $configurationManager
) {
$this->dockerActionManager = $dockerActionManager;
$this->containerDefinitionFetcher = $containerDefinitionFetcher;
$this->configurationManager = $configurationManager;
}
private function PerformRecursiveContainerStart(string $id, bool $pullImage = true) : void {
@ -48,7 +41,7 @@ class DockerController
}
}
// Check if docker hub is reachable in order to make sure that we do not try to pull an image if it is down
// Check if docker hub is reachable in order to make sure that we do not try to pull an image if it is down
// and try to mitigate issues that are arising due to that
if ($pullImage) {
if (!$this->dockerActionManager->isDockerHubReachable($container)) {

View file

@ -9,14 +9,11 @@ use AIO\Docker\DockerActionManager;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class LoginController
{
private AuthManager $authManager;
private DockerActionManager $dockerActionManager;
public function __construct(AuthManager $authManager, DockerActionManager $dockerActionManager) {
$this->authManager = $authManager;
$this->dockerActionManager = $dockerActionManager;
readonly class LoginController {
public function __construct(
private AuthManager $authManager,
private DockerActionManager $dockerActionManager,
) {
}
public function TryLogin(Request $request, Response $response, array $args) : Response {

View file

@ -4,16 +4,11 @@ namespace AIO\Data;
use AIO\Auth\PasswordGenerator;
class Setup
{
private PasswordGenerator $passwordGenerator;
private ConfigurationManager $configurationManager;
readonly class Setup {
public function __construct(
PasswordGenerator $passwordGenerator,
ConfigurationManager $configurationManager) {
$this->passwordGenerator = $passwordGenerator;
$this->configurationManager = $configurationManager;
private PasswordGenerator $passwordGenerator,
private ConfigurationManager $configurationManager,
) {
}
public function Setup() : string {

View file

@ -13,34 +13,21 @@ use AIO\Container\State\VersionDifferentState;
use AIO\Container\State\StoppedState;
use AIO\Container\State\VersionEqualState;
use AIO\Data\ConfigurationManager;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use AIO\ContainerDefinitionFetcher;
use http\Env\Response;
class DockerActionManager
{
readonly class DockerActionManager {
private const string API_VERSION = 'v1.41';
private \GuzzleHttp\Client $guzzleClient;
private ConfigurationManager $configurationManager;
private ContainerDefinitionFetcher $containerDefinitionFetcher;
private DockerHubManager $dockerHubManager;
private Client $guzzleClient;
public function __construct(
ConfigurationManager $configurationManager,
ContainerDefinitionFetcher $containerDefinitionFetcher,
DockerHubManager $dockerHubManager
private ConfigurationManager $configurationManager,
private ContainerDefinitionFetcher $containerDefinitionFetcher,
private DockerHubManager $dockerHubManager
) {
$this->configurationManager = $configurationManager;
$this->containerDefinitionFetcher = $containerDefinitionFetcher;
$this->dockerHubManager = $dockerHubManager;
$this->guzzleClient = new \GuzzleHttp\Client(
[
'curl' => [
CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock',
],
]
);
$this->guzzleClient = new Client(['curl' => [CURLOPT_UNIX_SOCKET_PATH => '/var/run/docker.sock']]);
}
private function BuildApiUrl(string $url) : string {

View file

@ -6,12 +6,11 @@ use AIO\ContainerDefinitionFetcher;
use AIO\Data\ConfigurationManager;
use GuzzleHttp\Client;
class DockerHubManager
{
readonly class DockerHubManager {
private Client $guzzleClient;
public function __construct()
{
public function __construct(
) {
$this->guzzleClient = new Client();
}
@ -59,4 +58,4 @@ class DockerHubManager
return null;
}
}
}
}

View file

@ -8,12 +8,10 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class AuthMiddleware
{
private AuthManager $authManager;
public function __construct(AuthManager $authManager) {
$this->authManager = $authManager;
readonly class AuthMiddleware {
public function __construct(
private AuthManager $authManager
) {
}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

View file

@ -3,17 +3,13 @@
namespace AIO\Twig;
use Slim\Csrf\Guard;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
class CsrfExtension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface
{
/**
* @var Guard
*/
protected Guard $csrf;
public function __construct(Guard $csrf)
{
$this->csrf = $csrf;
class CsrfExtension extends AbstractExtension implements GlobalsInterface {
public function __construct(
protected Guard $csrf
) {
}
public function getGlobals() : array
@ -35,4 +31,4 @@ class CsrfExtension extends \Twig\Extension\AbstractExtension implements \Twig\E
]
];
}
}
}