-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteController.php
More file actions
50 lines (39 loc) · 1.53 KB
/
ExecuteController.php
File metadata and controls
50 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace SyncEngine\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use SyncEngine\Controller\Api\ApiEndpointController;
use SyncEngine\Service\Execute;
use SyncEngine\Service\System;
class ExecuteController extends DefaultController
{
// @todo Allow in dev only?
#[Route( '/execute/endpoint/{endpoint}/{action}', name: 'endpoint_execute', defaults: [ 'action' => 'execute' ] )]
public function endpoint_profiler( string $endpoint, string $action, ApiEndpointController $endpointController, Execute $execute, ?Request $request = null ): Response
{
$response = $endpointController->endpoint( $endpoint, $action, $execute, $request );
if ( ! $response instanceof JsonResponse ) {
return $response;
}
$results = json_decode( $response->getContent(), true );
if ( isset( $results['success'] ) ) {
$results['code'] = $response->getStatusCode();
}
try {
$response = $this->render( 'api/endpoint.html.twig', [ 'response' => $results ] );
} catch ( \Exception $e ) {}
return $response;
}
#[Route( '/execute/clear:cache', name: 'execute_clear_cache' )]
public function execute_clear_cache( System $system, ?Request $request = null ): Response
{
$redirect = $request->request->get( 'redirect' );
$system->runCommand( 'cache:clear' );
if ( $redirect ) {
return $this->redirect( $redirect );
}
return $this->redirectToRoute( 'syncengine_system_index' );
}
}