Download the PHP package tihloh/prefab-input without Composer

On this page you can find all versions of the php package tihloh/prefab-input. 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 prefab-input

Prefab Input

Prefab Input turns raw/untrusted PHP input into clean, normalized, typed, validated and deeply whitelisted application data.

Define exactly what your application accepts. Everything else stays outside the validated result.

It combines closely related input-boundary concerns:

Prefab Input is standalone. It does not require Routes, Database, Users, Auth, Permissions, Logs, Laravel, or another framework.

Requirements

Installation

When published:


1. Quick start

validated() contains only schema-declared fields that passed processing.


2. One input pipeline

Incoming values often need several steps before business logic:

Prefab Input handles this as one pipeline:


3. Schema as a whitelist

Suppose a client sends:

but the schema declares only:

Then:

returns only:

Undeclared client fields never become validated application data.


4. Compact and array schemas

Compact syntax:

Array syntax:

Array schemas can also contain callable validation rules.


5. Transformations and casting

Built-in operations include:

Operation Effect
trim Trim string whitespace
lowercase Lowercase a string
uppercase Uppercase a string
null_if_empty Convert '' to null
string Cast sensible scalar/stringable values
integer Cast a valid integer representation
float Cast numeric input to float
boolean Cast common boolean forms
array Keep arrays or wrap a scalar in an array

Example:

Validated output:

Invalid casts produce validation errors rather than silently pretending the requested type was produced.


6. Core validation rules

Built-in rules include:


7. Required, nullable, sometimes and defaults

nullable accepts an absent/null/empty value as null. sometimes ignores an absent field completely. default applies only when the field is absent.


8. Conditional validation

These rules also work inside wildcard rows when the referenced rule path uses the same wildcard positions.

Example:

For items.3.sku, Prefab compares items.3.type.


9. Nested input

Dot notation reads and writes nested arrays:

Validated output:


10. Array form inputs

PHP automatically converts HTML names such as:

into:

Process each item using *:


11. Repeated/nested rows with wildcards

HTML:

PHP produces:

Prefab schema:

Validated output:

Errors keep their concrete index:

Nested wildcards are also supported:


12. Deep whitelisting

Wildcard schemas do not copy undeclared fields from parent arrays.

Input:

Schema:

Validated output:

This makes nested client input safer to pass to application services or persistence.


13. Standard multipart forms

For normal PHP multipart/form-data requests, PHP already parses the protocol into $_POST and $_FILES.

Use:

or explicitly:

HTML:

Process it naturally:

Prefab does not reimplement the standard PHP multipart boundary parser. It normalizes PHP's already-parsed request data.


14. UploadedFile

Uploaded files become UploadedFile objects:

mime() detects MIME from temporary file contents using fileinfo; it does not simply trust the browser-provided MIME string.

UploadedFile represents temporary input only. Permanent storage is intentionally outside Prefab Input.


15. File rules

Examples:

Rules:

Rule Meaning
file Valid PHP upload
image Upload is a readable image
mimes:pdf,png Allowed extension plus detected MIME for supported formats
mimetypes:application/pdf,image/png Allowed detected MIME
min_size:1kb Minimum byte size
max_size:10mb Maximum byte size
dimensions:min_width=200,min_height=200 Image dimension limits

Supported size suffixes are b, kb, mb, and gb.

Dimension examples:


16. Multiple file uploads

HTML:

Prefab normalizes PHP's column-oriented $_FILES representation into:

Then:


17. Nested multipart rows

HTML can mix ordinary fields and files:

Schema:

$_POST and $_FILES are merged into one logical nested input tree before validation.


18. JSON requests

Input::fromRequest() detects Content-Type: application/json and reads php://input automatically:

Invalid JSON produces a clear exception instead of silently converting the request into empty data.

Raw multipart parsing for unusual non-standard request flows can later belong to an HTTP transport layer; Prefab Input remains focused on input normalization and validation.


19. Result object

process() returns InputResult:

Meaning:

Prefer validated() when passing request data into application services.


20. Friendly attributes and messages

Wildcard pattern messages/attributes apply to their concrete paths unless an even more specific concrete key is configured.


21. Custom rules

Custom rule callbacks receive field, current value, raw data, parsed parameters and existence state.

This is also the extension point for database-aware unique/exists behavior without making Prefab Database mandatory.


22. Inline callable rules

Return null when valid, or a non-empty error string when invalid.


23. Custom transformations

Custom transformers receive the current value, parameters, field name and raw data.


24. Database-aware rules without a hard dependency

A future Database adapter may provide reusable resolvers while the Input core stays database-independent.


25. Responsibility boundary

Prefab Input owns the incoming-data boundary:

It deliberately does not own permanent file storage, directories, cloud storage, public URLs, database persistence, HTTP responses, or routing.

A future file-storage package could consume UploadedFile without changing Input itself.


26. API quick reference

API Purpose
Input::from($data, $files = []) Build from explicit arrays
Input::fromRequest() Read normal PHP form/multipart or JSON request data
process() Normalize/cast/validate/whitelist using a schema
rule() Register a custom validation rule
transform() Register a custom transformer
attributes() Configure friendly field labels
messages() Configure validation messages
Input::normalizeFiles() Normalize PHP $_FILES manually

InputResult:

API Purpose
passes() / fails() Validation status
raw() Original input tree
all() Processed declared fields
validated() Safe validated output or one validated path
errors() Error bag
first() First error globally or for a field
value() Read a processed value by dot path

UploadedFile:

API Purpose
name() Original client filename
tmpPath() PHP temporary path
size() File size in bytes
extension() Original filename extension
mime() Content-detected MIME
error() PHP upload error code
isValid() Valid temporary upload state
isImage() Detect readable image
dimensions() Image width/height

27. Design philosophy

Prefab Input stays simple for ordinary forms:

The same API scales to large dynamic forms and APIs:

The core principle is: turn untrusted external data into predictable application data without forcing a framework or persistence layer.


All versions of prefab-input with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-fileinfo Version *
tihloh/prefab-core Version ^0.4 || ^0.5
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 tihloh/prefab-input contains the following files

Loading the files please wait ...