PHPackages                             eserozvataf/scabbia2-helpers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eserozvataf/scabbia2-helpers

AbandonedArchivedLibrary

eserozvataf/scabbia2-helpers
============================

Scabbia2 Helpers Component

v0.1.3(10y ago)277Apache-2.0PHPPHP &gt;=5.6.0

Since Sep 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/eserozvataf/scabbia2-helpers)[ Packagist](https://packagist.org/packages/eserozvataf/scabbia2-helpers)[ Docs](http://www.scabbiafw.com/)[ RSS](/packages/eserozvataf-scabbia2-helpers/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Scabbia2 Helpers Component
==========================

[](#scabbia2-helpers-component)

[This component](https://github.com/eserozvataf/scabbia2-helpers) is the swiss knife for rest of the scabbia2 components. Includes most commonly used helper methods filed under `Arrays`, `Date`, `FileSystem`, `Html`, `Runtime` and `String` static classes.

[![Build Status](https://camo.githubusercontent.com/2e5b95f82e73733fb7974e03a65de8d43a3ca7ed684712fa4714737554177d82/68747470733a2f2f7472617669732d63692e6f72672f657365726f7a76617461662f73636162626961322d68656c706572732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/eserozvataf/scabbia2-helpers)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/51167850618513f4717237d9018c91892ab14d70875ec6b86a7efb8e6d17b1ac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f657365726f7a76617461662f73636162626961322d68656c706572732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/eserozvataf/scabbia2-helpers/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/9aca6127f30ad3961c99f02227db04a1ee9588170269efe7242aa2b159ab07c1/68747470733a2f2f706f7365722e707567782e6f72672f657365726f7a76617461662f73636162626961322d68656c706572732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/eserozvataf/scabbia2-helpers)[![Latest Stable Version](https://camo.githubusercontent.com/75f725f9514264c7b9c2ee5ed7efe83bde27a20e5334e9c41c340b7ebed5b60e/68747470733a2f2f706f7365722e707567782e6f72672f657365726f7a76617461662f73636162626961322d68656c706572732f762f737461626c65)](https://packagist.org/packages/eserozvataf/scabbia2-helpers)[![Latest Unstable Version](https://camo.githubusercontent.com/28f97d7598d3a3f540dcb4997ff2e9c4efa7ba89d2d0d51c1e2f3066ad923f81/68747470733a2f2f706f7365722e707567782e6f72672f657365726f7a76617461662f73636162626961322d68656c706572732f762f756e737461626c65)](https://packagist.org/packages/eserozvataf/scabbia2-helpers)[![Documentation Status](https://camo.githubusercontent.com/1ebeb3aa2c5cce31b6bf29a03a59cd40727e8fe235ba9ca28824ef1330a81328/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f73636162626961322d646f63756d656e746174696f6e2f62616467652f3f76657273696f6e3d6c6174657374)](https://readthedocs.org/projects/scabbia2-documentation)

Usage
-----

[](#usage)

### Arrays

[](#arrays)

```
use Scabbia\Helpers\Arrays;

$output = Arrays::flat(['a', ['b', 'c']]);
// $output == ['a', 'b', 'c']

$output = Arrays::getFirst(['a', 'b']);
// $output == 'a'

$output = Arrays::get(['a' => '1', 'b' => '2'], 'b');
// $output == '2'

$output = Arrays::getArray(['a' => '1', 'b' => '2', 'c' => '3'], 'a', 'c', 'd');
// $output == ['a' => '1', 'c' => '3', 'd' => null];

$output = Arrays::getPath(['a' => ['b' => ['c' => 5]]], 'a/b/c');
// $output == 5

$output = Arrays::getArrayPath(['a' => ['b' => ['c' => 5, 'd' => 6]]], 'a/b/c', 'a/b/d', 'a/b/e');
// $output == ['a/b/c' => 5, 'a/b/d' => 6, 'a/b/e' => null];

$output = Arrays::getRandom(['a', 'b', 'c']);
// $output == 'c'

$output = Arrays::range(1, 5);
// $output == [1, 2, 3, 4, 5]

$output = Arrays::sortByKey([
    ['i' => 5],
    ['i' => 2],
    ['i' => 4]
], 'i');
// $output == [['i' => 2], ['i' => 4], ['i' => 5]]

$output = Arrays::categorize([
    ['t' => 'a', 'i' => 5],
    ['t' => 'b', 'i' => 2],
    ['t' => 'a', 'i' => 4]
], 't');
// $output == [
//     'a' => [['t' => 'a', 'i' => 5], ['t' => 'a', 'i' => 4]],
//     'b' => [['t' => 'b', 'i' => 2]],
// ]

$output = Arrays::assignKeys([
    ['i' => 5],
    ['i' => 2],
    ['i' => 4]
], 'i');
// $output == [5 => ['i' => 5], 2 => ['i' => 2], 4 => ['i' => 4]]

$output = Arrays::column([
    ['i' => 5],
    ['i' => 2],
    ['i' => 4]
], 'i');
// $output == [5, 2, 4]

$output = Arrays::columns([
    ['i' => 5, 'j' => 6, 'k' => 7],
    ['i' => 2, 'j' => 3, 'k' => 4],
    ['i' => 4, 'j' => 5, 'k' => 6]
], 'i', 'k');
// $output == [
//     ['i' => 5, 'k' => 7],
//     ['i' => 2, 'k' => 4],
//     ['i' => 4, 'k' => 6]
// ]

$output = Arrays::getRow([
    ['i' => 5, 'j' => 6, 'k' => 7],
    ['i' => 2, 'j' => 3, 'k' => 4],
    ['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == ['i' => 5, 'j' => 6, 'k' => 7]

$output = Arrays::getRowKey([
    'a' => ['i' => 5, 'j' => 6, 'k' => 7],
    'b' => ['i' => 2, 'j' => 3, 'k' => 4],
    'c' => ['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == 'a'

$output = Arrays::getRows([
    ['i' => 5, 'j' => 6, 'k' => 7],
    ['i' => 2, 'j' => 3, 'k' => 4],
    ['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == [
//     ['i' => 5, 'j' => 6, 'k' => 7],
//     ['i' => 5, 'j' => 5, 'k' => 6]
// ]

$output = Arrays::getRowsBut([
    ['i' => 5, 'j' => 6, 'k' => 7],
    ['i' => 2, 'j' => 3, 'k' => 4],
    ['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == [
//     ['i' => 2, 'j' => 3, 'k' => 4]
// ]

$output = Arrays::combine(
    ['a', 'b', 'c'],
    [1, 2]
);
// $output == ['a' => 1, 'b' => 2, 'c' => null]

$output = Arrays::sortByPriority([
    'second' => 221,
    'forth' => 444,
    'third' => 727,
    'first' => 878
], ['first', 'second']);
// $output == ['first' => 878, 'second' => 221, 'forth' => 444, 'third' => 727]
```

### String

[](#string)

```
use Scabbia\Helpers\String;

$output = String::getEncoding();
// $output == 'utf8'

$output = String::coalesce($_GET['x'], '5');
// $output == '5'

$output = String::prefixLines("line 1\nline 2", '- ');
// $output == "- line 1\n- line 2"

$output = String::filter('1', String::FILTER_SANITIZE_BOOLEAN);
// $output == true

$output = String::format('value: {val}', ['val' => 5]);
// $output == 'value: 5'

String::vardump($_GLOBALS);
// echoes all globals in html format

$output = String::hash('scabbia test');
// $output ==

$output = String::generatePassword(5);
// $output == 'trawr'

$output = String::generateUuid();
// $output == '644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b'

$output = String::generate(6, 'abcdef');
// $output == 'efdabb'

$output = String::xss('
