{"id":21467406,"url":"https://github.com/elusivecodes/fyreserver","last_synced_at":"2025-07-15T05:31:29.388Z","repository":{"id":62508438,"uuid":"441643357","full_name":"elusivecodes/FyreServer","owner":"elusivecodes","description":"FyreServer is a free, open-source server request/response library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-17T00:22:24.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-17T01:08:19.681Z","etag":null,"topics":["php","request","response","server","upload"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-25T09:11:35.000Z","updated_at":"2024-11-17T00:21:46.000Z","dependencies_parsed_at":"2024-04-30T07:41:50.649Z","dependency_job_id":"0ba0eb1f-e6d2-4894-90a6-4f1e6957a586","html_url":"https://github.com/elusivecodes/FyreServer","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreServer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017466,"owners_count":17560515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","request","response","server","upload"],"created_at":"2024-11-23T08:17:53.899Z","updated_at":"2025-07-15T05:31:29.362Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreServer\r\n\r\n**FyreServer** is a free, open-source immutable HTTP server request/response library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Server Requests](#server-requests)\r\n- [Client Responses](#client-responses)\r\n- [Download Responses](#download-responses)\r\n- [Redirect Responses](#redirect-responses)\r\n- [Uploaded Files](#uploaded-files)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/server\r\n```\r\n\r\n\r\n## Server Requests\r\n\r\nThis class extends the [*Request*](https://github.com/elusivecodes/FyreRequest) class.\r\n\r\n```php\r\nuse Fyre\\Server\\ServerRequest;\r\n```\r\n\r\n- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n- `$typeParser` is a [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser).\r\n- `$options` is an array containing configuration options.\r\n    - `method` is a string representing the request method, and will default to the server request method.\r\n    - `body` is a string representing the request body, and will default to the value of `php://input`.\r\n    - `headers` is an array containing headers to set, and will default to the server headers.\r\n    - `protocolVersion` is a string representing the protocol version, and will default to \"*1.1*\".\r\n\r\n```php\r\n$request = new ServerRequest($config, $typeParser, $options);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*App*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `baseUri` is a string representing the base URI to use, and will default to \"\".\r\n    - `defaultLocale` is a string representing the default locale, and will default to the system default.\r\n    - `supportedLocales` is an array containing the supported locales, and will default to `[]`.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('App', $options);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *ServerRequest* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(ServerRequest::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$request = $container-\u003euse(ServerRequest::class);\r\n```\r\n\r\n### Server Request Methods\r\n\r\n**Get Cookie**\r\n\r\nGet a value from the `$_COOKIE` array.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetCookie($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetCookie();\r\n```\r\n\r\n**Get Data**\r\n\r\nGet a value from the `$_POST` array or JSON body data.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetData($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetData();\r\n```\r\n\r\n**Get Default Locale**\r\n\r\nGet the default locale.\r\n\r\n```php\r\n$defaultLocale = $request-\u003egetDefaultLocale();\r\n```\r\n\r\n**Get Environment**\r\n\r\nGet a value from the `$_ENV` array.\r\n\r\n- `$key` is a string representing the array key.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetEnv($key, $as);\r\n```\r\n\r\n**Get File**\r\n\r\nGet an *UploadedFile* or array of files from the `$_FILE` array.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n\r\n```php\r\n$file = $request-\u003egetFile($key);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all files.\r\n\r\n```php\r\n$files = $request-\u003egetFile();\r\n```\r\n\r\n**Get Json**\r\n\r\nGet a value from JSON body data.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetJson($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetJson();\r\n```\r\n\r\n**Get Locale**\r\n\r\nGet the current locale.\r\n\r\n```php\r\n$locale = $request-\u003egetLocale();\r\n```\r\n\r\n**Get Post**\r\n\r\nGet a value from the `$_POST` array.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetPost($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetPost();\r\n```\r\n\r\n**Get Query**\r\n\r\nGet a value from the `$_GET` array.\r\n\r\n- `$key` is a string representing the array key using \"dot\" notation.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetQuery($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetQuery();\r\n```\r\n\r\n**Get Server**\r\n\r\nGet a value from the `$_SERVER` array.\r\n\r\n- `$key` is a string representing the array key.\r\n- `$as` is a string representing the value type, and will default to *null*.\r\n\r\n```php\r\n$value = $request-\u003egetServer($key, $as);\r\n```\r\n\r\nIf the `$key` argument is omitted, this method will return an array containing all values.\r\n\r\n```php\r\n$values = $request-\u003egetServer();\r\n```\r\n\r\n**Get User Agent**\r\n\r\nGet the user agent.\r\n\r\n```php\r\n$userAgent = $request-\u003egetUserAgent();\r\n```\r\n\r\nThis method will return a [*UserAgent*](https://github.com/elusivecodes/FyreUserAgent).\r\n\r\n**Is AJAX**\r\n\r\nDetermine whether the request was made using AJAX.\r\n\r\n```php\r\n$isAjax = $request-\u003eisAjax();\r\n```\r\n\r\n**Is CLI**\r\n\r\nDetermine whether the request was made from the CLI.\r\n\r\n```php\r\n$isCli = $request-\u003eisCli();\r\n```\r\n\r\n**Is Secure**\r\n\r\nDetermine whether the request is using HTTPS.\r\n\r\n```php\r\n$isSecure = $request-\u003eisSecure();\r\n```\r\n\r\n**Negotiate**\r\n\r\nNegotiate a value from HTTP headers.\r\n\r\n- `$type` is a string representing the type of negotiation to perform, and must be one of either \"*content*\", \"*encoding*\" or \"*language*\".\r\n- `$supported` is an array containing the supported values.\r\n- `$strict` is a boolean indicating whether to not use a default fallback, and will default to *false*.\r\n\r\n```php\r\n$value = $request-\u003enegotiate($type, $supported, $strict);\r\n```\r\n\r\n**Set Locale**\r\n\r\nSet the current locale.\r\n\r\n- `$locale` is a string representing the locale.\r\n\r\n```php\r\n$newRequest = $request-\u003esetLocale($locale);\r\n```\r\n\r\nThe locale must be present in the `supportedLocales` property of the *ServerRequest* `$options` parameter.\r\n\r\n\r\n## Client Responses\r\n\r\nThis class extends the [*Response*](https://github.com/elusivecodes/FyreResponse) class.\r\n\r\n```php\r\nuse Fyre\\Server\\ClientResponse;\r\n```\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `body` is a string representing the message body, and will default to \"\".\r\n    - `headers` is an array containing additional headers to set.\r\n    - `protocolVersion` is a string representing the protocol version, and will default to \"*1.1*\".\r\n    - `statusCode` is a number representing the status code, and will default to *200*.\r\n\r\n```php\r\n$response = new ClientResponse($options);\r\n```\r\n\r\n**Delete Cookie**\r\n\r\n- `$name` is a string representing the cookie name.\r\n- `$options` is an array containing cookie options.\r\n    - `domain` is a string representing the cookie domain, and will default to \"\".\r\n    - `path` is a string representing the cookie path, and will default to \"*/*\".\r\n    - `secure` is a boolean indicating whether to set a secure cookie, and will default to *false*.\r\n    - `httpOnly` is a boolean indicating whether to the cookie should be HTTP only, and will default to *false*.\r\n    - `sameSite` is a string representing the cookie same site, and will default to \"*Lax*\".\r\n\r\n```php\r\n$newResponse = $response-\u003edeleteCookie($name, $options);\r\n```\r\n\r\n**Get Cookie**\r\n\r\n- `$name` is a string representing the cookie name.\r\n\r\n```php\r\n$cookie = $response-\u003egetCookie($name);\r\n```\r\n\r\nThis method will return a [*Cookie*](https://github.com/elusivecodes/FyreCookie).\r\n\r\n**Has Cookie**\r\n\r\nDetermine whether a cookie has been set.\r\n\r\n- `$name` is a string representing the cookie name.\r\n\r\n```php\r\n$hasCookie = $response-\u003ehasCookie($name);\r\n```\r\n\r\n**No Cache**\r\n\r\nSet headers to prevent browser caching.\r\n\r\n```php\r\n$newResponse = $response-\u003enoCache();\r\n```\r\n\r\n**Send**\r\n\r\nSend the response to the client.\r\n\r\n```php\r\n$response-\u003esend();\r\n```\r\n\r\n**Set Content Type**\r\n\r\nSet the content type header\r\n\r\n- `$mimeType` is a string representing the MIME type.\r\n- `$charset` is a string representing the character set, and will default to \"*UTF-8*\".\r\n\r\n```php\r\n$newResponse = $response-\u003esetContentType($mimeType, $charset);\r\n```\r\n\r\n**Set Cookie**\r\n\r\nSet a cookie value.\r\n\r\n- `$name` is a string representing the cookie name.\r\n- `$value` is a string representing the cookie value.\r\n- `$options` is an array containing cookie options.\r\n    - `expires` is a number representing the cookie lifetime, and will default to *0*.\r\n    - `domain` is a string representing the cookie domain, and will default to \"\".\r\n    - `path` is a string representing the cookie path, and will default to \"*/*\".\r\n    - `secure` is a boolean indicating whether to set a secure cookie, and will default to *false*.\r\n    - `httpOnly` is a boolean indicating whether to the cookie should be HTTP only, and will default to *false*.\r\n    - `sameSite` is a string representing the cookie same site, and will default to \"*Lax*\".\r\n\r\n```php\r\n$newResponse = $response-\u003esetCookie($name, $value, $options);\r\n```\r\n\r\n**Set Date**\r\n\r\nSet the date header.\r\n\r\n- `$date` is a string, number or *DateTime* object representing the date.\r\n\r\n```php\r\n$newResponse = $response-\u003esetDate($date);\r\n```\r\n\r\n**Set JSON**\r\n\r\nSet a JSON response.\r\n\r\n- `$data` is the data to send.\r\n\r\n```php\r\n$newResponse = $response-\u003esetJson($data);\r\n```\r\n\r\n**Set Last Modified**\r\n\r\nSet the last modified date header.\r\n\r\n- `$date` is a string, number or *DateTime* object representing the date.\r\n\r\n```php\r\n$newResponse = $response-\u003esetLastModified($date);\r\n```\r\n\r\n**Set XML**\r\n\r\nSet an XML response.\r\n\r\n- `$data` is a *SimpleXMLElement* containing the data to send.\r\n\r\n```php\r\n$newResponse = $response-\u003esetXml($data);\r\n```\r\n\r\n\r\n## Download Responses\r\n\r\nThis class extends the [*ClientResponse*](#client-responses) class.\r\n\r\n```php\r\nuse Fyre\\Server\\DownloadResponse;\r\n```\r\n\r\n- `$path` is a string representing the file path.\r\n- `$options` is an array containing configuration options.\r\n    - `filename` is a string representing the download filename, and will default to the file name.\r\n    - `mimeType` is a string representing the MIME type, and will default to the file MIME type.\r\n    - `headers` is an array containing additional headers to set.\r\n    - `protocolVersion` is a string representing the protocol version, and will default to \"*1.1*\".\r\n    - `statusCode` is a number representing the status code, and will default to *200*.\r\n\r\n```php\r\n$response = new DownloadResponse($path, $options);\r\n```\r\n\r\n**From Binary**\r\n\r\n- `$data` is a string representing the file data.\r\n- `$options` is an array containing configuration options.\r\n    - `filename` is a string representing the download filename, and will default to the file name.\r\n    - `mimeType` is a string representing the MIME type, and will default to the file MIME type.\r\n\r\n```php\r\n$response = DownloadResponse::fromBinary($data, $options);\r\n```\r\n\r\n**Get File**\r\n\r\nGet the download [*File*](https://github.com/elusivecodes/FyreFileSystem#files).\r\n\r\n```php\r\n$file = $response-\u003egetFile();\r\n```\r\n\r\n\r\n## Redirect Responses\r\n\r\nThis class extends the [*ClientResponse*](#client-responses) class.\r\n\r\n```php\r\nuse Fyre\\Server\\RedirectResponse;\r\n```\r\n\r\n- `$uri` is a [*Uri*](https://github.com/elusivecodes/FyreURI) or string representing the URI to redirect to.\r\n- `$code` is a number representing the header status code, and will default to *302*.\r\n- `$options` is an array containing configuration options.\r\n\r\n```php\r\n$response = new RedirectResponse($uri, $code $options);\r\n```\r\n\r\n\r\n## Uploaded Files\r\n\r\nThis class extends the [*File*](https://github.com/elusivecodes/FyreFileSystem#files) class.\r\n\r\n**Client Extension**\r\n\r\nGet the client extension.\r\n\r\n```php\r\n$extension = $uploadedFile-\u003eclientExtension();\r\n```\r\n\r\n**Client MIME Type**\r\n\r\nGet the client MIME type.\r\n\r\n```php\r\n$mimeType = $uploadedFile-\u003eclientMimeType();\r\n```\r\n\r\n**Client Name**\r\n\r\nGet the client filename.\r\n\r\n```php\r\n$name = $uploadedFile-\u003eclientName();\r\n```\r\n\r\n**Error**\r\n\r\nGet the uploaded error code.\r\n\r\n```php\r\n$error = $uploadedFile-\u003eerror();\r\n```\r\n\r\n**Has Moved**\r\n\r\nDetermine whether the uploaded file has been moved.\r\n\r\n```php\r\n$hasMoved = $uploadedFile-\u003ehasMoved();\r\n```\r\n\r\n**Is Valid**\r\n\r\nDetermine whether the uploaded file is valid.\r\n\r\n```php\r\n$isValid = $uploadedFile-\u003eisValid();\r\n```\r\n\r\n**Move To**\r\n\r\nMove the uploaded file.\r\n\r\n- `$destination` is string representing the destination folder.\r\n- `$name` is a string representing the new filename, and will default to the client name.\r\n\r\n```php\r\n$file = $uploadedFile-\u003emoveTo($destination, $name);\r\n```\r\n\r\nThis method will return a new [*File*](https://github.com/elusivecodes/FyreFileSystem#files) for the moved file.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyreserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreserver/lists"}