| @@ 34-93 (lines=60) @@ | ||
| 31 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
|
| 32 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
|
| 33 | */ |
|
| 34 | public function get( ServerRequestInterface $request, ResponseInterface $response ) |
|
| 35 | { |
|
| 36 | $view = $this->getView(); |
|
| 37 | ||
| 38 | try |
|
| 39 | { |
|
| 40 | if( $view->param( 'id' ) != '' ) { |
|
| 41 | $response = $this->getItem( $view, $request, $response ); |
|
| 42 | } else { |
|
| 43 | $response = $this->getItems( $view, $request, $response ); |
|
| 44 | } |
|
| 45 | ||
| 46 | $status = 200; |
|
| 47 | } |
|
| 48 | catch( \Aimeos\MShop\Exception $e ) |
|
| 49 | { |
|
| 50 | $status = 404; |
|
| 51 | $view->errors = array( array( |
|
| 52 | 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
| 53 | 'detail' => $e->getTraceAsString(), |
|
| 54 | ) ); |
|
| 55 | } |
|
| 56 | catch( \Exception $e ) |
|
| 57 | { |
|
| 58 | $status = 500; |
|
| 59 | $view->errors = array( array( |
|
| 60 | 'title' => $e->getMessage(), |
|
| 61 | 'detail' => $e->getTraceAsString(), |
|
| 62 | ) ); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** client/jsonapi/attribute/standard/template-get |
|
| 66 | * Relative path to the attribute lists JSON API template for GET requests |
|
| 67 | * |
|
| 68 | * The template file contains the code and processing instructions |
|
| 69 | * to generate the result shown in the JSON API body. The |
|
| 70 | * configuration string is the path to the template file relative |
|
| 71 | * to the templates directory (usually in client/jsonapi/templates). |
|
| 72 | * |
|
| 73 | * You can overwrite the template file configuration in extensions and |
|
| 74 | * provide alternative templates. These alternative templates should be |
|
| 75 | * named like the default one but with the string "default" replaced by |
|
| 76 | * an unique name. You may use the name of your project for this. If |
|
| 77 | * you've implemented an alternative client class as well, "standard" |
|
| 78 | * should be replaced by the name of the new class. |
|
| 79 | * |
|
| 80 | * @param string Relative path to the template creating the body for the GET method of the JSON API |
|
| 81 | * @since 2017.03 |
|
| 82 | * @category Developer |
|
| 83 | */ |
|
| 84 | $tplconf = 'client/jsonapi/attribute/standard/template-get'; |
|
| 85 | $default = 'attribute/get-default.php'; |
|
| 86 | ||
| 87 | $body = $view->render( $view->config( $tplconf, $default ) ); |
|
| 88 | ||
| 89 | return $response->withHeader( 'Allow', 'GET' ) |
|
| 90 | ->withHeader( 'Content-Type', 'application/vnd.api+json' ) |
|
| 91 | ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
| 92 | ->withStatus( $status ); |
|
| 93 | } |
|
| 94 | ||
| 95 | ||
| 96 | /** |
|
| @@ 34-93 (lines=60) @@ | ||
| 31 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
|
| 32 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
|
| 33 | */ |
|
| 34 | public function get( ServerRequestInterface $request, ResponseInterface $response ) |
|
| 35 | { |
|
| 36 | $view = $this->getView(); |
|
| 37 | ||
| 38 | try |
|
| 39 | { |
|
| 40 | if( $view->param( 'id' ) != '' ) { |
|
| 41 | $response = $this->getItem( $view, $request, $response ); |
|
| 42 | } else { |
|
| 43 | $response = $this->getItems( $view, $request, $response ); |
|
| 44 | } |
|
| 45 | ||
| 46 | $status = 200; |
|
| 47 | } |
|
| 48 | catch( \Aimeos\MShop\Exception $e ) |
|
| 49 | { |
|
| 50 | $status = 404; |
|
| 51 | $view->errors = array( array( |
|
| 52 | 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
| 53 | 'detail' => $e->getTraceAsString(), |
|
| 54 | ) ); |
|
| 55 | } |
|
| 56 | catch( \Exception $e ) |
|
| 57 | { |
|
| 58 | $status = 500; |
|
| 59 | $view->errors = array( array( |
|
| 60 | 'title' => $e->getMessage(), |
|
| 61 | 'detail' => $e->getTraceAsString(), |
|
| 62 | ) ); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** client/jsonapi/stock/standard/template-get |
|
| 66 | * Relative path to the catalog lists JSON API template for GET requests |
|
| 67 | * |
|
| 68 | * The template file contains the code and processing instructions |
|
| 69 | * to generate the result shown in the JSON API body. The |
|
| 70 | * configuration string is the path to the template file relative |
|
| 71 | * to the templates directory (usually in client/jsonapi/templates). |
|
| 72 | * |
|
| 73 | * You can overwrite the template file configuration in extensions and |
|
| 74 | * provide alternative templates. These alternative templates should be |
|
| 75 | * named like the default one but with the string "default" replaced by |
|
| 76 | * an unique name. You may use the name of your project for this. If |
|
| 77 | * you've implemented an alternative client class as well, "standard" |
|
| 78 | * should be replaced by the name of the new class. |
|
| 79 | * |
|
| 80 | * @param string Relative path to the template creating the body for the GET method of the JSON API |
|
| 81 | * @since 2017.03 |
|
| 82 | * @category Developer |
|
| 83 | */ |
|
| 84 | $tplconf = 'client/jsonapi/stock/standard/template-get'; |
|
| 85 | $default = 'stock/get-default.php'; |
|
| 86 | ||
| 87 | $body = $view->render( $view->config( $tplconf, $default ) ); |
|
| 88 | ||
| 89 | return $response->withHeader( 'Allow', 'GET' ) |
|
| 90 | ->withHeader( 'Content-Type', 'application/vnd.api+json' ) |
|
| 91 | ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
| 92 | ->withStatus( $status ); |
|
| 93 | } |
|
| 94 | ||
| 95 | ||
| 96 | /** |
|
| @@ 34-93 (lines=60) @@ | ||
| 31 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
|
| 32 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
|
| 33 | */ |
|
| 34 | public function get( ServerRequestInterface $request, ResponseInterface $response ) |
|
| 35 | { |
|
| 36 | $view = $this->getView(); |
|
| 37 | ||
| 38 | try |
|
| 39 | { |
|
| 40 | if( $view->param( 'id' ) != '' ) { |
|
| 41 | $response = $this->getItem( $view, $request, $response ); |
|
| 42 | } else { |
|
| 43 | $response = $this->getItems( $view, $request, $response ); |
|
| 44 | } |
|
| 45 | ||
| 46 | $status = 200; |
|
| 47 | } |
|
| 48 | catch( \Aimeos\MShop\Exception $e ) |
|
| 49 | { |
|
| 50 | $status = 404; |
|
| 51 | $view->errors = array( array( |
|
| 52 | 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
| 53 | 'detail' => $e->getTraceAsString(), |
|
| 54 | ) ); |
|
| 55 | } |
|
| 56 | catch( \Exception $e ) |
|
| 57 | { |
|
| 58 | $status = 500; |
|
| 59 | $view->errors = array( array( |
|
| 60 | 'title' => $e->getMessage(), |
|
| 61 | 'detail' => $e->getTraceAsString(), |
|
| 62 | ) ); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** client/jsonapi/locale/standard/template-get |
|
| 66 | * Relative path to the locale lists JSON API template for GET requests |
|
| 67 | * |
|
| 68 | * The template file contains the code and processing instructions |
|
| 69 | * to generate the result shown in the JSON API body. The |
|
| 70 | * configuration string is the path to the template file relative |
|
| 71 | * to the templates directory (usually in client/jsonapi/templates). |
|
| 72 | * |
|
| 73 | * You can overwrite the template file configuration in extensions and |
|
| 74 | * provide alternative templates. These alternative templates should be |
|
| 75 | * named like the default one but with the string "default" replaced by |
|
| 76 | * an unique name. You may use the name of your project for this. If |
|
| 77 | * you've implemented an alternative client class as well, "standard" |
|
| 78 | * should be replaced by the name of the new class. |
|
| 79 | * |
|
| 80 | * @param string Relative path to the template creating the body for the GET method of the JSON API |
|
| 81 | * @since 2017.03 |
|
| 82 | * @category Developer |
|
| 83 | */ |
|
| 84 | $tplconf = 'client/jsonapi/locale/standard/template-get'; |
|
| 85 | $default = 'locale/get-default.php'; |
|
| 86 | ||
| 87 | $body = $view->render( $view->config( $tplconf, $default ) ); |
|
| 88 | ||
| 89 | return $response->withHeader( 'Allow', 'GET' ) |
|
| 90 | ->withHeader( 'Content-Type', 'application/vnd.api+json' ) |
|
| 91 | ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
| 92 | ->withStatus( $status ); |
|
| 93 | } |
|
| 94 | ||
| 95 | ||
| 96 | /** |
|