Download the PHP package incoming/incoming without Composer
On this page you can find all versions of the php package incoming/incoming. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download incoming/incoming
More information about incoming/incoming
Files in incoming/incoming
Package incoming
Short Description Transform loose and complex input into consistent, strongly-typed data structures
License MIT
Homepage https://github.com/Rican7/incoming
Informations about the package incoming
Incoming
Incoming is a PHP library designed to simplify and abstract the transformation of loose, complex input data into consistent, strongly-typed data structures.
Born out of inspiration from using Fractal, Incoming can be seen as a spiritual inversion. When working with data models of any kind (database, remote service, etc), it can be a huge pain to take raw input data and turn it into anything usable. Even worse is when something changes and you have to duplicate code or try and keep backwards compatibility. Incoming is here to make all this easier while enabling you to create more concern-separated, reusable, and testable code.
"Wait, what? Why not just use 'x' or 'y'?" Don't worry, I've got you covered.
Features
- Input filtering and transforming
- Built-in powerful, immutable data-structures for handling complex input
- Allows for automatic hydrator-for-model resolution via factory abstraction
- Makes strong use of interfaces for well structured, easily-testable code
- Completely configurable via composable units
Still curious? Check out the examples.
Installation
- Get Composer
- Add "incoming/incoming" to your dependencies:
composer require incoming/incoming
- Include the Composer autoloader
<?php require 'vendor/autoload.php';
Examples
The easiest example to relate to in the PHP world? "Form" or HTTP request data:
Sure, that's a pretty contrived example. But what kind of power can we gain when we compose some pieces together?
Let's try and filter our input first.
Missing type hints? PHP's type-system's restrictions can be circumvented!:
Immutable objects or objects with required data in the constructor? No problem!
Wait, what? Why not just use "x" or "y"?
Still not sold on the idea even with the provided examples? You may be thinking...
- "Why not just use
MyModelName::fromArray($data)
?" - "But my ORM already has a
$model->fill($data)
method..." - "I don't get it..."
Yea, sure, you could easily just build a model from a raw data array or just pass an array of attributes to a "fill"
method and hope that everything goes well, but there's a few issues with doing that: What happens when you refactor a
model or an underlying database table? Do you all of a sudden break backwards compatibility in an HTTP API's parameters
just because your table might have changed? What about if you want to prevent certain parameters from being changed in a
conditional manner? Do you just create a massive chunk of if
statements in a factory method of the model itself?
The idea with using Incoming is to separate concerns, create reusable and composable units, and really enrich an application's ability to create complex entities while providing a convenient API that rids of some of PHP's "gotchas".
After all, "magical" solutions like mass attribute assignment have had their pitfalls before. ;)
License
Incoming is proud to be MIT licensed.