Download the PHP package peekandpoke/psi without Composer

On this page you can find all versions of the php package peekandpoke/psi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package psi

Code Coverage Scrutinizer Code Quality Build Status

Introduction

PSI helps you to write cleaner and more stable PHP-Code. Especially when it comes to iterating, filtering, mapping, sorting arrays or array-like data.

PSI consists of multiple small operations that can be combined and chained. Doing so results in easier to read and more expressive code.

PSI supports PHP versions >= 7.0

TOC

Examples

Let's have a look at some examples.

Get all adults

In plain PHP this might looks like:

Get all adults and sort them by age

In plain PHP this might looks like:

Get all adults and sort them by age descending

Mapping

With Psi::map() you can convert incoming data.

For example lets convert all persons to ints (the persons age)

This might result in

We could also convert each Person into something else.

This might result in

Advanced filtering

With Psi::filterBy() you can combine mapping and filtering.

Let's get all adults by checking the age using Psi\IsGreaterThanOrEqual().

The example below will also give you all Persons with an age greater than or equal to 18.

Check if all or any elements match

With Psi::all() you can check if all elements match the given condition

With Psi::any() you can check if there is at least one element matching the condition

Grouping

Let's group all persons by their age

This might output:

Multiple inputs

You can pass multiple array or array-like parameters to Psi::it(... $inputs)

Skip and Limit

Let's get up to 5 adults but skip the first 10:

Or let's skip the first 10 no matter what they are and then get up to 5 adults

Or let's skip the first 10, then get up to 5 and then filter the adults out of these

Count, sum, min, max, average, median

Let's count the number of adults:

Let's sum the age of all persons:

Let's get the youngest age of all people we know:

Let's get the oldest age of all:

Let's get the average age:

Let's get the median age:

Let's get the median age of all adults:

Get first, last, random

Let's get the first person that fits a certain condition (name starting with "A")

Let's get the last person that fits a certain condition (name starting with "A")

Let's get a random person that fits a certain condition (name starting with "A")

Detailed Documentation

Filters - type checks

IsArray and IsNotArray

Filters for Arrays using is_array()

IsBool and IsNotBool

Filter for Booleans using is_bool()

IsCallable and IsNotCallable

Filter for Callables using is_callable()

IsDateString and IsNotDateString

Checks if the given string is a string that would be understood be new \DateTime($str)

IsEmpty and IsNotEmpty

Filter for empty things using empty()

IsInstanceOf and IsNotInstanceOf

Filter for class instance

IsInteger and IsNotInteger

Filter for integers using is_int()

IsIntegerString and IsNotIntegerString

Filter for strings that contain an integer

IsNull and IsNotNull

Filter for nulls

IsNumeric and IsNotNumeric

Filter for numeric values using is_numeric()

IsObject and IsNotObject

Filter for objects

IsResource and IsNotResource

Filter for resources

IsScalar and IsNotScalar

Filter for scalar values using is_scalar()

Filter - comparison

IsEqualTo and IsNotEqualTo

Filter for NON type safe eqaulity (==). See IsSame / IsNotSame for === comparison

UnitTests

First install all dependencies

Then run all tests

Releases

new in v1.2.0

REMOVED PHP 5.6 SUPPORT

Added

new in v1.1.0

Moved mapper ToFloat, ToInteger, ToString to Psi\Map...

Old versions are kept for compatibility and marked as deprecated.

new in v0.6.4

Psi::chunk

Will split the stream into chunks of the given size.

will result in

Psi::skip

Skips the first n elements in the current stream

will result in

Psi::limit

Limits the result to the first n element in the current stream

will result in

Psi::takeWhile

Take all elements of the input stream while the condition is met

will result in

Psi::takeUntil

Take all elements of the input stream until the condition is met

will result in

Psi::getLast

Get the last element of the stream.

will result in

Psi::getRandom

Will select a random element from the stream.

will result in

Num::IsMultipleOf and Num::IsNotMultipleOf

Filters all numbers that are a multiple of the given factor

will result in

Num::IsPrime and Num::IsNotPrime

Filters all number that are prime number.

CAUTION: do not use this impl for big numbers, a it can be very slow.

will result in

new in v0.6.3

Psi::filterBy()

In order to by able to use all other matchers on nested property / values of input objects, the method Psi::filterBy() was added

Psi::uniqueBy

Finds unique elements by first passing them through a mapper.

ToFloat

Maps inputs to floats.

ToInteger

Maps inputs to integers.

ToString

Maps inputs to strings.

Str::IsStartingWith and Str::IsNotStartingWith - with or with case

Filters all strings starting with the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

Str::IsEndingWith and Str::IsNotEndingWith - with or without case

Filters all strings ending with the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

Str::IsContaining and Str::IsNotContaining - with or without case

Filters all strings containing the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

Str::IsMatchingRegex and Str::IsNotMatchingRegex

Filters all strings containing the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

Str::WithoutAccents

Modifies a string by replacing special characters with the "normal" form, e.g.

new in v0.6.0 to v0.6.2

The internal folder structure was changed:

new in v0.5.0

Psi::groupBy

would become

Psi::sortBy

Sort a list of objects by one of their properties, e.g. sorting persons by their age

Todos and ideas

general

Unary filter functions for strings

String-Mappers

... for PHP-Types ... LocalDate::isSameDay


All versions of psi with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
ext-pcre Version *
peekandpoke/php-types Version ^1.2.0
symfony/polyfill-mbstring Version ^1.6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package peekandpoke/psi contains the following files

Loading the files please wait ....