aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/core/src/Http
diff options
context:
space:
mode:
authorMarvin Borner2018-06-08 20:03:25 +0200
committerMarvin Borner2018-06-08 20:03:25 +0200
commit92b7dd3335a6572debeacfb5faa82c63a5e67888 (patch)
tree7ebbca22595d542ec5e2912a24a0400ac8f6b113 /main/app/sprinkles/core/src/Http
parent22a1bb27f94ea33042b0bdd35bef1a5cfa96cc0d (diff)
Some minor fixes
Diffstat (limited to 'main/app/sprinkles/core/src/Http')
-rw-r--r--main/app/sprinkles/core/src/Http/Concerns/DeterminesContentType.php152
1 files changed, 76 insertions, 76 deletions
diff --git a/main/app/sprinkles/core/src/Http/Concerns/DeterminesContentType.php b/main/app/sprinkles/core/src/Http/Concerns/DeterminesContentType.php
index 06cf0b3..2a22331 100644
--- a/main/app/sprinkles/core/src/Http/Concerns/DeterminesContentType.php
+++ b/main/app/sprinkles/core/src/Http/Concerns/DeterminesContentType.php
@@ -1,76 +1,76 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Http\Concerns;
-
-use Psr\Http\Message\ServerRequestInterface;
-
-/**
- * Trait for classes that need to determine a request's accepted content type(s).
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-trait DeterminesContentType
-{
- /**
- * Known handled content types
- *
- * @var array
- */
- protected $knownContentTypes = [
- 'application/json',
- 'application/xml',
- 'text/xml',
- 'text/html',
- 'text/plain'
- ];
-
- /**
- * Determine which content type we know about is wanted using Accept header
- *
- * Note: This method is a bare-bones implementation designed specifically for
- * Slim's error handling requirements. Consider a fully-feature solution such
- * as willdurand/negotiation for any other situation.
- *
- * @param ServerRequestInterface $request
- * @return string
- */
- protected function determineContentType(ServerRequestInterface $request, $ajaxDebug = FALSE) {
- // For AJAX requests, if AJAX debugging is turned on, always return html
- if ($ajaxDebug && $request->isXhr()) {
- return 'text/html';
- }
-
- $acceptHeader = $request->getHeaderLine('Accept');
- $selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
- $count = count($selectedContentTypes);
-
- if ($count) {
- $current = current($selectedContentTypes);
-
- /**
- * Ensure other supported content types take precedence over text/plain
- * when multiple content types are provided via Accept header.
- */
- if ($current === 'text/plain' && $count > 1) {
- return next($selectedContentTypes);
- }
-
- return $current;
- }
-
- if (preg_match('/\+(json|xml)/', $acceptHeader, $matches)) {
- $mediaType = 'application/' . $matches[1];
- if (in_array($mediaType, $this->knownContentTypes)) {
- return $mediaType;
- }
- }
-
- return 'text/html';
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Http\Concerns;
+
+use Psr\Http\Message\ServerRequestInterface;
+
+/**
+ * Trait for classes that need to determine a request's accepted content type(s).
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+trait DeterminesContentType
+{
+ /**
+ * Known handled content types
+ *
+ * @var array
+ */
+ protected $knownContentTypes = [
+ 'application/json',
+ 'application/xml',
+ 'text/xml',
+ 'text/html',
+ 'text/plain'
+ ];
+
+ /**
+ * Determine which content type we know about is wanted using Accept header
+ *
+ * Note: This method is a bare-bones implementation designed specifically for
+ * Slim's error handling requirements. Consider a fully-feature solution such
+ * as willdurand/negotiation for any other situation.
+ *
+ * @param ServerRequestInterface $request
+ * @return string
+ */
+ protected function determineContentType(ServerRequestInterface $request, $ajaxDebug = FALSE) {
+ // For AJAX requests, if AJAX debugging is turned on, always return html
+ if ($ajaxDebug && $request->isXhr()) {
+ return 'text/html';
+ }
+
+ $acceptHeader = $request->getHeaderLine('Accept');
+ $selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
+ $count = count($selectedContentTypes);
+
+ if ($count) {
+ $current = current($selectedContentTypes);
+
+ /**
+ * Ensure other supported content types take precedence over text/plain
+ * when multiple content types are provided via Accept header.
+ */
+ if ($current === 'text/plain' && $count > 1) {
+ return next($selectedContentTypes);
+ }
+
+ return $current;
+ }
+
+ if (preg_match('/\+(json|xml)/', $acceptHeader, $matches)) {
+ $mediaType = 'application/' . $matches[1];
+ if (in_array($mediaType, $this->knownContentTypes)) {
+ return $mediaType;
+ }
+ }
+
+ return 'text/html';
+ }
+}