Download the PHP package respect/fluent without Composer
On this page you can find all versions of the php package respect/fluent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fluent
Respect\Fluent
Build fluent interfaces from class namespaces. PHP 8.5+, zero dependencies.
Fluent maps method calls to class instances. You define classes in a namespace,
extend FluentBuilder, and get a chainable API where each call resolves a
class name, instantiates it, and accumulates it immutably.
Middlewares, validators, processors: anything that composes well as a chain can leverage Respect/Fluent.
Installation
Quick Start
1. Choose a namespace and interface
Fluent discovers classes from one or more namespaces. Giving them a shared interface lets your builder enforce type safety and expose domain methods.
2. Extend FluentBuilder
The #[FluentNamespace] attribute declares where your classes live and how to
resolve them. The builder inherits __call, immutable accumulation, and
withNamespace support, you only add domain logic:
The attribute carries the full factory configuration: the resolver (Ucfirst),
optional type constraint (Middleware::class), and namespace to search. The
inherited factoryFromAttribute() reads it at runtime so there's a single
source of truth.
Now MiddlewareStack::cors()->auth('bearer')->jsonBody() builds the
layers for you.
3. Add composition if you want
Prefix composition lets optionalAuth() create Optional(Auth()). You're
not limited to Optional cases, you can design nesting as deep as you want.
Annotate wrapper classes with #[Composable]:
Then switch the attribute to use ComposingLookup, it automatically discovers
#[Composable] prefixes from the same namespace:
Now MiddlewareStack::optionalAuth('bearer') creates Optional(Auth('bearer')).
4. Add custom namespaces
Users can extend your middleware stack with their own classes.
withNamespace is inherited from FluentBuilder:
How It Works
Fluent has three layers:
- Resolvers transform method names before lookup (e.g.,
'email'→'Email', or'notEmail'→ wrapper'Not'+ inner'Email'). - Factories search namespaces for the resolved class name and instantiate it.
- Builders (
Append,Prepend) chain factory calls immutably via__call.
Resolved classes are called nodes because consumer libraries (like Respect/Validation) often arrange them into tree structures.
A FluentNode carries the resolution state between resolvers and factories: a name, constructor arguments, and an optional wrapper.
NamespaceLookup vs ComposingLookup: use NamespaceLookup for simple
name-to-class mapping. Wrap it with ComposingLookup when you need prefix
composition like notEmail() → Not(Email()). Composition resolves a single
prefix level (e.g. notEmail, nullOrEmail); deeper nesting such as
notNullOrEmail is not decomposed.
Assurance attributes
Node classes can declare what they assure about their input via #[Assurance].
Assertion methods are marked with #[AssuranceAssertion], and #[AssuranceParameter]
identifies specific parameters. Constructor parameters for composition use
#[ComposableParameter]. Composable prefixes declare how they relate to the
wrapped node's subject with #[AssuranceSubject] (Wrap, Elements, or
Container).
This metadata is available at runtime through reflection and is also consumed by tools like FluentAnalysis for static type narrowing.
See Assurance, AssuranceParameter, ComposableParameter, and the enum
types in the API reference for the full set of options.
API Reference
See docs/api.md for the complete API reference covering attributes, builders, factories, resolvers, and exceptions.