Phootwork is a collection of php libraries which fill gaps in the php language and provides consistent object oriented solutions where the language natively offers only functions.
The phootwork package includes:
- collection a library to model several flavours of collections
- file an object oriented library to manipulate filesystems elements (stream compatible)
- json a json library, with clean syntax and proper error handling
- lang a library to manipulate arrays and strings in an object oriented way
- tokenizer an easy to use tokenizer library for PHP code
- xml an object oriented xml utility library
We use composer as dependency manager and distribution system. To install the library run:
composer require phootwork/phootwork
Each single package can be installed separately. I.e. if you want to include in your project the collection
library only:
composer require phootwork/collection
Note: the single library packages does not ship with tests and --dev dependencies. If you want to run the test suite or contribute to the library, you have to install the whole
phootwork/phootwork
package.
The following examples show what you can find in this library. You can discover much, much more by reading the documentation and the api.
<?php declare(strict_types=1);
/**
* Example describing how to manipulate a string via the Text class
* and its nice fluent api.
*/
use phootwork\lang\Text;
$text = new Text('a beautiful string');
// Remove the substring 'a ' and capitalize. Note: Text objects are *immutable*,
// so you should assign the result to a variable
$text = $text->slice(2)->toCapitalCase(); // 'Beautiful string'
// Capitalize each word and add an 's' character at the end of the string
$text = $text->toCapitalCaseWords()->append('s'); // 'Beautiful Strings'
// Calculate the length of the string
$length = $text->length(); // 17
// Check if the string ends with the 'ngs' substring
$text->endsWith('ngs'); // true
<?php declare(strict_types=1);
/**
* Example describing how to manipulate a Stack collection (Last In First Out)
* via the Stack class
*/
use phootwork\collection\Stack;
$stack = new Stack(['Obiwan', 'Luke', 'Yoda', 'Leila']);
// Sort the stack
$stack = $stack->sort(); // ['Leila', 'Luke', 'Obiwan', 'Yoda']
// Check if the collection contains any elements
$stack->isEmpty(); // false
// How many elements?
$stack->size(); // 4
// Push an elememt
$stack->push('Chewbecca');
// How many elements now?
$stack->size(); // 5
// Peek the head element (return the head element, without removing it)
$stack->peek(); // 'Chewbecca'
$stack->size(); // 5
// Pop the head element
$stack->pop(); // 'Chewbecca'
$stack->size(); // 4: pop() removes the popped element
The official documentation site: https://phootwork.github.io
In order to run the test suite, download the full library:
git clone https://github.com/phootwork/phootwork
Then install the dependencies via composer:
composer install
and run:
composer test
Our test
script calls the vendor/bin/phpunit
command under the hood, so you can pass to it all the phpunit options,
via --
operator i.e.: composer test -- --stop-on-failure
.
Each library has its own test suite and you can run it separately. I.e. suppose you want to run the collection library test suite:
composer test -- --testsuite collection
or alternatively:
vendor/bin/phpunit --testsuite collection
Phootwork also provides a command to generate a code coverage report in html format, into the coverage/
directory:
composer coverage
Report issues at the github Issue Tracker.
Every contribute is welcome, whether it is a simple typo or a new modern complicated feature. We are very grateful to all the people who will dedicate their precious time to this library!
You can find all information about it in the CONTRIBUTING.md document.
Refer to Releases