phpallas / buffer
A Stock to keep variables and function and use them inside a pipiline system
Requires
- php: >=5.3
- phpallas/utilities: >=1.0
Requires (Dev)
- phpunit/phpunit: ^11
This package is auto-updated.
Last update: 2025-04-07 20:26:18 UTC
README
A stock to keep variables and functions and use them inside a pipeline system. This package was originally created to work alongside various packages by the PHPallas Team. However, it can be used anywhere you need a buffer object to keep your variables and functions available across steps of a pipeline.
How to Use
-
Install
phpallas/buffer
: You can install it in your project using Composer as follows:composer require phpallas/buffer
This will install the latest version of the package.
-
Get an Instance:
Buffer
is a singleton, so to get the instance in any part of your program, use the following method:use PHPallas\Buffer\Stock as Buffer; $buffer = Buffer::getInstance();
-
Set a Variable: You can set a variable as shown below:
use PHPallas\Buffer\Stock as Buffer; $buffer->set("namespace.name", "value here");
The name of the variable may include namespaces using dot notation, for example,
vars.page.title
,tables.main.headers
, etc. -
Get a Variable: You can use dot notation to get the variable value. For example, if you set an array as follows:
$buffer->set("page.title", ["title" => "great", "subTitle" => "awesome title", "separator" => "|"]);
Then:
$buffer->get("page.title.title"); // => great $buffer->get("page.title.subTitle"); // => awesome title $buffer->get("page.title"); // => ["title" => "great", "subTitle" => "awesome title", "separator" => "|"]
-
Unset a Variable: You can use dot notation to unset variables. For example:
$buffer->unset("page.title");
-
Attach an Observer: It is possible to attach observers to watch buffer elements and get notified if a change occurs.
For example:
$buffer->attach("page.title", $observer, "main");
Now, by any changes in page.title
, $observer
will be notified throughout notify($scope, $name, $oldValue, $value)
method of $observer
.
Feature Request
If you need a feature that is missing from this package, just create an issue.
Contribution
All types of contributions (development, testing, translation) are welcome! You can contribute to this package to make it better and more usable.
License
This package is licensed under the MIT License.