Index.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swagger\Block;
  7. use Magento\Framework\Phrase;
  8. use Magento\Framework\View\Element\Template;
  9. use Magento\Swagger\Api\Data\SchemaTypeInterface;
  10. /**
  11. * Block for swagger index page
  12. *
  13. * @api
  14. *
  15. * @method SchemaTypeInterface[] getSchemaTypes()
  16. * @method bool hasSchemaTypes()
  17. * @method string getDefaultSchemaTypeCode()
  18. * @since 100.2.1
  19. */
  20. class Index extends Template
  21. {
  22. /**
  23. * @return mixed|string
  24. */
  25. private function getParamStore()
  26. {
  27. return $this->getRequest()->getParam('store') ?: 'all';
  28. }
  29. /**
  30. * @return SchemaTypeInterface|null
  31. */
  32. private function getSchemaType()
  33. {
  34. if (!$this->hasSchemaTypes()) {
  35. return null;
  36. }
  37. $schemaTypeCode = $this->getRequest()->getParam(
  38. 'type',
  39. $this->getDefaultSchemaTypeCode()
  40. );
  41. if (!array_key_exists($schemaTypeCode, $this->getSchemaTypes())) {
  42. throw new \UnexpectedValueException(
  43. new Phrase('Unknown schema type supplied')
  44. );
  45. }
  46. return $this->getSchemaTypes()[$schemaTypeCode];
  47. }
  48. /**
  49. * @return string|null
  50. * @since 100.2.1
  51. */
  52. public function getSchemaUrl()
  53. {
  54. if ($this->getSchemaType() === null) {
  55. return null;
  56. }
  57. return rtrim($this->getBaseUrl(), '/') .
  58. $this->getSchemaType()->getSchemaUrlPath($this->getParamStore());
  59. }
  60. }