Skip to content

Commit

Permalink
apply symfony 5.2 set
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Aug 27, 2021
1 parent a20e64e commit 3ebe170
Show file tree
Hide file tree
Showing 59 changed files with 159 additions and 361 deletions.
9 changes: 2 additions & 7 deletions lib/Admin/Controller/ApiClient/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,31 @@ public function __construct(private ApiClientService $service, private UserServi
}

/**
* @Route(path="users/{userId}/api-clients/{id}/audit", name=Audit::class, methods={"GET"}, priority=-255)
*
* @throws InvalidArgumentException
*/
public function __invoke(string $userId, string $id): Response
#[Route(path: 'users/{userId}/api-clients/{id}/audit', name: Audit::class, methods: ['GET'], priority: -255)]
public function __invoke(string $userId, string $id) : Response
{
$user = $this->userService->get($userId);
if (!$user instanceof UserInterface) {
$this->addFlash('error', 'sas.page.user.not_found');

return new RedirectResponse($this->generateUrl(GetAllUser::class));
}

$entity = $this->service->get($id);
if (!$entity instanceof ApiClientInterface) {
$this->addFlash('error', 'sas.page.api_client.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

if (!$this->reader->getProvider()->isAuditable(Group::class)) {
$this->addFlash('error', 'sas.page.audit.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

$audit = $this->audit->getAudits($entity, $id)->toArray();
$class = new ReflectionClass(ApiClient::class);
$context = StringUtil::lowercase($class->getShortName());

return $this->render(sprintf('%s/audit.html.twig', $context), [
'page_title' => 'sas.page.audit.view',
'context' => $context,
Expand Down
10 changes: 2 additions & 8 deletions lib/Admin/Controller/ApiClient/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,23 @@ public function __construct(private ApiClientService $service, private UserServi
{
}

/**
* @Route(path="users/{userId}/api-clients/{id}/delete", name=Delete::class, methods={"GET"})
*/
public function __invoke(string $userId, string $id): Response
#[Route(path: 'users/{userId}/api-clients/{id}/delete', name: Delete::class, methods: ['GET'])]
public function __invoke(string $userId, string $id) : Response
{
$user = $this->userService->get($userId);
if (!$user instanceof UserInterface) {
$this->addFlash('error', 'sas.page.user.not_found');

return new RedirectResponse($this->generateUrl(GetAllUser::class));
}

$client = $this->service->get($id);
if (!$client instanceof ApiClientInterface) {
$this->addFlash('error', 'sas.page.api_client.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

$this->service->remove($client);

$this->addFlash('info', 'sas.page.api_client.deleted');

return new RedirectResponse($this->generateUrl(Main::class));
}
}
10 changes: 2 additions & 8 deletions lib/Admin/Controller/ApiClient/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,26 @@ public function __construct(private ApiClientService $service, private UserServi
{
}

/**
* @Route(path="/users/{userId}/api-clients/download", name=Download::class, methods={"GET"})
*/
public function __invoke(string $userId): Response
#[Route(path: '/users/{userId}/api-clients/download', name: Download::class, methods: ['GET'])]
public function __invoke(string $userId) : Response
{
$user = $this->userService->get($userId);
if (!$user instanceof UserInterface) {
$this->addFlash('error', 'sas.page.user.not_found');

return new RedirectResponse($this->generateUrl(GetAllUser::class));
}

$records = $this->service->total();
if (10000 < $records) {
$this->addFlash('error', 'sas.page.error.too_many_records');

return new RedirectResponse($this->generateUrl(Main::class));
}

$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'text/csv');
$response->headers->set('Content-Disposition', sprintf('attachment; filename="%s_%s.csv"', 'api-clients', date('YmdHis')));

$response->setContent($this->serializer->serialize($this->service->all(), 'csv', ['groups' => 'read']));

return $response;
}
}
9 changes: 2 additions & 7 deletions lib/Admin/Controller/ApiClient/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ public function __construct(
) {
}

/**
* @Route(path="/users/{userId}/api-clients", name=Main::class, methods={"GET", "POST"}, defaults={"userId": "2e0cac45-822f-4b97-95f1-9516ad824ec1"})
*/
public function __invoke(Request $request, string $userId): Response
#[Route(path: '/users/{userId}/api-clients', name: Main::class, methods: ['GET', 'POST'], defaults: ['userId' => '2e0cac45-822f-4b97-95f1-9516ad824ec1'])]
public function __invoke(Request $request, string $userId) : Response
{
$user = $this->userService->get($userId);
if (!$user instanceof UserInterface) {
$this->addFlash('error', 'sas.page.user.not_found');

return new RedirectResponse($this->generateUrl(GetAllUser::class));
}

$client = new ApiClient();
$client->setUser($user);
$form = $this->createForm(ApiClientType::class, $client);
Expand All @@ -58,10 +55,8 @@ public function __invoke(Request $request, string $userId): Response
$this->addFlash('info', 'sas.page.api_client.saved');
}
}

$class = new ReflectionClass(ApiClient::class);
$context = StringUtil::lowercase($class->getShortName());

return $this->render(sprintf('%s/all.html.twig', $context), [
'page_title' => 'sas.page.api_client.list',
'context' => $context,
Expand Down
8 changes: 2 additions & 6 deletions lib/Admin/Controller/ApiClient/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ public function __construct(private ApiClientRequestService $service, private Us
{
}

/**
* @Route(path="/users/{userId}/api-clients/{id}/logs", name=Report::class, methods={"GET"})
*/
public function __invoke(Request $request, string $userId, string $id): Response
#[Route(path: '/users/{userId}/api-clients/{id}/logs', name: Report::class, methods: ['GET'])]
public function __invoke(Request $request, string $userId, string $id) : Response
{
$user = $this->userService->get($userId);
if (!$user instanceof UserInterface) {
$this->addFlash('error', 'sas.page.user.not_found');

return new RedirectResponse($this->generateUrl(GetAllUser::class));
}

$class = new ReflectionClass(ApiClientRequest::class);

return $this->render('apiclient/report.html.twig', [
'page_title' => 'sas.page.api_client.report',
'id' => $id,
Expand Down
7 changes: 2 additions & 5 deletions lib/Admin/Controller/Cron/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ public function __construct(private CronService $service, private AuditService $
}

/**
* @Route(path="/crons/{id}/audit", name=Audit::class, methods={"GET"}, priority=-255)
*
* @throws InvalidArgumentException
*/
public function __invoke(string $id): Response
#[Route(path: '/crons/{id}/audit', name: Audit::class, methods: ['GET'], priority: -255)]
public function __invoke(string $id) : Response
{
if (!$entity = $this->service->get($id)) {
$this->addFlash('error', 'sas.page.cron.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

if (!$this->reader->getProvider()->isAuditable(Cron::class)) {
$this->addFlash('error', 'sas.page.audit.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

return $this->renderAudit($this->audit->getAudits($entity, $id), new ReflectionClass(Cron::class));
}
}
9 changes: 2 additions & 7 deletions lib/Admin/Controller/Cron/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@ public function __construct(private CronService $service)
{
}

/**
* @Route(path="/crons/{id}/delete", name=Delete::class, methods={"GET"})
*/
public function __invoke(string $id): Response
#[Route(path: '/crons/{id}/delete', name: Delete::class, methods: ['GET'])]
public function __invoke(string $id) : Response
{
$cron = $this->service->get($id);
if (!$cron instanceof CronInterface) {
$this->addFlash('error', 'sas.page.cron.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

$this->service->remove($cron);

$this->addFlash('info', 'sas.page.cron.deleted');

return new RedirectResponse($this->generateUrl(Main::class));
}
}
9 changes: 2 additions & 7 deletions lib/Admin/Controller/Cron/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ public function __construct(private CronService $service, private SerializerInte
{
}

/**
* @Route(path="/crons/download", name=Download::class, methods={"GET"})
*/
public function __invoke(): Response
#[Route(path: '/crons/download', name: Download::class, methods: ['GET'])]
public function __invoke() : Response
{
$records = $this->service->total();
if (10000 < $records) {
$this->addFlash('error', 'sas.page.error.too_many_records');

return new RedirectResponse($this->generateUrl(Main::class));
}

$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'text/csv');
$response->headers->set('Content-Disposition', sprintf('attachment; filename="%s_%s.csv"', 'crons', date('YmdHis')));

$response->setContent($this->serializer->serialize($this->service->all(), 'csv', ['groups' => 'read']));

return $response;
}
}
8 changes: 2 additions & 6 deletions lib/Admin/Controller/Cron/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@ public function __construct(private CronService $service, private AuditService $
parent::__construct($this->service);
}

/**
* @Route(path="/crons/{id}", name=Get::class, methods={"GET"})
*/
public function __invoke(string $id): Response
#[Route(path: '/crons/{id}', name: Get::class, methods: ['GET'])]
public function __invoke(string $id) : Response
{
$cron = $this->service->get($id);
if (!$cron instanceof CronInterface) {
$this->addFlash('error', 'sas.page.cron.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

$audit = new Record($cron);
if ($this->reader->getProvider()->isAuditable(Cron::class)) {
$audit = $this->audit->getAudits($cron, $id, 1);
}

return $this->renderDetail($audit, new ReflectionClass(Cron::class));
}
}
8 changes: 2 additions & 6 deletions lib/Admin/Controller/Cron/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public function __construct(private CronService $service, Paginator $paginator)
parent::__construct($this->service, $paginator);
}

/**
* @Route(path="/crons", name=Main::class, methods={"GET", "POST"})
*/
public function __invoke(Request $request): Response
#[Route(path: '/crons', name: Main::class, methods: ['GET', 'POST'])]
public function __invoke(Request $request) : Response
{
$cron = new Cron();
if ($request->isMethod(Request::METHOD_POST)) {
Expand All @@ -46,7 +44,6 @@ public function __invoke(Request $request): Response
}
}
}

$form = $this->createForm(CronType::class, $cron);
if ($request->isMethod(Request::METHOD_POST)) {
$form->handleRequest($request);
Expand All @@ -55,7 +52,6 @@ public function __invoke(Request $request): Response
$this->addFlash('info', 'sas.page.cron.saved');
}
}

return $this->renderList($form, $request, new ReflectionClass(Cron::class));
}
}
8 changes: 2 additions & 6 deletions lib/Admin/Controller/Cron/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ public function __construct(private CronService $service)
{
}

/**
* @Route(path="/crons/{id}/edit", name=Put::class, methods={"GET"}, priority=1)
*/
public function __invoke(Request $request, string $id): Response
#[Route(path: '/crons/{id}/edit', name: Put::class, methods: ['GET'], priority: 1)]
public function __invoke(Request $request, string $id) : Response
{
$cron = $this->service->get($id);
if (!$cron instanceof CronInterface) {
$this->addFlash('error', 'sas.page.cron.not_found');
}

$this->addFlash('id', $cron->getId());

return new RedirectResponse($this->generateUrl(Main::class, $request->query->all()));
}
}
8 changes: 2 additions & 6 deletions lib/Admin/Controller/Cron/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ public function __construct(private CronReportService $service, private Paginato
{
}

/**
* @Route(path="/crons/{id}/logs", name=Report::class, methods={"GET"}, priority=-27)
*/
public function __invoke(Request $request, string $id): Response
#[Route(path: '/crons/{id}/logs', name: Report::class, methods: ['GET'], priority: -27)]
public function __invoke(Request $request, string $id) : Response
{
$class = new ReflectionClass(CronReport::class);

$request->query->set($this->settingService->getPerPageField(), 10);

return $this->render('cron/report.html.twig', [
'page_title' => 'sas.page.cron_report.list',
'id' => $id,
Expand Down
10 changes: 2 additions & 8 deletions lib/Admin/Controller/Cron/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,28 @@ public function __construct(private CronService $service, private KernelInterfac
{
}

/**
* @Route(path="/crons/{id}/run", name=Run::class, methods={"GET"}, priority=-17)
*/
public function __invoke(string $id): Response
#[Route(path: '/crons/{id}/run', name: Run::class, methods: ['GET'], priority: -17)]
public function __invoke(string $id) : Response
{
$cron = $this->service->get($id);
if (!$cron instanceof CronInterface) {
$this->addFlash('error', 'sas.page.cron.not_found');

return new RedirectResponse($this->generateUrl(Main::class));
}

$application = new Application($this->kernel);
$application->setAutoExit(false);

$input = new ArrayInput([
'command' => 'semart:cron:run',
'job' => $cron->getId(),
'--schedule_now' => null,
]);

$return = $application->run($input, new NullOutput());
if (0 === $return) {
$this->addFlash('info', 'sas.page.cron.run_success');
} else {
$this->addFlash('error', 'sas.page.cron.run_failed');
}

return new RedirectResponse($this->generateUrl(Get::class, ['id' => $id]));
}
}
6 changes: 2 additions & 4 deletions lib/Admin/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
*/
final class DashboardController extends Base
{
/**
* @Route(path="/", name=AdminContext::ADMIN_ROUTE, methods={"GET"})
*/
public function __invoke(): Response
#[Route(path: '/', name: AdminContext::ADMIN_ROUTE, methods: ['GET'])]
public function __invoke() : Response
{
return $this->render('dashboard/layout.html.twig', ['page_title' => 'sas.page.dashboard']);
}
Expand Down
Loading

0 comments on commit 3ebe170

Please sign in to comment.