1 | <?php |
||
16 | * Utility to generate Yuml compatible strings from metadata graphs |
||
17 | * |
||
18 | * @link http://www.doctrine-project.org/ |
||
19 | */ |
||
20 | class YumlController extends AbstractActionController |
||
21 | { |
||
22 | protected Client $httpClient; |
||
|
|||
23 | |||
24 | public function __construct(Client $httpClient) |
||
25 | { |
||
26 | 1 | $this->httpClient = $httpClient; |
|
27 | } |
||
28 | 1 | ||
29 | 1 | /** |
|
30 | * Redirects the user to a YUML graph drawn with the provided `dsl_text` |
||
31 | * |
||
32 | * If the YUML service answered incorrectly throws exception |
||
33 | * |
||
34 | * @throws UnexpectedValueException |
||
35 | */ |
||
36 | public function indexAction() : Response |
||
37 | { |
||
38 | 2 | $request = $this->getRequest(); |
|
39 | assert($request instanceof Request); |
||
40 | $this->httpClient->setMethod(Request::METHOD_POST); |
||
41 | 2 | $this->httpClient->setParameterPost(['dsl_text' => $request->getPost('dsl_text')]); |
|
42 | 2 | $response = $this->httpClient->send(); |
|
43 | 2 | ||
44 | 2 | if (! $response->isSuccess()) { |
|
45 | throw new UnexpectedValueException('HTTP Request failed'); |
||
46 | 2 | } |
|
47 | 1 | ||
48 | $redirect = $this->plugin('redirect'); |
||
49 | assert($redirect instanceof Redirect); |
||
50 | |||
51 | 1 | return $redirect->toUrl('https://yuml.me/' . $response->getBody()); |
|
52 | } |
||
53 | } |
||
54 |