Download the PHP package axm/fluent without Composer
On this page you can find all versions of the php package axm/fluent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package fluent
Short Description Fluent Interface for PHP
License MIT
Homepage https://axmphp.com
Informations about the package fluent
Fluent Interface
The FluentInterface
class is a PHP tool that provides a fluent interface for chaining methods and controlling the flow of operations concisely in PHP fluentlications. Its main purpose is to improve code readability, allowing you to chain a series of methods coherently and easy to follow. This is the greatest potential of this interface, it is no longer necessary to repeatedly return the $this object, now FluentInterface
handles it automatically for you.
📦 Installation
You can also use Composer to install Axm in your project quickly.
Method Chaining
You can chain multiple methods, which facilitates executing multiple operations sequentially. For example:
Flow Control
The class allows precise control of the method execution flow using if, elseif and else conditions. This is useful to run specific operations based on certain conditions. For example:
Dynamic Instance Creation
You can dynamically create class instances and set them as the current object. This is useful when you need to work with different objects flexibly. For example:
Exception Handling
The FluentInterface class handles exceptions and allows you to throw exceptions during execution, making condition-based decisions and thrown exceptions easier.
Debugging Functions
It offers methods like dd(), dump(), and echo() to aid in debugging and analyzing results.
dd() method
The dd() method (dump and die) is used to debug and analyze the results of the FluentInterface class. You can use it to show the contents of the current variable in detail. If you provide a key ($key), only that specific entry in the results will be shown. Usage example:
dump() method
The dump() method is used to debug and analyze the results of the FluentInterface class. As with dd(), you can provide a key ($key) to show only a specific entry in the results. Usage example:
echo() method
The echo() method is used to print the results of the FluentInterface class. You can optionally provide a value ($value) to print something specific. If no value is provided, it will print all current results. Usage example:
Using Custom Methods
In addition to the built-in methods, you can add your own custom methods using addCustomMethod(). This extends the functionality of the class according to your specific needs.
Interface with Laravel Collections
The class can work with Laravel collections and run collection methods on them. You just need to pass an array as an argument to the FluentInterface class. For example:
Usage Examples of Fluent Interface with an object.
Example 1: Operations on a Numeric Value
This example illustrates the use of the MyClass class, which provides a fluent interface to perform operations on a numeric value. The MyClass class has three main methods: increment()
, duplicate()
, and getValue()
.
Fluent Interface implementation:
Example 2: User Input Validation This example shows how to validate user input and make decisions based on specific conditions. The FluentInterface class provides a fluent interface to chain methods and control the execution flow effectively.
Example 3: Dynamic Report Generation Imagine you are developing a report generation fluentlication that allows users to configure and customize reports according to their needs. In this situation, FluentInterface can simplify the building of dynamic reports.
Suppose you have a ReportBuilder class that is used to build reports. You can use FluentInterface to chain methods and dynamically configure report components like headers, charts, data, and output formats.
Example 4: Building Configurable Forms Imagine you are developing a form builder platform where users can design their own forms with custom fields. FluentInterface can simplify the creation and manipulation of dynamic forms.
Example 5: Sending Custom Emails Suppose you are developing an fluentlication that sends custom emails to users. FluentInterface can simplify the building of these emails.
Example 6: Generating Dynamic SQL Queries Suppose you are developing a web fluentlication that needs to generate dynamic SQL queries to interact with a database. You can use FluentInterface to build these queries programmatically and readably:
Example 7: Creating Interactive Charts Suppose you are developing a web fluentlication that displays interactive charts to users. FluentInterface can help you construct and configure these charts flexibly: