Skip to content

Commit

Permalink
feat: Refactored command signatures
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Command constructor signatures changed
  • Loading branch information
ambroisemaupate committed Feb 10, 2024
1 parent 89af94e commit 173a4fb
Show file tree
Hide file tree
Showing 92 changed files with 493 additions and 1,462 deletions.
21 changes: 3 additions & 18 deletions lib/Models/src/Core/Handlers/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

abstract class AbstractHandler
{
protected ObjectManager $objectManager;

/**
* @return ObjectManager
*/
Expand All @@ -18,22 +16,9 @@ public function getObjectManager(): ObjectManager
return $this->objectManager;
}

/**
* @param ObjectManager $objectManager
* @return static
*/
public function setObjectManager(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
return $this;
}

/**
* @param ObjectManager $objectManager
*/
public function __construct(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
public function __construct(
protected readonly ObjectManager $objectManager
) {
}

/**
Expand Down
4 changes: 0 additions & 4 deletions lib/Models/src/Core/Handlers/HandlerFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@

interface HandlerFactoryInterface
{
/**
* @param AbstractEntity $entity
* @return AbstractHandler
*/
public function getHandler(AbstractEntity $entity): AbstractHandler;
}
18 changes: 2 additions & 16 deletions lib/RoadizCoreBundle/src/Bag/NodeTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,20 @@

namespace RZ\Roadiz\CoreBundle\Bag;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\Bag\LazyParameterBag;
use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
use RZ\Roadiz\CoreBundle\Repository\NodeTypeRepository;

class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface
final class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface
{
private ?NodeTypeRepository $repository = null;
private ManagerRegistry $managerRegistry;

/**
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
public function __construct(private readonly NodeTypeRepository $repository)
{
parent::__construct();
$this->managerRegistry = $managerRegistry;
}

/**
* @return NodeTypeRepository
*/
public function getRepository(): NodeTypeRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(NodeType::class);
}
return $this->repository;
}

Expand Down
28 changes: 9 additions & 19 deletions lib/RoadizCoreBundle/src/Bag/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@
use RZ\Roadiz\CoreBundle\Entity\Role;
use RZ\Roadiz\CoreBundle\Repository\RoleRepository;

class Roles extends LazyParameterBag
final class Roles extends LazyParameterBag
{
private ManagerRegistry $managerRegistry;
private ?RoleRepository $repository = null;

/**
* @param ManagerRegistry $managerRegistry;
*/
public function __construct(ManagerRegistry $managerRegistry)
{
public function __construct(
private readonly RoleRepository $repository,
private readonly ManagerRegistry $managerRegistry
) {
parent::__construct();
$this->managerRegistry = $managerRegistry;
}

/**
* @return RoleRepository
*/
public function getRepository(): RoleRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(Role::class);
}
return $this->repository;
}

