PHP Classes

File: src/Util.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   Ionizer PHP Filter Input   src/Util.php   Download  
File: src/Util.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Ionizer PHP Filter Input
Filter input values by chaining filter objects
Author: By
Last change:
Date: 5 years ago
Size: 1,575 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace ParagonIE\Ionizer;

/**
 * Class Util
 * @package ParagonIE\Ionizer
 */
abstract class Util
{
    /**
     * A wrapper for explode($a, trim($b, $a))
     *
     * @param string $str
     * @param string $token
     * @return array<int, string>
     */
    public static function chunk(string $str, string $token = '/'): array
    {
        return \explode(
            $token,
            \trim($str, $token)
        );
    }

    /**
     * @param mixed $input
     * @return string
     * @throws \TypeError
     */
    public static function getType($input): string
    {
        if (\is_null($input)) {
            return 'null';
        }
        if (\is_callable($input)) {
            return 'callable';
        }
        if (\is_resource($input)) {
            return 'resource';
        }
        if (\is_object($input)) {
            return \get_class($input);
        }
        if (\is_string($input)) {
            return 'string';
        }
        $type = \gettype($input);
        switch ($type) {
            case 'boolean':
                return 'bool';
            case 'double':
                return 'float';
            case 'integer':
                return 'int';
        }
        throw new \TypeError('Unknown type');
    }

    /**
     * Returns true if every member of an array is NOT another array
     *
     * @param array $source
     * @return bool
     */
    public static function is1DArray(array $source): bool
    {
        return \count($source) === \count($source, \COUNT_RECURSIVE);
    }
}