Download the PHP package componenta/http-responder without Composer

On this page you can find all versions of the php package componenta/http-responder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-responder

Componenta HTTP Responder

Response builder for PSR-7 HTTP responses. The package centralizes common response creation: JSON, text, HTML, redirects, downloads, inline files, error responses, and cache headers.

Use this package in controllers, route handlers, and middleware that need to create responses without depending on a concrete PSR-7 implementation.

Boundary

This package only builds PSR-7 responses. It does not emit responses, does not create server requests, and does not choose a PSR-7 implementation. Use componenta/http-emitter to send responses and one of the componenta/http-psr-* packages to register PSR-17 factories.

Installation

The package declares Componenta\Http\ResponderConfigProvider in extra.componenta.config-providers. When componenta/composer-plugin is installed, the provider is added to the generated provider list automatically.

Register one PSR-17 implementation package, for example componenta/http-psr-nyholm, so the container has response and stream factories.

Configuration

ResponderConfigProvider registers Responder from:

Dependency Purpose
ResponseFactoryInterface Creates PSR-7 responses.
StreamFactoryInterface Creates body streams.

The provider also includes the mime type detector provider for file responses.

Main API

Responder is the consumer-facing service. It can either infer a response from arbitrary content or create a specific response type explicitly.

Content responses

Method Purpose
respond(?int $code = null, mixed $content = null, ?string $contentType = null) Builds a response from null, ResponseInterface, StreamInterface, string, array, JsonSerializable, Arrayable, Stringable, or a stream resource.
empty(int $status = 204) Creates an empty response.
text(string $content, int $status = 200) Creates a text/plain; charset=utf-8 response.
html(string $content, int $status = 200) Creates a text/html; charset=utf-8 response.
xml(string $content, int $status = 200) Creates an application/xml; charset=utf-8 response.
json(mixed $data, int $status = 200, int $flags = ...) JSON-encodes data with JSON_THROW_ON_ERROR, JSON_UNESCAPED_UNICODE, and JSON_UNESCAPED_SLASHES by default.
jsonp(mixed $data, string $callback, int $status = 200) Creates a JavaScript callback response after validating the callback name.

When respond() receives status 204 or 304, it returns an empty response even if content is supplied.

Redirects

Method Status
redirect(string $url, int $status = 302) Custom redirect status.
movedPermanently(string $url) 301
found(string $url) 302
seeOther(string $url) 303
temporaryRedirect(string $url) 307
permanentRedirect(string $url) 308
back(?string $referer, string $fallback = '/') 302 to the referrer or fallback URL.

Redirect URLs are trimmed and rejected when empty or when they contain control characters.

Files

download() and inline() accept a StreamInterface, stream resource, or string content. downloadFile() and inlineFile() read from an absolute filesystem path and auto-detect the content type from the stream when possible.

Method Purpose
download() / downloadFile() Builds Content-Disposition: attachment responses.
inline() / inlineFile() Builds Content-Disposition: inline responses.
file() / fileFromPath() Lower-level file response helpers with an explicit disposition.
xAccelRedirect() Header-only response for nginx internal file serving.
xSendfile() Header-only response for Apache mod_xsendfile.

Error and conditional responses

Convenience methods are available for common HTTP statuses: badRequest(), unauthorized(), forbidden(), notFound(), methodNotAllowed(), conflict(), gone(), unprocessableEntity(), tooManyRequests(), serverError(), notImplemented(), serviceUnavailable(), notModified(), preconditionFailed(), and rangeNotSatisfiable().

unauthorized() can add WWW-Authenticate; tooManyRequests() and serviceUnavailable() can add Retry-After.

Cache headers

Use withCache(), withNoCache(), withEtag(), and withLastModified() to add cache-related headers to an existing response. The methods return a modified PSR-7 response and do not mutate the original instance.

Errors

The responder throws InvalidArgumentException when it receives unsupported content, invalid status codes, invalid redirect or header values, unreadable files, invalid filenames, invalid cache values, or invalid JSONP callback names.


All versions of http-responder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
componenta/arrayable Version ^1.0
componenta/config Version ^3.0.0
componenta/mimetype-detector Version ^1.0
psr/container Version ^2.0
psr/http-message Version ^2.0
psr/http-factory Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package componenta/http-responder contains the following files

Loading the files please wait ...