Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -18,27 +18,20 @@ use App\Event\CustomerMetaDefinitionEvent;
use App\Event\CustomerUpdatePostEvent;
use App\Event\CustomerUpdatePreEvent;
use App\Repository\CustomerRepository;
use App\Utils\NumberGenerator;
use App\Validator\ValidationFailedException;
use InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @final
*/
class CustomerService
final class CustomerService
{
private $repository;
private $dispatcher;
private $validator;
private $configuration;
public function __construct(CustomerRepository $customerRepository, SystemConfiguration $configuration, ValidatorInterface $validator, EventDispatcherInterface $dispatcher)
{
$this->repository = $customerRepository;
$this->dispatcher = $dispatcher;
$this->validator = $validator;
$this->configuration = $configuration;
public function __construct(
private CustomerRepository $repository,
private SystemConfiguration $configuration,
private ValidatorInterface $validator,
private EventDispatcherInterface $dispatcher
) {
}
private function getDefaultTimezone(): string
@@ -50,12 +43,13 @@ class CustomerService
return $timezone;
}
public function createNewCustomer(): Customer
public function createNewCustomer(string $name): Customer
{
$customer = new Customer();
$customer = new Customer($name);
$customer->setTimezone($this->getDefaultTimezone());
$customer->setCountry($this->configuration->getCustomerDefaultCountry());
$customer->setCurrency($this->configuration->getCustomerDefaultCurrency());
$customer->setNumber($this->calculateNextCustomerNumber());
$this->dispatcher->dispatch(new CustomerMetaDefinitionEvent($customer));
$this->dispatcher->dispatch(new CustomerCreateEvent($customer));
@@ -112,4 +106,21 @@ class CustomerService
{
return $this->repository->findOneBy(['number' => $number]);
}
public function calculateNextCustomerNumber(): string
{
$format = $this->configuration->find('customer.number_format');
if (empty($format) || !\is_string($format)) {
$format = '{cc,4}';
}
$numberGenerator = new NumberGenerator($format, function (string $originalFormat, string $format, int $increaseBy): string|int {
return match ($format) {
'cc' => $this->repository->count([]) + $increaseBy,
default => $originalFormat,
};
});
return $numberGenerator->getNumber();
}
}