PHPackages                             grithin/phpbase - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. grithin/phpbase

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

grithin/phpbase
===============

PHP Base Tools.

5.0.9(4y ago)1314112Apache-2.0PHPPHP &gt;=7

Since Oct 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/grithin/phpbase)[ Packagist](https://packagist.org/packages/grithin/phpbase)[ Docs](http://devtools.grithin.com)[ RSS](/packages/grithin-phpbase/feed)WikiDiscussions master Synced yesterday

READMEChangelog (8)DependenciesVersions (19)Used By (12)

PHP Base Tools
==============

[](#php-base-tools)

Provides php tools used by other grithin/php\* projects.

Tools
=====

[](#tools)

Arrays
------

[](#arrays)

```
# get arbitrarily deep item using a path (like lodash.get)
$user_input = [
	'name'=> [
		'first'=>'bob',
		'last'=>'bobl',
	]
];

$x = Arrays::get($user_input, 'name.first');
#> 'bob'

#+ flatten array picking one value {
$user_input = [
	'name'=> [
		'first'=>'bob',
		'last'=>'bobl',
	]
];

$x = Arrays::flatten_values($user_input);
ppe($x);
#>  {"name": "bob"}
#+ }

#+ flatten structured array {
$user_input = [
	'name'=> [
		'first'=>'bob',
		'last'=>'bobl',
	]
];

$x = Arrays::flatten($user_input);
ppe($x);
/*
{"name_first": "bob",
    "name_last": "bobl"}
*/
#+ }

#+ pick and ensure
$user_input = [
	'first_name'=>'bob',
	'last_name'=>'bobl',
	'unwanted'=>'blah'
];
$pick = ['first_name', 'last_name', 'middle_name'];

$x = Arrays::pick_default($user_input, $pick, 'N/A');
/*
{"first_name": "bob",
    "last_name": "bobl",
    "middle_name": "N\/A"}
*/
#+ }

#+ rekey and exclude {

$user_input = [
	'first_name'=>'bob',
	'last_name'=>'bobl',
	'unwanted'=>'blah'
];
$map = ['first_name'=>'FirstName', 'last_name'=>'LastName'];

$x = Arrays::map_only($user_input, $map);
ppe($x);
/*
{"FirstName": "bob",
    "LastName": "bobl"}
*/
#+ }
```

Files
-----

[](#files)

The primary functions are file inclusion functions `inc`, `req`, `incOnce`, `reqOnce`. They allow inclusion tracking, context isolation, variable injection, variable extraction, and global injection.

Example file `bob.php`

```
$bill = [$bob]
$bill[] = 'monkey'
return 'blue'
```

Use

```
Files::inc('bob.php')
#< 'blue'

# Using variable injection and variable extraction
Files::inc('bob.php',['bob'=>'sue'], ['extract'=>['bill']])
#< ['sue', 'monkey']
```

Bench
-----

[](#bench)

Simple benching utility

```
$bench = new \Grithin\Bench();
for($i=0; $imark();
for($i=0; $iend_out();
```

```
...
   "value": {
        "intervals": [
            {
                "time": 0.0035231113433838,
                "mem.change": 808
            },
            {
                "time": 0.0028860569000244,
                "mem.change": 776
            }
        ],
        "summary": {
            "mem": {
                "start": 403168,
                "end": 404752,
                "diff": 1584
            },
            "time": 0.0064091682434082
        }
    }
...

```

Memoized
--------

[](#memoized)

The Memoized trait adds magic methods that interpret the method call, and if the call is prefixed with either `memoize_` or `memoized_`, Memoized will handle memoizing the method.

```
class Test{
	use \Grithin\Traits\Memoized;

	public function random(){
		return microtime()
	}
}
$Test = new Test;
$x = $Test->memoized_random();
$y = $Test->memoized_random();
$x == $y; # > true
```

If a memoized function needs to be re-memoized, you can prefix it with `memoize_`

```
# ...
$x = $Test->memoized_random();
$y = $Test->memoize_random();
$x == $y; # > false
```

Memoized will make a key out of the function parameters, so if the function parameters are different, they will generate different memoize cache - and it does this independently of which parameters are used.

```
# ...
$x = $Test->memoized_random(1);
$y = $Test->memoized_random(2);
$x == $y; # > false
```

Memoized can be used with static methods

```
class Test{
	use \Grithin\Traits\Memoized;

	static function random(){
		return microtime();
	}
}
$x = Test::memoized_random();
$y = Test::memoized_random();
$x == $y; # > true
```

In some cases, it is desirable to know whether a method is currently being memoized. Let's say we have a `user_get` function that returns data about a user, and within that function there is another `location_get` function, that returns data about location linked to the user. Let's say there are two scenarios where we ant output from user\_get:

- code that needs the most up-to-date `user_get` data
- code that can expect `user_get` calls to be the same data during its run

Memoized provides a way to check whether the current function is within a memoize chain. For instance level memoizing `$this->memoizing()`; for static memoizing, the `Memoized::static_memoizing()`.

We could have a `user_get` that looks like

```
class User{
	use \Grithin\Traits\Memoized;
	public user_get($id){
		$user_data = Db::get('...');
		if($this->memoizing()){ # function has been called with a memoize_ or memoized_ prefix
			$location = Location::memoized_get($user_data['location']);
		}else{
			$location = Location::get($user_data['location']);
		}
	}
}
```

Finally, a function can check if it was directly called to be memoized by using `->caller_requested_memoized()` and `::static_caller_requested_memoized()`.

Debug
-----

[](#debug)

Handling errors and print output

### Set up for error handling

[](#set-up-for-error-handling)

```
# optionally configure
Debug::configure([
	'log_file'=>__DIR__.'/log/'.date('Ymd').'.log',
	'err_file'=>__DIR__.'/log/'.date('Ymd').'.err',	]);

set_error_handler(['\Grithin\Debug','handleError'], E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
set_exception_handler(['\Grithin\Debug','handleException']);
```

### Output

[](#output)

Printing out any variable

```
$bob = ['bob'];
$sue = ['sue'];
$bob[] = &$sue;
$sue[] = &$bob;
$sue[] = 'moe';

Debug::out($sue);

echo 'bob';
```

Outputs:

```
{
    "file": "\/test.php",
    "line": 37,
    "i": 1,
    "value": []
}bob

```

If run within a web server, it will enclose with ``

`Debug::quit();` will do `::out()` then `exit`.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~124 days

Recently: every ~6 days

Total

18

Last Release

1808d ago

Major Versions

2.3.0 → 3.0.02016-08-07

3.0.0 → 4.0.02017-01-10

4.1.0 → v5.0.02021-06-18

PHP version history (2 changes)v2.0.0PHP &gt;=5.5.9

v5.0.2PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4543facab3c88d548b98d8472b532faf7bcd00555cc47c0dc808d935f8d3d73f?d=identicon)[grithin](/maintainers/grithin)

---

Top Contributors

[![grithin](https://avatars.githubusercontent.com/u/7241358?v=4)](https://github.com/grithin "grithin (121 commits)")

---

Tags

php-tools

### Embed Badge

![Health badge](/badges/grithin-phpbase/health.svg)

```
[![Health](https://phpackages.com/badges/grithin-phpbase/health.svg)](https://phpackages.com/packages/grithin-phpbase)
```

###  Alternatives

[appstract/nova-horizon

Horizon statistics in Nova

77311.7k](/packages/appstract-nova-horizon)[z38/metzli

PHP library to generate Aztec barcodes

26330.2k](/packages/z38-metzli)[moneyphp/iso-currencies

Provides up-to-date list of ISO 4217 currencies as provide by the official ISO Maintenance Agency

25153.2k7](/packages/moneyphp-iso-currencies)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
