@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | * @class RouteMatchMiddleware |
| 61 | 61 | * @package Platine\Framework\Http\Middleware |
| 62 | 62 | */ |
| 63 | -class RouteMatchMiddleware implements MiddlewareInterface |
|
| 64 | -{
|
|
| 63 | +class RouteMatchMiddleware implements MiddlewareInterface { |
|
| 65 | 64 | /** |
| 66 | 65 | * The Router instance |
| 67 | 66 | * @var Router |
@@ -79,12 +78,11 @@ discard block |
||
| 79 | 78 | * @param Router $router |
| 80 | 79 | * @param array<string> $allowedMethods the default allowed methods |
| 81 | 80 | */ |
| 82 | - public function __construct(Router $router, array $allowedMethods = ['HEAD']) |
|
| 83 | - {
|
|
| 81 | + public function __construct(Router $router, array $allowedMethods = ['HEAD']) { |
|
| 84 | 82 | $this->router = $router; |
| 85 | 83 | |
| 86 | - foreach ($allowedMethods as $method) {
|
|
| 87 | - if (is_string($method)) {
|
|
| 84 | + foreach ($allowedMethods as $method) { |
|
| 85 | + if (is_string($method)) { |
|
| 88 | 86 | $this->allowedMethods[] = strtoupper($method); |
| 89 | 87 | } |
| 90 | 88 | } |
@@ -97,7 +95,7 @@ discard block |
||
| 97 | 95 | ServerRequestInterface $request, |
| 98 | 96 | RequestHandlerInterface $handler |
| 99 | 97 | ): ResponseInterface {
|
| 100 | - if (!$route = $this->router->match($request, false)) {
|
|
| 98 | + if (!$route = $this->router->match($request, false)) { |
|
| 101 | 99 | return $handler->handle($request); |
| 102 | 100 | } |
| 103 | 101 | |
@@ -105,14 +103,14 @@ discard block |
||
| 105 | 103 | !$this->isAllowedMethod($request->getMethod()) |
| 106 | 104 | && !$route->isAllowedMethod($request->getMethod()) |
| 107 | 105 | && $request->getMethod() !== 'OPTIONS' |
| 108 | - ) {
|
|
| 106 | + ) { |
|
| 109 | 107 | $exception = new HttpMethodNotAllowedException($request); |
| 110 | 108 | $exception->setAllowedMethods($route->getMethods()); |
| 111 | 109 | |
| 112 | 110 | throw $exception; |
| 113 | 111 | } |
| 114 | 112 | |
| 115 | - foreach ($route->getParameters()->all() as $parameter) {
|
|
| 113 | + foreach ($route->getParameters()->all() as $parameter) { |
|
| 116 | 114 | $request = $request->withAttribute( |
| 117 | 115 | $parameter->getName(), |
| 118 | 116 | $parameter->getValue() |
@@ -163,7 +163,7 @@ |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | if (!$this->hasParser($contentType)) {
|
| 166 | - // If not, look for a media type with a structured syntax suffix (RFC 6839) |
|
| 166 | + // If not, look for a media type with a structured syntax suffix (RFC 6839) |
|
| 167 | 167 | $parts = explode('+', $contentType);
|
| 168 | 168 | |
| 169 | 169 | if (count($parts) >= 2) {
|
@@ -138,11 +138,11 @@ |
||
| 138 | 138 | */ |
| 139 | 139 | protected function registerDefaultParsers(): void |
| 140 | 140 | {
|
| 141 | - $this->registerParser('application/json', static function ($body) {
|
|
| 141 | + $this->registerParser('application/json', static function($body) {
|
|
| 142 | 142 | return Json::decode($body, true); |
| 143 | 143 | }); |
| 144 | 144 | |
| 145 | - $this->registerParser('application/x-www-form-urlencoded', static function ($body) {
|
|
| 145 | + $this->registerParser('application/x-www-form-urlencoded', static function($body) {
|
|
| 146 | 146 | $data = []; |
| 147 | 147 | parse_str($body, $data); |
| 148 | 148 | |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | * @class BodyParserMiddleware |
| 59 | 59 | * @package Platine\Framework\Http\Middleware |
| 60 | 60 | */ |
| 61 | -class BodyParserMiddleware implements MiddlewareInterface |
|
| 62 | -{
|
|
| 61 | +class BodyParserMiddleware implements MiddlewareInterface { |
|
| 63 | 62 | /** |
| 64 | 63 | * List of body parser to use |
| 65 | 64 | * @var array<string, callable> |
@@ -69,8 +68,7 @@ discard block |
||
| 69 | 68 | /** |
| 70 | 69 | * Create new instance |
| 71 | 70 | */ |
| 72 | - public function __construct() |
|
| 73 | - {
|
|
| 71 | + public function __construct() { |
|
| 74 | 72 | $this->registerDefaultParsers(); |
| 75 | 73 | } |
| 76 | 74 | |
@@ -82,7 +80,7 @@ discard block |
||
| 82 | 80 | RequestHandlerInterface $handler |
| 83 | 81 | ): ResponseInterface {
|
| 84 | 82 | $parsedBody = $request->getParsedBody(); |
| 85 | - if ($parsedBody === null || empty($parsedBody)) {
|
|
| 83 | + if ($parsedBody === null || empty($parsedBody)) { |
|
| 86 | 84 | $parsedBody = $this->parseBody($request); |
| 87 | 85 | |
| 88 | 86 | $request = $request->withParsedBody($parsedBody); |
@@ -122,7 +120,7 @@ discard block |
||
| 122 | 120 | */ |
| 123 | 121 | public function getParser(string $contentType): callable |
| 124 | 122 | {
|
| 125 | - if (!isset($this->parsers[$contentType])) {
|
|
| 123 | + if (!isset($this->parsers[$contentType])) { |
|
| 126 | 124 | throw new RuntimeException(sprintf( |
| 127 | 125 | 'Can not find the parser for the given content type [%s]', |
| 128 | 126 | $contentType |
@@ -138,11 +136,11 @@ discard block |
||
| 138 | 136 | */ |
| 139 | 137 | protected function registerDefaultParsers(): void |
| 140 | 138 | {
|
| 141 | - $this->registerParser('application/json', static function ($body) {
|
|
| 139 | + $this->registerParser('application/json', static function ($body) { |
|
| 142 | 140 | return Json::decode($body, true); |
| 143 | 141 | }); |
| 144 | 142 | |
| 145 | - $this->registerParser('application/x-www-form-urlencoded', static function ($body) {
|
|
| 143 | + $this->registerParser('application/x-www-form-urlencoded', static function ($body) { |
|
| 146 | 144 | $data = []; |
| 147 | 145 | parse_str($body, $data); |
| 148 | 146 | |
@@ -155,28 +153,27 @@ discard block |
||
| 155 | 153 | * @param ServerRequestInterface $request |
| 156 | 154 | * @return null|array<mixed>|object |
| 157 | 155 | */ |
| 158 | - protected function parseBody(ServerRequestInterface $request) |
|
| 159 | - {
|
|
| 156 | + protected function parseBody(ServerRequestInterface $request) { |
|
| 160 | 157 | $contentType = $this->getRequestContentType($request); |
| 161 | - if ($contentType === null) {
|
|
| 158 | + if ($contentType === null) { |
|
| 162 | 159 | return null; |
| 163 | 160 | } |
| 164 | 161 | |
| 165 | - if (!$this->hasParser($contentType)) {
|
|
| 162 | + if (!$this->hasParser($contentType)) { |
|
| 166 | 163 | // If not, look for a media type with a structured syntax suffix (RFC 6839) |
| 167 | 164 | $parts = explode('+', $contentType);
|
| 168 | 165 | |
| 169 | - if (count($parts) >= 2) {
|
|
| 166 | + if (count($parts) >= 2) { |
|
| 170 | 167 | $contentType = 'application/' . $parts[count($parts) - 1]; |
| 171 | 168 | } |
| 172 | 169 | } |
| 173 | 170 | |
| 174 | - if ($this->hasParser($contentType)) {
|
|
| 171 | + if ($this->hasParser($contentType)) { |
|
| 175 | 172 | $body = (string) $request->getBody(); |
| 176 | 173 | $parser = $this->getParser($contentType); |
| 177 | 174 | |
| 178 | 175 | $parsed = $parser($body); |
| 179 | - if (!is_null($parsed) && !is_array($parsed) && !is_object($parsed)) {
|
|
| 176 | + if (!is_null($parsed) && !is_array($parsed) && !is_object($parsed)) { |
|
| 180 | 177 | throw new RuntimeException(sprintf( |
| 181 | 178 | 'The return value of body parser must be an array, an ' |
| 182 | 179 | . 'object, or null, got [%s]', |
@@ -200,7 +197,7 @@ discard block |
||
| 200 | 197 | $contentTypes = $request->getHeader('Content-Type');
|
| 201 | 198 | $contentType = $contentTypes[0] ?? null; |
| 202 | 199 | |
| 203 | - if (is_string($contentType) && trim($contentType) !== '') {
|
|
| 200 | + if (is_string($contentType) && trim($contentType) !== '') { |
|
| 204 | 201 | $parts = explode(';', $contentType);
|
| 205 | 202 | |
| 206 | 203 | return strtolower(trim($parts[0])); |
@@ -152,7 +152,7 @@ |
||
| 152 | 152 | */ |
| 153 | 153 | protected function shouldBeProcessed(ServerRequestInterface $request): bool |
| 154 | 154 | {
|
| 155 | - //If no route has been match no need check for CSRF |
|
| 155 | + //If no route has been match no need check for CSRF |
|
| 156 | 156 | /** @var ?Route $route */ |
| 157 | 157 | $route = $request->getAttribute(Route::class); |
| 158 | 158 | if (!$route) {
|
@@ -64,8 +64,7 @@ discard block |
||
| 64 | 64 | * @package Platine\Framework\Http\Middleware |
| 65 | 65 | * @template T |
| 66 | 66 | */ |
| 67 | -class CsrfMiddleware implements MiddlewareInterface |
|
| 68 | -{
|
|
| 67 | +class CsrfMiddleware implements MiddlewareInterface { |
|
| 69 | 68 | /** |
| 70 | 69 | * The configuration instance |
| 71 | 70 | * @var Config<T> |
@@ -108,7 +107,7 @@ discard block |
||
| 108 | 107 | Lang $lang, |
| 109 | 108 | Config $config, |
| 110 | 109 | CsrfManager $csrfManager |
| 111 | - ) {
|
|
| 110 | + ) { |
|
| 112 | 111 | $this->config = $config; |
| 113 | 112 | $this->csrfManager = $csrfManager; |
| 114 | 113 | $this->lang = $lang; |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | RequestHandlerInterface $handler |
| 124 | 123 | ): ResponseInterface {
|
| 125 | 124 | |
| 126 | - if (!$this->shouldBeProcessed($request)) {
|
|
| 125 | + if (!$this->shouldBeProcessed($request)) { |
|
| 127 | 126 | return $handler->handle($request); |
| 128 | 127 | } |
| 129 | 128 | |
| 130 | 129 | $this->request = $request; |
| 131 | 130 | |
| 132 | - if ($this->isValid() === false) {
|
|
| 131 | + if ($this->isValid() === false) { |
|
| 133 | 132 | return $this->unauthorizedResponse(); |
| 134 | 133 | } |
| 135 | 134 | |
@@ -155,7 +154,7 @@ discard block |
||
| 155 | 154 | //If no route has been match no need check for CSRF |
| 156 | 155 | /** @var ?Route $route */ |
| 157 | 156 | $route = $request->getAttribute(Route::class); |
| 158 | - if (!$route) {
|
|
| 157 | + if (!$route) { |
|
| 159 | 158 | return false; |
| 160 | 159 | } |
| 161 | 160 | |
@@ -164,13 +163,13 @@ discard block |
||
| 164 | 163 | |
| 165 | 164 | $methods = $this->config->get('security.csrf.http_methods', []);
|
| 166 | 165 | |
| 167 | - if (!in_array($request->getMethod(), $methods) && $csrf === false) {
|
|
| 166 | + if (!in_array($request->getMethod(), $methods) && $csrf === false) { |
|
| 168 | 167 | return false; |
| 169 | 168 | } |
| 170 | 169 | |
| 171 | 170 | //check if is url whitelist |
| 172 | 171 | $urls = $this->config->get('security.csrf.url_whitelist', []);
|
| 173 | - if (in_array($route->getName(), $urls)) {
|
|
| 172 | + if (in_array($route->getName(), $urls)) { |
|
| 174 | 173 | return false; |
| 175 | 174 | } |
| 176 | 175 | |
@@ -71,45 +71,45 @@ discard block |
||
| 71 | 71 | class CrudAction |
| 72 | 72 | {
|
| 73 | 73 | /** |
| 74 | - * The Lang instance |
|
| 75 | - * @var Lang |
|
| 76 | - */ |
|
| 74 | + * The Lang instance |
|
| 75 | + * @var Lang |
|
| 76 | + */ |
|
| 77 | 77 | protected Lang $lang; |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | - * The Pagination instance |
|
| 81 | - * @var Pagination |
|
| 82 | - */ |
|
| 80 | + * The Pagination instance |
|
| 81 | + * @var Pagination |
|
| 82 | + */ |
|
| 83 | 83 | protected Pagination $pagination; |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | - * The Template instance |
|
| 87 | - * @var Template |
|
| 88 | - */ |
|
| 86 | + * The Template instance |
|
| 87 | + * @var Template |
|
| 88 | + */ |
|
| 89 | 89 | protected Template $template; |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * The Flash instance |
|
| 93 | - * @var Flash |
|
| 94 | - */ |
|
| 92 | + * The Flash instance |
|
| 93 | + * @var Flash |
|
| 94 | + */ |
|
| 95 | 95 | protected Flash $flash; |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * The RouteHelper instance |
|
| 99 | - * @var RouteHelper |
|
| 100 | - */ |
|
| 98 | + * The RouteHelper instance |
|
| 99 | + * @var RouteHelper |
|
| 100 | + */ |
|
| 101 | 101 | protected RouteHelper $routeHelper; |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * The LoggerInterface instance |
|
| 105 | - * @var LoggerInterface |
|
| 106 | - */ |
|
| 104 | + * The LoggerInterface instance |
|
| 105 | + * @var LoggerInterface |
|
| 106 | + */ |
|
| 107 | 107 | protected LoggerInterface $logger; |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | - * The Repository instance |
|
| 111 | - * @var Repository<TEntity> |
|
| 112 | - */ |
|
| 110 | + * The Repository instance |
|
| 111 | + * @var Repository<TEntity> |
|
| 112 | + */ |
|
| 113 | 113 | protected Repository $repository; |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | protected string $validatorClass; |
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | - * Create new instance |
|
| 201 | - * @param Lang $lang |
|
| 202 | - * @param Pagination $pagination |
|
| 203 | - * @param Template $template |
|
| 204 | - * @param Flash $flash |
|
| 205 | - * @param RouteHelper $routeHelper |
|
| 206 | - * @param LoggerInterface $logger |
|
| 207 | - */ |
|
| 200 | + * Create new instance |
|
| 201 | + * @param Lang $lang |
|
| 202 | + * @param Pagination $pagination |
|
| 203 | + * @param Template $template |
|
| 204 | + * @param Flash $flash |
|
| 205 | + * @param RouteHelper $routeHelper |
|
| 206 | + * @param LoggerInterface $logger |
|
| 207 | + */ |
|
| 208 | 208 | public function __construct( |
| 209 | 209 | Lang $lang, |
| 210 | 210 | Pagination $pagination, |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * List all entities |
|
| 226 | - * @param ServerRequestInterface $request |
|
| 227 | - * @return ResponseInterface |
|
| 228 | - */ |
|
| 225 | + * List all entities |
|
| 226 | + * @param ServerRequestInterface $request |
|
| 227 | + * @return ResponseInterface |
|
| 228 | + */ |
|
| 229 | 229 | public function index(ServerRequestInterface $request): ResponseInterface |
| 230 | 230 | {
|
| 231 | 231 | $context = $this->getTemplateData(); |
@@ -237,14 +237,14 @@ discard block |
||
| 237 | 237 | $currentPage = (int) $param->get('page', 1);
|
| 238 | 238 | |
| 239 | 239 | $this->pagination->setTotalItems($totalItems) |
| 240 | - ->setCurrentPage($currentPage); |
|
| 240 | + ->setCurrentPage($currentPage); |
|
| 241 | 241 | |
| 242 | 242 | $limit = $this->pagination->getItemsPerPage(); |
| 243 | 243 | $offset = $this->pagination->getOffset(); |
| 244 | 244 | |
| 245 | 245 | $query = $this->repository->query(); |
| 246 | 246 | $query->offset($offset) |
| 247 | - ->limit($limit); |
|
| 247 | + ->limit($limit); |
|
| 248 | 248 | |
| 249 | 249 | if (count($this->orderFields) > 0) {
|
| 250 | 250 | foreach ($this->orderFields as $field => $dir) {
|
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * List entity detail |
|
| 274 | - * @param ServerRequestInterface $request |
|
| 275 | - * @return ResponseInterface |
|
| 276 | - */ |
|
| 273 | + * List entity detail |
|
| 274 | + * @param ServerRequestInterface $request |
|
| 275 | + * @return ResponseInterface |
|
| 276 | + */ |
|
| 277 | 277 | public function detail(ServerRequestInterface $request): ResponseInterface |
| 278 | 278 | {
|
| 279 | 279 | $routeListName = sprintf('%s_list', $this->routePrefix);
|
@@ -301,10 +301,10 @@ discard block |
||
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | - * Create new entity |
|
| 305 | - * @param ServerRequestInterface $request |
|
| 306 | - * @return ResponseInterface |
|
| 307 | - */ |
|
| 304 | + * Create new entity |
|
| 305 | + * @param ServerRequestInterface $request |
|
| 306 | + * @return ResponseInterface |
|
| 307 | + */ |
|
| 308 | 308 | public function create(ServerRequestInterface $request): ResponseInterface |
| 309 | 309 | {
|
| 310 | 310 | $routeListName = sprintf('%s_list', $this->routePrefix);
|
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
| 381 | - * Update existing entity |
|
| 382 | - * @param ServerRequestInterface $request |
|
| 383 | - * @return ResponseInterface |
|
| 384 | - */ |
|
| 381 | + * Update existing entity |
|
| 382 | + * @param ServerRequestInterface $request |
|
| 383 | + * @return ResponseInterface |
|
| 384 | + */ |
|
| 385 | 385 | public function update(ServerRequestInterface $request): ResponseInterface |
| 386 | 386 | {
|
| 387 | 387 | $routeListName = sprintf('%s_list', $this->routePrefix);
|
@@ -467,10 +467,10 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
| 470 | - * Delete the entity |
|
| 471 | - * @param ServerRequestInterface $request |
|
| 472 | - * @return ResponseInterface |
|
| 473 | - */ |
|
| 470 | + * Delete the entity |
|
| 471 | + * @param ServerRequestInterface $request |
|
| 472 | + * @return ResponseInterface |
|
| 473 | + */ |
|
| 474 | 474 | public function delete(ServerRequestInterface $request): ResponseInterface |
| 475 | 475 | {
|
| 476 | 476 | $routeListName = sprintf('%s_list', $this->routePrefix);
|
@@ -68,8 +68,7 @@ discard block |
||
| 68 | 68 | * @package Platine\Framework\Http\Action |
| 69 | 69 | * @template TEntity as \Platine\Orm\Entity |
| 70 | 70 | */ |
| 71 | -class CrudAction |
|
| 72 | -{
|
|
| 71 | +class CrudAction { |
|
| 73 | 72 | /** |
| 74 | 73 | * The Lang instance |
| 75 | 74 | * @var Lang |
@@ -212,7 +211,7 @@ discard block |
||
| 212 | 211 | Flash $flash, |
| 213 | 212 | RouteHelper $routeHelper, |
| 214 | 213 | LoggerInterface $logger |
| 215 | - ) {
|
|
| 214 | + ) { |
|
| 216 | 215 | $this->lang = $lang; |
| 217 | 216 | $this->pagination = $pagination; |
| 218 | 217 | $this->template = $template; |
@@ -246,11 +245,11 @@ discard block |
||
| 246 | 245 | $query->offset($offset) |
| 247 | 246 | ->limit($limit); |
| 248 | 247 | |
| 249 | - if (count($this->orderFields) > 0) {
|
|
| 250 | - foreach ($this->orderFields as $field => $dir) {
|
|
| 251 | - if (is_int($field)) {
|
|
| 248 | + if (count($this->orderFields) > 0) { |
|
| 249 | + foreach ($this->orderFields as $field => $dir) { |
|
| 250 | + if (is_int($field)) { |
|
| 252 | 251 | $query->orderBy($dir); |
| 253 | - } else {
|
|
| 252 | + } else { |
|
| 254 | 253 | $query->orderBy($field, $dir); |
| 255 | 254 | } |
| 256 | 255 | } |
@@ -284,7 +283,7 @@ discard block |
||
| 284 | 283 | /** @var TEntity|null $entity */ |
| 285 | 284 | $entity = $this->repository->find($id); |
| 286 | 285 | |
| 287 | - if ($entity === null) {
|
|
| 286 | + if ($entity === null) { |
|
| 288 | 287 | $this->flash->setError($this->lang->tr($this->messageNotFound)); |
| 289 | 288 | |
| 290 | 289 | return new RedirectResponse( |
@@ -315,7 +314,7 @@ discard block |
||
| 315 | 314 | $formParam = new $this->paramClass($param->posts()); |
| 316 | 315 | $context['param'] = $formParam; |
| 317 | 316 | |
| 318 | - if ($request->getMethod() === 'GET') {
|
|
| 317 | + if ($request->getMethod() === 'GET') { |
|
| 319 | 318 | return new TemplateResponse( |
| 320 | 319 | $this->template, |
| 321 | 320 | $templateName, |
@@ -324,7 +323,7 @@ discard block |
||
| 324 | 323 | } |
| 325 | 324 | |
| 326 | 325 | $validator = new $this->validatorClass($formParam, $this->lang); |
| 327 | - if ($validator->validate() === false) {
|
|
| 326 | + if ($validator->validate() === false) { |
|
| 328 | 327 | $context['errors'] = $validator->getErrors(); |
| 329 | 328 | |
| 330 | 329 | return new TemplateResponse( |
@@ -334,13 +333,13 @@ discard block |
||
| 334 | 333 | ); |
| 335 | 334 | } |
| 336 | 335 | |
| 337 | - if (count($this->uniqueFields) > 0) {
|
|
| 336 | + if (count($this->uniqueFields) > 0) { |
|
| 338 | 337 | $entityExist = $this->repository->findBy($this->getEntityFields( |
| 339 | 338 | $this->uniqueFields, |
| 340 | 339 | $formParam |
| 341 | 340 | )); |
| 342 | 341 | |
| 343 | - if ($entityExist !== null) {
|
|
| 342 | + if ($entityExist !== null) { |
|
| 344 | 343 | $this->flash->setError($this->lang->tr($this->messageDuplicate)); |
| 345 | 344 | |
| 346 | 345 | return new TemplateResponse( |
@@ -356,7 +355,7 @@ discard block |
||
| 356 | 355 | $this->fields, |
| 357 | 356 | $formParam |
| 358 | 357 | )); |
| 359 | - try {
|
|
| 358 | + try { |
|
| 360 | 359 | $this->repository->save($entity); |
| 361 | 360 | |
| 362 | 361 | $this->flash->setSuccess($this->lang->tr($this->messageCreate)); |
@@ -364,7 +363,7 @@ discard block |
||
| 364 | 363 | return new RedirectResponse( |
| 365 | 364 | $this->routeHelper->generateUrl($routeListName) |
| 366 | 365 | ); |
| 367 | - } catch (Exception $ex) {
|
|
| 366 | + } catch (Exception $ex) { |
|
| 368 | 367 | $this->logger->error('Error when saved the data {error}', ['error' => $ex->getMessage()]);
|
| 369 | 368 | |
| 370 | 369 | $this->flash->setError($this->lang->tr($this->messageProcessError)); |
@@ -394,7 +393,7 @@ discard block |
||
| 394 | 393 | /** @var TEntity|null $entity */ |
| 395 | 394 | $entity = $this->repository->find($id); |
| 396 | 395 | |
| 397 | - if ($entity === null) {
|
|
| 396 | + if ($entity === null) { |
|
| 398 | 397 | $this->flash->setError($this->lang->tr($this->messageNotFound)); |
| 399 | 398 | |
| 400 | 399 | return new RedirectResponse( |
@@ -403,7 +402,7 @@ discard block |
||
| 403 | 402 | } |
| 404 | 403 | $context[$this->entityContextName] = $entity; |
| 405 | 404 | $context['param'] = (new $this->paramClass())->fromEntity($entity); |
| 406 | - if ($request->getMethod() === 'GET') {
|
|
| 405 | + if ($request->getMethod() === 'GET') { |
|
| 407 | 406 | return new TemplateResponse( |
| 408 | 407 | $this->template, |
| 409 | 408 | $templateName, |
@@ -414,7 +413,7 @@ discard block |
||
| 414 | 413 | $context['param'] = $formParam; |
| 415 | 414 | |
| 416 | 415 | $validator = new $this->validatorClass($formParam, $this->lang); |
| 417 | - if ($validator->validate() === false) {
|
|
| 416 | + if ($validator->validate() === false) { |
|
| 418 | 417 | $context['errors'] = $validator->getErrors(); |
| 419 | 418 | |
| 420 | 419 | return new TemplateResponse( |
@@ -424,13 +423,13 @@ discard block |
||
| 424 | 423 | ); |
| 425 | 424 | } |
| 426 | 425 | |
| 427 | - if (count($this->uniqueFields) > 0) {
|
|
| 426 | + if (count($this->uniqueFields) > 0) { |
|
| 428 | 427 | $entityExist = $this->repository->findBy($this->getEntityFields( |
| 429 | 428 | $this->uniqueFields, |
| 430 | 429 | $formParam |
| 431 | 430 | )); |
| 432 | 431 | |
| 433 | - if ($entityExist !== null && $entityExist->id !== $id) {
|
|
| 432 | + if ($entityExist !== null && $entityExist->id !== $id) { |
|
| 434 | 433 | $this->flash->setError($this->lang->tr($this->messageDuplicate)); |
| 435 | 434 | |
| 436 | 435 | return new TemplateResponse( |
@@ -442,10 +441,10 @@ discard block |
||
| 442 | 441 | } |
| 443 | 442 | |
| 444 | 443 | $fields = $this->getEntityFields($this->fields, $formParam); |
| 445 | - foreach ($fields as $field => $value) {
|
|
| 444 | + foreach ($fields as $field => $value) { |
|
| 446 | 445 | $entity->{$field} = $value;
|
| 447 | 446 | } |
| 448 | - try {
|
|
| 447 | + try { |
|
| 449 | 448 | $this->repository->save($entity); |
| 450 | 449 | |
| 451 | 450 | $this->flash->setSuccess($this->lang->tr($this->messageUpdate)); |
@@ -453,7 +452,7 @@ discard block |
||
| 453 | 452 | return new RedirectResponse( |
| 454 | 453 | $this->routeHelper->generateUrl($routeListName) |
| 455 | 454 | ); |
| 456 | - } catch (Exception $ex) {
|
|
| 455 | + } catch (Exception $ex) { |
|
| 457 | 456 | $this->logger->error('Error when saved the data {error}', ['error' => $ex->getMessage()]);
|
| 458 | 457 | |
| 459 | 458 | $this->flash->setError($this->lang->tr($this->messageProcessError)); |
@@ -479,7 +478,7 @@ discard block |
||
| 479 | 478 | /** @var TEntity|null $entity */ |
| 480 | 479 | $entity = $this->repository->find($id); |
| 481 | 480 | |
| 482 | - if ($entity === null) {
|
|
| 481 | + if ($entity === null) { |
|
| 483 | 482 | $this->flash->setError($this->lang->tr($this->messageNotFound)); |
| 484 | 483 | |
| 485 | 484 | return new RedirectResponse( |
@@ -487,7 +486,7 @@ discard block |
||
| 487 | 486 | ); |
| 488 | 487 | } |
| 489 | 488 | |
| 490 | - try {
|
|
| 489 | + try { |
|
| 491 | 490 | $this->repository->delete($entity); |
| 492 | 491 | |
| 493 | 492 | $this->flash->setSuccess($this->lang->tr($this->messageDelete)); |
@@ -495,7 +494,7 @@ discard block |
||
| 495 | 494 | return new RedirectResponse( |
| 496 | 495 | $this->routeHelper->generateUrl($routeListName) |
| 497 | 496 | ); |
| 498 | - } catch (Exception $ex) {
|
|
| 497 | + } catch (Exception $ex) { |
|
| 499 | 498 | $this->logger->error('Error when delete the data {error}', ['error' => $ex->getMessage()]);
|
| 500 | 499 | |
| 501 | 500 | $this->flash->setError($this->lang->tr($this->messageProcessError)); |
@@ -516,8 +515,8 @@ discard block |
||
| 516 | 515 | {
|
| 517 | 516 | $results = []; |
| 518 | 517 | |
| 519 | - foreach ($fields as $field => $paramName) {
|
|
| 520 | - if (is_int($field)) {
|
|
| 518 | + foreach ($fields as $field => $paramName) { |
|
| 519 | + if (is_int($field)) { |
|
| 521 | 520 | $field = $paramName; |
| 522 | 521 | } |
| 523 | 522 | |
@@ -54,8 +54,7 @@ |
||
| 54 | 54 | * @class EmitterInterface |
| 55 | 55 | * @package Platine\Framework\Http\Emitter |
| 56 | 56 | */ |
| 57 | -interface EmitterInterface |
|
| 58 | -{
|
|
| 57 | +interface EmitterInterface { |
|
| 59 | 58 | /** |
| 60 | 59 | * Emits a HTTP response, that including status line, headers and message |
| 61 | 60 | * body, according to the environment. |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | * @class ResponseEmitter |
| 59 | 59 | * @package Platine\Framework\Http\Emitter |
| 60 | 60 | */ |
| 61 | -class ResponseEmitter implements EmitterInterface |
|
| 62 | -{
|
|
| 61 | +class ResponseEmitter implements EmitterInterface { |
|
| 63 | 62 | /** |
| 64 | 63 | * The response buffer length |
| 65 | 64 | * @var int|null |
@@ -70,9 +69,8 @@ discard block |
||
| 70 | 69 | * Create new instance |
| 71 | 70 | * @param int|null $bufferLength |
| 72 | 71 | */ |
| 73 | - public function __construct(?int $bufferLength = null) |
|
| 74 | - {
|
|
| 75 | - if ($bufferLength !== null && $bufferLength < 1) {
|
|
| 72 | + public function __construct(?int $bufferLength = null) { |
|
| 73 | + if ($bufferLength !== null && $bufferLength < 1) { |
|
| 76 | 74 | throw new InvalidArgumentException(sprintf( |
| 77 | 75 | 'The response buffer length must be greater than zero; received [%d].', |
| 78 | 76 | $bufferLength |
@@ -87,18 +85,18 @@ discard block |
||
| 87 | 85 | */ |
| 88 | 86 | public function emit(ResponseInterface $response, bool $withBody = true): void |
| 89 | 87 | {
|
| 90 | - if (headers_sent()) {
|
|
| 88 | + if (headers_sent()) { |
|
| 91 | 89 | throw HeadersAlreadySentException::create(); |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | - if (ob_get_level() > 0 && ob_get_length() > 0) {
|
|
| 92 | + if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 95 | 93 | throw OutputAlreadySentException::create(); |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | $this->emitHeaders($response); |
| 99 | 97 | $this->emitStatusLine($response); |
| 100 | 98 | |
| 101 | - if ($withBody && $response->getBody()->isReadable()) {
|
|
| 99 | + if ($withBody && $response->getBody()->isReadable()) { |
|
| 102 | 100 | $this->emitBody($response); |
| 103 | 101 | } |
| 104 | 102 | } |
@@ -110,7 +108,7 @@ discard block |
||
| 110 | 108 | */ |
| 111 | 109 | protected function emitHeaders(ResponseInterface $response): void |
| 112 | 110 | {
|
| 113 | - foreach ($response->getHeaders() as $name => $values) {
|
|
| 111 | + foreach ($response->getHeaders() as $name => $values) { |
|
| 114 | 112 | $name = str_replace( |
| 115 | 113 | ' ', |
| 116 | 114 | '-', |
@@ -118,7 +116,7 @@ discard block |
||
| 118 | 116 | ); |
| 119 | 117 | |
| 120 | 118 | $isFirst = $name !== 'Set-Cookie'; |
| 121 | - foreach ($values as $value) {
|
|
| 119 | + foreach ($values as $value) { |
|
| 122 | 120 | $header = sprintf('%s: %s', $name, $value);
|
| 123 | 121 | header($header, $isFirst); |
| 124 | 122 | $isFirst = false; |
@@ -148,7 +146,7 @@ discard block |
||
| 148 | 146 | */ |
| 149 | 147 | protected function emitBody(ResponseInterface $response): void |
| 150 | 148 | {
|
| 151 | - if ($this->bufferLength === null) {
|
|
| 149 | + if ($this->bufferLength === null) { |
|
| 152 | 150 | echo $response->getBody(); |
| 153 | 151 | return; |
| 154 | 152 | } |
@@ -159,16 +157,16 @@ discard block |
||
| 159 | 157 | $response->getHeaderLine('content-range')
|
| 160 | 158 | ); |
| 161 | 159 | |
| 162 | - if (isset($range['unit']) && $range['unit'] === 'bytes') {
|
|
| 160 | + if (isset($range['unit']) && $range['unit'] === 'bytes') { |
|
| 163 | 161 | $this->emitBodyRange($body, $range['first'], $range['last']); |
| 164 | 162 | return; |
| 165 | 163 | } |
| 166 | 164 | |
| 167 | - if ($body->isSeekable()) {
|
|
| 165 | + if ($body->isSeekable()) { |
|
| 168 | 166 | $body->rewind(); |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | - while (!$body->eof()) {
|
|
| 169 | + while (!$body->eof()) { |
|
| 172 | 170 | echo $body->read($this->bufferLength); |
| 173 | 171 | } |
| 174 | 172 | } |
@@ -183,18 +181,18 @@ discard block |
||
| 183 | 181 | protected function emitBodyRange(StreamInterface $body, int $first, int $last): void |
| 184 | 182 | {
|
| 185 | 183 | $length = $last - $first + 1; |
| 186 | - if ($body->isSeekable()) {
|
|
| 184 | + if ($body->isSeekable()) { |
|
| 187 | 185 | $body->seek($first); |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | - while ($length >= $this->bufferLength && !$body->eof()) {
|
|
| 188 | + while ($length >= $this->bufferLength && !$body->eof()) { |
|
| 191 | 189 | $contents = $body->read((int) $this->bufferLength); |
| 192 | 190 | $length -= strlen($contents); |
| 193 | 191 | |
| 194 | 192 | echo $contents; |
| 195 | 193 | } |
| 196 | 194 | |
| 197 | - if ($length > 0 && !$body->eof()) {
|
|
| 195 | + if ($length > 0 && !$body->eof()) { |
|
| 198 | 196 | echo $body->read($length); |
| 199 | 197 | } |
| 200 | 198 | } |
@@ -214,7 +212,7 @@ discard block |
||
| 214 | 212 | $header, |
| 215 | 213 | $matches |
| 216 | 214 | ) |
| 217 | - ) {
|
|
| 215 | + ) { |
|
| 218 | 216 | return [ |
| 219 | 217 | 'unit' => $matches['unit'], |
| 220 | 218 | 'first' => (int) $matches['first'], |
@@ -40,8 +40,7 @@ |
||
| 40 | 40 | * @class OutputAlreadySentException |
| 41 | 41 | * @package Platine\Http\Framework\Emitter\Exception |
| 42 | 42 | */ |
| 43 | -class OutputAlreadySentException extends RuntimeException |
|
| 44 | -{
|
|
| 43 | +class OutputAlreadySentException extends RuntimeException { |
|
| 45 | 44 | /** |
| 46 | 45 | * Create new instance |
| 47 | 46 | * @return self |
@@ -40,8 +40,7 @@ |
||
| 40 | 40 | * @class HeadersAlreadySentException |
| 41 | 41 | * @package Platine\Framework\Http\Emitter\Exception |
| 42 | 42 | */ |
| 43 | -class HeadersAlreadySentException extends RuntimeException |
|
| 44 | -{
|
|
| 43 | +class HeadersAlreadySentException extends RuntimeException { |
|
| 45 | 44 | /** |
| 46 | 45 | * Create new instance |
| 47 | 46 | * @return self |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | * @package Platine\Framework\Http\Maintenance\Driver |
| 57 | 57 | * @template T |
| 58 | 58 | */ |
| 59 | -class FileMaintenanceDriver implements MaintenanceDriverInterface |
|
| 60 | -{
|
|
| 59 | +class FileMaintenanceDriver implements MaintenanceDriverInterface { |
|
| 61 | 60 | /** |
| 62 | 61 | * The application configuration |
| 63 | 62 | * @var Config<T> |
@@ -75,8 +74,7 @@ discard block |
||
| 75 | 74 | * @param Config<T> $config |
| 76 | 75 | * @param Filesystem $filesystem |
| 77 | 76 | */ |
| 78 | - public function __construct(Config $config, Filesystem $filesystem) |
|
| 79 | - {
|
|
| 77 | + public function __construct(Config $config, Filesystem $filesystem) { |
|
| 80 | 78 | $this->config = $config; |
| 81 | 79 | $this->filesystem = $filesystem; |
| 82 | 80 | } |
@@ -107,7 +105,7 @@ discard block |
||
| 107 | 105 | */ |
| 108 | 106 | public function deactivate(): void |
| 109 | 107 | {
|
| 110 | - if ($this->active()) {
|
|
| 108 | + if ($this->active()) { |
|
| 111 | 109 | $path = $this->getFilePath(); |
| 112 | 110 | $this->filesystem->file($path)->delete(); |
| 113 | 111 | } |