Expand All @@ -57,14 +46,15 @@ protected function populateParameters(): void
*
* @return Role
*/
public function get($key, $default = null): Role
public function get(string $key, $default = null): Role
{
$role = parent::get($key, $default);

if (null === $role) {
$role = new Role($key);
$this->managerRegistry->getManagerForClass(Role::class)->persist($role);
$this->managerRegistry->getManagerForClass(Role::class)->flush();
$roleManager = $this->managerRegistry->getManagerForClass(Role::class);
$roleManager->persist($role);
$roleManager->flush();
}

return $role;
Expand Down
27 changes: 8 additions & 19 deletions lib/RoadizCoreBundle/src/Bag/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,25 @@

namespace RZ\Roadiz\CoreBundle\Bag;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\Bag\LazyParameterBag;
use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Setting;
use RZ\Roadiz\CoreBundle\Repository\DocumentRepository;
use RZ\Roadiz\CoreBundle\Repository\SettingRepository;
use Symfony\Component\Stopwatch\Stopwatch;

class Settings extends LazyParameterBag
final class Settings extends LazyParameterBag
{
private ManagerRegistry $managerRegistry;
private ?SettingRepository $repository = null;
private Stopwatch $stopwatch;

public function __construct(ManagerRegistry $managerRegistry, Stopwatch $stopwatch)
{
public function __construct(
private readonly SettingRepository $repository,
private readonly DocumentRepository $documentRepository,
private readonly Stopwatch $stopwatch
) {
parent::__construct();
$this->managerRegistry = $managerRegistry;
$this->stopwatch = $stopwatch;
}

/**
* @return SettingRepository
*/
public function getRepository(): SettingRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(Setting::class);
}
return $this->repository;
}

Expand Down Expand Up @@ -72,9 +63,7 @@ public function getDocument(string $key): ?Document
{
try {
$id = $this->getInt($key);
return $this->managerRegistry
->getRepository(Document::class)
->findOneById($id);
return $this->documentRepository->findOneById($id);
} catch (\Exception $e) {
return null;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/RoadizCoreBundle/src/Cache/Clearer/FileClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
abstract class FileClearer implements ClearerInterface
{
protected ?string $output = null;
protected string $cacheDir;

public function __construct(string $cacheDir)
public function __construct(protected readonly string $cacheDir)
{
$this->cacheDir = $cacheDir;
}

public function clear(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

final class NodesSourcesUrlsCacheClearer extends FileClearer
{
private CacheItemPoolInterface $cacheProvider;

public function __construct(CacheItemPoolInterface $cacheProvider)
public function __construct(private readonly CacheItemPoolInterface $cacheProvider)
{
parent::__construct('');
$this->cacheProvider = $cacheProvider;
}

public function clear(): bool
Expand Down
35 changes: 9 additions & 26 deletions lib/RoadizCoreBundle/src/Cache/CloudflareProxyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,15 @@

final class CloudflareProxyCache
{
protected string $name;
protected string $zone;
protected string $version;
protected string $bearer;
protected string $email;
protected string $key;
protected int $timeout;

/**
* @param string $name
* @param string $zone
* @param string $version
* @param string $bearer
* @param string $email
* @param string $key
* @param int $timeout
*/
public function __construct(string $name, string $zone, string $version, string $bearer, string $email, string $key, int $timeout)
{
$this->name = $name;
$this->zone = $zone;
$this->version = $version;
$this->bearer = $bearer;
$this->email = $email;
$this->key = $key;
$this->timeout = $timeout;
public function __construct(
private readonly string $name,
private readonly string $zone,
private readonly string $version,
private readonly string $bearer,
private readonly string $email,
private readonly string $key,
private readonly int $timeout
) {
}

/**
Expand Down
28 changes: 11 additions & 17 deletions lib/RoadizCoreBundle/src/Cache/ReverseProxyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@

final class ReverseProxyCache
{
protected string $name;
protected string $host;
protected string $domainName;
protected int $timeout;

/**
* @param string $name
* @param string $host
* @param string $domainName
* @param int $timeout
*/
public function __construct(string $name, string $host, string $domainName, int $timeout)
{
$this->name = $name;
$this->host = $host;
$this->domainName = $domainName;
$this->timeout = $timeout;
public function __construct(
private readonly string $name,
private readonly string $host,
private readonly string $domainName,
private readonly int $timeout
) {
}

/**
Expand All @@ -48,4 +37,9 @@ public function getDomainName(): string
{
return $this->domainName;
}

public function getTimeout(): int
{
return $this->timeout;
}
}
14 changes: 4 additions & 10 deletions lib/RoadizCoreBundle/src/Cache/ReverseProxyCacheLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

final class ReverseProxyCacheLocator
{
/**
* @var ReverseProxyCache[]
*/
private array $frontends;
private ?CloudflareProxyCache $cloudflareProxyCache;

/**
* @param ReverseProxyCache[] $frontends
* @param CloudflareProxyCache|null $cloudflareProxyCache
*/
public function __construct(array $frontends, ?CloudflareProxyCache $cloudflareProxyCache = null)
{
$this->frontends = $frontends;
$this->cloudflareProxyCache = $cloudflareProxyCache;
public function __construct(
private readonly array $frontends,
private readonly ?CloudflareProxyCache $cloudflareProxyCache = null
) {
}

/**
Expand Down
39 changes: 10 additions & 29 deletions lib/RoadizCoreBundle/src/Console/AppInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,23 @@
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Yaml\Yaml;

/**
* Command line utils for managing themes from terminal.
*/
final class AppInstallCommand extends Command
{
protected SymfonyStyle $io;
private SymfonyStyle $io;
private bool $dryRun = false;
protected string $projectDir;
protected NodeTypesImporter $nodeTypesImporter;
protected TagsImporter $tagsImporter;
protected SettingsImporter $settingsImporter;
protected RolesImporter $rolesImporter;
protected GroupsImporter $groupsImporter;
protected AttributeImporter $attributeImporter;
protected ManagerRegistry $managerRegistry;

public function __construct(
string $projectDir,
ManagerRegistry $managerRegistry,
NodeTypesImporter $nodeTypesImporter,
TagsImporter $tagsImporter,
SettingsImporter $settingsImporter,
RolesImporter $rolesImporter,
GroupsImporter $groupsImporter,
AttributeImporter $attributeImporter,
string $name = null
private readonly string $projectDir,
private readonly ManagerRegistry $managerRegistry,
private readonly NodeTypesImporter $nodeTypesImporter,
private readonly TagsImporter $tagsImporter,
private readonly SettingsImporter $settingsImporter,
private readonly RolesImporter $rolesImporter,
private readonly GroupsImporter $groupsImporter,
private readonly AttributeImporter $attributeImporter,
?string $name = null
) {
parent::__construct($name);
$this->projectDir = $projectDir;
$this->nodeTypesImporter = $nodeTypesImporter;
$this->tagsImporter = $tagsImporter;
$this->settingsImporter = $settingsImporter;
$this->rolesImporter = $rolesImporter;
$this->groupsImporter = $groupsImporter;
$this->attributeImporter = $attributeImporter;
$this->managerRegistry = $managerRegistry;
}

protected function configure(): void
Expand Down
Loading

0 comments on commit 173a4fb

Please sign in to comment.