XrdController.php 975 B

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