You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Web/Sources/src/app/router/request/ContentStrategyFactory.php

23 lines
759 B

<?php
namespace App\Router\Request;
// should maybe change this
class ContentStrategyFactory {
private static $strategyMap = [
'application/json' => JsonContentStrategy::class,
// Format...
];
public static function createContentStrategy(string $contentType, string $requestMethod): ContentStrategy {
foreach (self::$strategyMap as $type => $className) {
if ($contentType === $type || in_array($requestMethod, ['PUT', 'PATCH', 'DELETE'])) {
return new $className();
}
}
return new FormContentStrategy();
}
public static function registerStrategy(string $contentType, string $className): void {
self::$strategyMap[$contentType] = $className;
}
}