PHPackages                             hphio/util - 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. hphio/util

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

hphio/util
==========

Various convenience and utility classes

v1.5.5.8(2y ago)02.9k—0%proprietaryPHP

Since Oct 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mjmunger/util)[ Packagist](https://packagist.org/packages/hphio/util)[ RSS](/packages/hphio-util/feed)WikiDiscussions master Synced 1mo ago

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

util
====

[](#util)

Utility classes for doing various tasks.

Helpers
-------

[](#helpers)

These are utility wrappers of system functions, which should be used to perform system operations because they can easily be mocked in tests.

### ShellExec

[](#shellexec)

Use this to run command line utilities. It is a wrapper for `shell_exec()`. It is a class so that it can be mocked in tests.

```
$shell = new ShellExec();
$cwd = sys_get_temp_dir();
$shell->exec("echo 'test' && echo 'error test' >&2", $cwd);
```

Running the example above will print *test* to stdout, and *error test* to stderr. You can retrieve the output of both streams by calling the `getStdout()` and `getStderr()` methods.

This is very useful in preventing output from going to the screen with command line utils that dump logging information to `stderr`.

### Tempdir

[](#tempdir)

Use this to get a temporary directory.

```
$tempdir = new Tempdir();
$path = $tempdir->create();
```

Tempfile
--------

[](#tempfile)

Use this to get a temporary file.

```
$tempfile = new Tempfile();
$path = $tempfile->create();
```

PDF
---

[](#pdf)

### Ghostscript

[](#ghostscript)

This class is used to downgrade / convert files from a newer version of PDF version 1.4 so that FPDi, FPDF, and other libraries can use it. It uses Ghostscript to do the conversion.

Usage:

```
$container = new Container();
$container->add(ShellExec::class);
$container->add(VersionParser::class);
$container->add(GhostScript::class)->addArgument($container);

$ghostscript = $container->get(GhostScript::class);
$pathToPdfFile = '/path/to/file.pdf';
$outputfile = '/path/to/output.pdf';
$ghostscript->downgrade($pathToPdfFile, $outputfile);
```

### PDF\\VersionParser

[](#pdfversionparser)

This class read a PDF file, and parses out the version of the PDF for that file. The method: `getVersion()` returns a string, like "1.4" or "1.7". Example usage:

```
$parser = new VersionParser();
$version = $parser->getVersion($pathToPdfFile);
```

It follows the specification for PDF files for the header described in ISO 32000-1:2008 for PDF v1.7. The latest standard (v2.0) is described in ISO 32000-2:2020.

This class was developed using the following information obtained from [PDF (Portable Document Format) Family](https://www.loc.gov/preservation/digital/formats/fdd/fdd000030.shtml#:~:text=Adobe%20has%20a%20number%20of,1.7):

```
Self-identification of chronological versions of PDF: Identification of chronological versions of PDF can be given
in two places in a PDF file. All PDF files should have a version identified in the header with the 5 characters
%PDF– followed by a version number of the form 1.N, where N is a digit between 0 and 7 or a version number of 2.0.
For example, PDF 1.7 would be identified as %PDF–1.7. However, beginning with PDF 1.4, a conforming PDF writer may
use the Version entry in the document Catalog to override the version specified in the header. The location of the
Catalog within the file is indicated in the Root entry of the file trailer/footer. This override feature was
introduced to facilitate the incremental updating of a PDF by simply adding to the end of the file. As a result,
it is necessary to locate the Catalog within the file to get the correct version number. Unless the PDF is
"linearized," in which case the Catalog is up front, this will require reading the trailer and then using the
reference there to locate the Catalog, which will typically be compressed. This has practical implications because
format identification tools, including DROID, typically look for particular characters at the beginning of a file
(i.e., in the header), to permit identification with minimal effort. DROID can look for characters at the end of the
file, but is not able to follow an indirect reference or decompress file contents. When the version number is not
the same in the header and the Catalog, there is potential for format identification errors.

```

PeopleTime
----------

[](#peopletime)

### Summary

[](#summary)

This class accepts two unix timestamps, and returns the human-readable, relative time for the interval between the two.

### Usage:

[](#usage)

```
$endTime = 1675209600;
$startTime = 1676470379;
$relativeTime = PeopleTime::calculate($endTime, $startTime);
echo $relativeTime; // "14 days"
```

$startTime is optional. If you leave do not specify it, it will use "now".

```
$endTime = 2018748556;
$relativeTime = PeopleTime::calculate($endTime);
echo $relativeTime; // "11 years"
```

IniUploadManager
----------------

[](#iniuploadmanager)

### Summary

[](#summary-1)

This class reads the php.ini file, and returns information about allowed upload sizes.

### Dependencies

[](#dependencies)

Requires these classes, which are included in this package.

- hphio\\util\\ByteValueInterpreter\\HumanReadable
- hphio\\util\\ByteValueInterpreter\\RawInteger
- hphio\\util\\PhpIni (a wrapper for `ini_get()`)

Usage:
------

[](#usage-1)

Assuming the following ini values:

```
post_max_size=8k
upload_max_filesize=7M
```

This code can used as follows:

```
$manager = $container->get(IniUploadManager::class);
echo $manager->getMaxUpload(); //7340032
echo $manager->getMaxPost(); //8192
echo $manager->getUploadLimit(); //8192

```

ByteValueInterpreter
--------------------

[](#bytevalueinterpreter)

### Summary

[](#summary-2)

A series of classes for converting ini values (like '8M') into their actual integer values.

### Usage

[](#usage-2)

Add dependencies to the container.

```
$container = new Container();
$container->add(RawInteger::class);
$container->add(HumanReadable::class);

```

It can interpret human readable shortcut values:

```
$value = '8M';
$obj = ByteValueFactory::getByteInterpreter($container, $value);
$obj->getBytes($value); //8388608

```

And will interpret raw integer values as well:

```
$value = '8388608';
$obj = ByteValueFactory::getByteInterpreter($container, $value);
$obj->getBytes($value); //8388608

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity74

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 ~46 days

Recently: every ~0 days

Total

42

Last Release

893d ago

Major Versions

v0.1.2 → v1.0.22022-07-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb09c625c46f0c8bbc7691aaa7efe99f1f567ed534d6f2b3ea7529bf708a72ea?d=identicon)[hphinc](/maintainers/hphinc)

---

Top Contributors

[![mjmunger](https://avatars.githubusercontent.com/u/6370814?v=4)](https://github.com/mjmunger "mjmunger (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hphio-util/health.svg)

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

###  Alternatives

[consolidation/robo

Modern task runner

2.7k62.9M410](/packages/consolidation-robo)[roach-php/core

A complete web scraping toolkit for PHP

1.5k352.4k3](/packages/roach-php-core)[ec-europa/toolkit

Toolkit packaged for Drupal projects based on Robo.

38244.6k16](/packages/ec-europa-toolkit)

PHPackages © 2026

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