2017 © Pedro Peláez
 

library stdlib

Standard library for PHP

image

blackbonjour/stdlib

Standard library for PHP

  • Sunday, June 10, 2018
  • by BlackBonjour
  • Repository
  • 3 Watchers
  • 2 Stars
  • 1,242 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 12 Versions
  • 60 % Grown

The README.md

Latest Stable Version Total Downloads License, (*1)

stdlib

Standard library for PHP., (*2)

This library contains many helping classes for manipulating multibyte strings and handling various types of arrays., (*3)

Installation

It's recommend that you use Composer to install Stdlib., (*4)

$ composer require blackbonjour/stdlib

This will install Stdlib and all required dependencies. Stdlib requires PHP 7.4 or newer., (*5)

Usage

Following are a few example of what this library is capable of., (*6)

Language

With StdString you have a powerful tool for manipulating strings. Many functions are good known from other programming languages such as Java., (*7)

$string      = new StdString('My vehicle has %d wheels.');
$translation = StdString::format($string, 4);

echo $translation; // My vehicle has 4 wheels.

StdString is also multibyte compatible., (*8)

$format      = '"%s" means "%s".';
$translation = StdString::format($format, 'Привет', new StdString('Hello'));

echo $translation; // "Привет" means "Hello".

StdString instances can be created from string and Character[]., (*9)

StdString also implemented ArrayAccess, which allows us to treat StdString instances like regular strings., (*10)

$string = new StdString('FooBar');

echo $string[4]; // a

Utils

Utils contains classes for easier handling with arrays and assertions., (*11)

Assert

With Assert::empty() you have the possibility to check multible values for emptiness at once. This method works exactly the same as PHPs internal function empty()., (*12)

var_dump(Assert::empty(null, 0, '', [])); // true
var_dump(Assert::empty(null, 1, 'FooBar', [])); // false

For the opposite way use Assert::notEmpty to check if all values are not empty., (*13)

var_dump(Assert::notEmpty(123, 'FooBar', [123])); // true
var_dump(Assert::notEmpty(123, 'FooBar', [])); // false

With Assert::typeOf() to check if multiple values are of specified types or are instances of specified classes. This method is supposed to react like PHP itself. So if the values are not of specified types or classes, a TypeError exception will be thrown. If that behaviour is not what you want, you can use the method Assert::validate instead. That method will return true if all values are of specified types or classes, false otherwise., (*14)

$allowedTypes = [Assert::TYPE_INTEGER, Assert::TYPE_FLOAT];

var_dump(Assert::validate($types, 123, 456.7));

HashMap

With HashMap it is now possible to have arrays with objects as keys., (*15)

$hashMap = new HashMap;
$hashMap->put(new StdString('FooBar'), ['foo' => 'bar']);

var_dump($hashMap->key() instanceof StdString); // Returns `true`

$hashMap->put(new stdClass, new StdString('NotFooBar'));

foreach ($hashMap as $key => $value) {
    echo StdString::format('%s => %s' . PHP_EOL, gettype($key), gettype($value));
}

/*
 * Output:
 *
 * object => array
 * object => object
 */

The Versions

10/06 2018

dev-master

9999999-dev https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php utility utf-8 manipulation string assertion util map stdlib hashmap

10/06 2018

0.5.1

0.5.1.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php utility utf-8 manipulation string assertion util map stdlib hashmap

04/06 2018

0.5.0

0.5.0.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php utility utf-8 manipulation string assertion util map stdlib hashmap

29/05 2018

0.4.1

0.4.1.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

28/04 2018

0.4.0

0.4.0.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

06/03 2018

0.3.1

0.3.1.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

06/03 2018

0.3.2

0.3.2.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

10/02 2018

0.3.0

0.3.0.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

07/02 2018

0.2.2

0.2.2.0 https://github.com/BlackBonjour/stdlib

Standard library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php utility utf-8 manipulation string assertion util stdlib

06/02 2018

0.2.1

0.2.1.0 http://www.erickdyck.de

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

php stdlib

06/02 2018

0.2.0

0.2.0.0 http://www.erickdyck.de

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

php stdlib

30/01 2018

0.1.0

0.1.0.0 http://www.erickdyck.de

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

php stdlib