| 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 | * @throws UnexpectedValueException if the YUML service answered incorrectly |
||
| 33 | */ |
||
| 34 | public function indexAction() : Response |
||
| 35 | { |
||
| 36 | $request = $this->getRequest(); |
||
| 37 | assert($request instanceof Request); |
||
| 38 | 2 | $this->httpClient->setMethod(Request::METHOD_POST); |
|
| 39 | $this->httpClient->setParameterPost(['dsl_text' => $request->getPost('dsl_text')]); |
||
| 40 | $response = $this->httpClient->send(); |
||
| 41 | 2 | ||
| 42 | 2 | if (! $response->isSuccess()) { |
|
| 43 | 2 | throw new UnexpectedValueException('HTTP Request failed'); |
|
| 44 | 2 | } |
|
| 45 | |||
| 46 | 2 | $redirect = $this->plugin('redirect'); |
|
| 47 | 1 | assert($redirect instanceof Redirect); |
|
| 48 | |||
| 49 | return $redirect->toUrl('https://yuml.me/' . $response->getBody()); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |