fyre / server
A HTTP server request/response library.
Installs: 333
Dependents: 9
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/fyre/server
Requires
- fyre/array: ^3.0
- fyre/config: ^5.0
- fyre/cookie: ^5.0
- fyre/datetime: ^4.0
- fyre/macro: ^2.0
- fyre/negotiate: ^3.0
- fyre/request: ^4.0
- fyre/response: ^4.0
- fyre/typeparser: ^6.0
- fyre/useragent: ^3.0
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
- dev-main
- v5.0
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.0
- v4.0
- v3.3.5
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- v1.1.1
- v1.1.0
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0
This package is auto-updated.
Last update: 2025-11-11 12:13:20 UTC
README
FyreServer is a free, open-source immutable HTTP server request/response library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/server
Server Requests
This class extends the Request class.
use Fyre\Server\ServerRequest;
$configis a Config.$typeParseris a TypeParser.$optionsis an array containing configuration options.methodis a string representing the request method, and will default to the server request method.bodyis a string or StreamInterface representing the message body, and will default tophp://input.headersis an array containing headers to set, and will default to the server headers.protocolVersionis a string representing the protocol version, and will default to "1.1".
$request = new ServerRequest($config, $typeParser, $options);
Default configuration options will be resolved from the "App" key in the Config.
$optionsis an array containing configuration options.baseUriis a string representing the base URI to use, and will default to "".defaultLocaleis a string representing the default locale, and will default to the system default.supportedLocalesis an array containing the supported locales, and will default to[].
$container->use(Config::class)->set('App', $options);
Autoloading
It is recommended to bind the ServerRequest to the Container as a singleton.
$container->singleton(ServerRequest::class);
Any dependencies will be injected automatically when loading from the Container.
$request = $container->use(ServerRequest::class);
Server Request Methods
Get Attribute
Get an attribute from the request.
$keyis a string representing the attribute key.
$attribute = $request->getAttribute($key);
Get Attributes
Get all attributes from the request.
$attributes = $request->getAttributes();
Get Cookie
Get a value from the $_COOKIE array.
$keyis a string representing the array key using "dot" notation.$asis a string representing the value type, and will default to null.
$value = $request->getCookie($key, $as);
Get Cookie Params
Get the $_COOKIE array.
$values = $request->getCookieParams();
Get Data
Get a value from the $_POST array or parsed body data.
$keyis a string representing the array key using "dot" notation.$asis a string representing the value type, and will default to null.
$value = $request->getData($key, $as);
Get Default Locale
Get the default locale.
$defaultLocale = $request->getDefaultLocale();
Get Environment
Get a value from the $_ENV array.
$keyis a string representing the array key.$asis a string representing the value type, and will default to null.
$value = $request->getEnv($key, $as);
Get Locale
Get the current locale.
$locale = $request->getLocale();
Get Param
Get a route parameter.
$keyis a string representing the parameter key.
$param = $request->getParam();
Get Parsed Body
Get the parsed body data.
$values = $request->getParsedBody();
Get Query
Get a value from the $_GET array.
$keyis a string representing the array key using "dot" notation.$asis a string representing the value type, and will default to null.
$value = $request->getQuery($key, $as);
Get Query Params
Get the $_GET array.
$values = $request->getQueryParams();
Get Server
Get a value from the $_SERVER array.
$keyis a string representing the array key.$asis a string representing the value type, and will default to null.
$value = $request->getServer($key, $as);
Get Server Params
Get the $_SERVER array.
$values = $request->getServerParams();
Get Uploaded File
Get an UploadedFile or array of files from the $_FILE array.
$keyis a string representing the array key using "dot" notation.
$file = $request->getUploadedFile($key);
Get Uploaded Files
Get the uploaded files from the $_FILE array.
$files = $request->getUploadedFiles();
Get User Agent
Get the user agent.
$userAgent = $request->getUserAgent();
This method will return a UserAgent.
Is AJAX
Determine whether the request was made using AJAX.
$isAjax = $request->isAjax();
Is CLI
Determine whether the request was made from the CLI.
$isCli = $request->isCli();
Is Secure
Determine whether the request is using HTTPS.
$isSecure = $request->isSecure();
Negotiate
Negotiate a value from HTTP headers.
$typeis a string representing the type of negotiation to perform, and must be one of either "content", "encoding" or "language".$supportedis an array containing the supported values.$strictis a boolean indicating whether to not use a default fallback, and will default to false.
$value = $request->negotiate($type, $supported, $strict);
With Attribute
Clone the ServerRequest with a new attribute.
$keyis a string representing the attribute key.$valueis the attribute value.
$newRequest = $request->withAttribute($key, $value);
With Cookie Params
Clone the ServerRequest with new cookie parameters.
$datais an array containing the new cookie parameters.
$newRequest = $request->withCookieParams($data);
With Locale
Clone the ServerRequest with a new locale.
$localeis a string representing the locale.
$newRequest = $request->withLocale($locale);
The locale must be present in the supportedLocales property of the ServerRequest $options parameter.
Without Attribute
Clone the ServerRequest without an attribute.
$keyis a string representing the attribute key.
$newRequest = $request->withoutAttribute($key);
With Param
Clone the ServerRequest with new a new parameter.
$keyis a string representing the parameter key.$valueis the parameter value.
$newRequest = $request->withParam($key, $value);
With Parsed Body
Clone the ServerRequest with new a new parsed body.
$datais an array containing the new parsed body.
$newRequest = $request->withParsedData($data);
With Query Params
Clone the ServerRequest with new query parameters.
$datais an array containing the new query parameters.
$newRequest = $request->withQueryParams($data);
With Server Params
Clone the ServerRequest with new server parameters.
$datais an array containing the new server parameters.
$newRequest = $request->withServerParams($data);
With Uploaded Files
Clone the ServerRequest with new uploaded files.
$datais an array containing the new uploaded files.
$newRequest = $request->withUploadedFiles($data);
Client Responses
This class extends the Response class.
use Fyre\Server\ClientResponse;
$optionsis an array containing configuration options.bodyis a string or StreamInterface representing the message body, and will default to "".headersis an array containing additional headers to set.protocolVersionis a string representing the protocol version, and will default to "1.1".statusCodeis a number representing the status code, and will default to 200.
$response = new ClientResponse($options);
Get Cookie
$nameis a string representing the cookie name.
$cookie = $response->getCookie($name);
This method will return a Cookie.
Has Cookie
Determine whether a cookie has been set.
$nameis a string representing the cookie name.
$hasCookie = $response->hasCookie($name);
Send
Send the response to the client.
$response->send();
With Content Type
Clone the ClientResponse with a new content type.
$mimeTypeis a string representing the MIME type.$charsetis a string representing the character set, and will default to "UTF-8".
$newResponse = $response->withContentType($mimeType, $charset);
With Cookie
Clone the ClientResponse with a new cookie.
$nameis a string representing the cookie name.$valueis a string representing the cookie value.$optionsis an array containing cookie options.expiresis a number representing the cookie lifetime, and will default to 0.domainis a string representing the cookie domain, and will default to "".pathis a string representing the cookie path, and will default to "/".secureis a boolean indicating whether to set a secure cookie, and will default to false.httpOnlyis a boolean indicating whether to the cookie should be HTTP only, and will default to false.sameSiteis a string representing the cookie same site, and will default to "Lax".
$newResponse = $response->withCookie($name, $value, $options);
With Date
Clone the ClientResponse with a new date header.
$dateis a string, number or DateTime object representing the date.
$newResponse = $response->withDate($date);
With Disabled Cache
Clone the ClientResponse with disabled cache heades
$newResponse = $response->withDisabledCache();
With Expired Cookie
Clone the ClientResponse with a new expired cookie.
$nameis a string representing the cookie name.$optionsis an array containing cookie options.domainis a string representing the cookie domain, and will default to "".pathis a string representing the cookie path, and will default to "/".secureis a boolean indicating whether to set a secure cookie, and will default to false.httpOnlyis a boolean indicating whether to the cookie should be HTTP only, and will default to false.sameSiteis a string representing the cookie same site, and will default to "Lax".
$newResponse = $response->withExpiredCookie($name, $options);
With JSON
Clone the ClientResponse with a new JSON body.
$datais the data to send.
$newResponse = $response->withJson($data);
With Last Modified
Clone the ClientResponse with a new last modified date header.
$dateis a string, number or DateTime object representing the date.
$newResponse = $response->withLastModified($date);
With XML
Clone the ClientResponse with a new XML body.
$datais a SimpleXMLElement containing the data to send.
$newResponse = $response->withXml($data);
Download Responses
This class extends the ClientResponse class.
use Fyre\Server\DownloadResponse;
$pathis a string representing the file path.$optionsis an array containing configuration options.filenameis a string representing the download filename, and will default to the file name.mimeTypeis a string representing the MIME type, and will default to the file MIME type.headersis an array containing additional headers to set.protocolVersionis a string representing the protocol version, and will default to "1.1".statusCodeis a number representing the status code, and will default to 200.
$response = new DownloadResponse($path, $options);
Create From String
$datais a string representing the file data.$optionsis an array containing configuration options.filenameis a string representing the download filename, and will default to the file name.mimeTypeis a string representing the MIME type, and will default to the file MIME type.
$response = DownloadResponse::createFromString($data, $options);
Redirect Responses
This class extends the ClientResponse class.
use Fyre\Server\RedirectResponse;
$uriis a Uri or string representing the URI to redirect to.$codeis a number representing the header status code, and will default to 302.$optionsis an array containing configuration options.
$response = new RedirectResponse($uri, $code $options);
Uploaded Files
Get Client Filename
Get the client filename.
$filename = $uploadedFile->getClientFilename();
Get Client Media Type
Get the client media type.
$mediaType = $uploadedFile->getClientMediaType();
Get Error
Get the uploaded error code.
$error = $uploadedFile->getError();
Get Size
Get the uploaded file size.
$size = $uploadedFile->getSize();
Get Stream
Get a Stream representing the uploaded file.
$stream = $uploadedFile->getStream();
Move To
Move the uploaded file.
$targetPathis string representing the target path.
$uploadedFile->moveTo($targetPath);