XrdController.php 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types = 1);
  3. namespace Component\FreeNetwork\Util;
  4. use App\Core\Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use XML_XRD;
  8. abstract class XrdController extends Controller
  9. {
  10. protected string $default_mimetype = Discovery::JRD_MIMETYPE;
  11. protected XML_XRD $xrd;
  12. /*
  13. * Configures $this->xrd which will later be printed. Must be
  14. * implemented by child classes.
  15. */
  16. abstract protected function setXRD();
  17. public function __construct(RequestStack $requestStack)
  18. {
  19. parent::__construct($requestStack);
  20. if ($this->request->headers->get('format', null) === null) {
  21. $this->request->headers->set('format', $this->default_mimetype);
  22. }
  23. $this->xrd = new XML_XRD();
  24. }
  25. public function handle(Request $request): array
  26. {
  27. $this->setXRD();
  28. return ['xrd' => $this->xrd, 'default_mimetype' => $this->default_mimetype];
  29. }
  30. }