Download the PHP package pixelcone/fraction without Composer
On this page you can find all versions of the php package pixelcone/fraction. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pixelcone/fraction
More information about pixelcone/fraction
Files in pixelcone/fraction
Package fraction
Short Description A set of architecture abstractions to help you build structured and maintainable PHP apps
License
Informations about the package fraction
Fraction
Fraction is a set of abstractions offering PHP devs a convenient way of storing a business logic in their apps.
The idea for this package was born during the process of refactoring a large project written in Laravel. This package was inspired by many different works (packages, articles) of other authors. Here are some of them:
Prerequisites
Before you begin, ensure you have met the following requirements:
- PHP ^8.0
There are really no any other requirements. The package is Laravel-friendly, so if you install it into a Laravel project,
you will be able to use dependency injection within the handle()
method of your Actions/Features (more of them down below).
Installing Fraction
To install Fraction, run the composer require
command:
Using Fraction
This package introduces two abstract layers: Actions and Features.
Actions
Actions are basic "Units of Life" of the entire application. In a nutshell, Actions are regular PHP classes, focusing on
performing one specific task only (for example, saving a user into DB or sending an email). Actions can accept different
parameters via constructor and can be called from anywhere in the code (preferably from Applications or within the same
Domain only, though). It is highly recommended to have only one public method in each action class to help developers
avoid the temptation of polluting it with extra logic. A name of the Action should reflect what it actually does by
answering the question "what should it do?". Actions are parts of Domains, residing in their own Actions
folder.
Actions can also be used as Laravel Jobs.
An example of an Action class and its usage:
Thanks to the Pixelcone\Fraction\AsAction
trait, this Action class can be now called like this:
We've just instantiated the Action class and run a handle()
method using a single expression!
Features
Features have a lot in common with Actions: they're regular PHP classes too, they accept different params through
constructor, and they also can have one custom public handle
method. They have different purpose, though: they act as
an intermediate layer between controllers/commands and actions. It is a fairly common case when controller or command
methods get bigger over time, making it more difficult to read them. Features are designed to solve this problem, acting
as a controller/command action handler: processing input, calling action classes and forming a response. Features should
not be responsible for running actual business logic, though. Simply put, all the content of a particular controller or
command's method goes inside the Feature. And because it's now there, it can be divided into smaller methods. With that
being said, Features must be called from controllers/commands only. Similar to Action, the name of the Feature should
answer the question "what should it do?".
A typical feature's tasks include (but not limited to):
- Receiving user input and passing it further along the call chain
- Calling different Actions
- Forming and returning a response
An example of a Feature class and its usage:
With help of the Pixelcone\Fraction\RunsFeatures
trait, this class can now be conveniently called within the
controller's method:
Contributing to Fraction
To contribute to Fraction, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin pixelcone/fraction
- Create the pull request.
Alternatively, see the GitHub documentation on creating a pull request.
Contact
If you want to contact me you can reach me at [email protected].
License
This project uses the following license: MIT.