<?php
namespace Wpupgrader\Libraries\WordPress\Plugins\Core;

/**
 * Class Utilities is a library of static functions
 *
 * @author Wpupgrader | P.R. Weijtenburg
 * @package Wpupgrader\Libraries\WordPress\Plugins\Core
 */
final class Utilities
{
    private function __construct()
    {
        throw new \Exception(__CLASS__.' may not be constructed.');
    }

    /**
     * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
     *
     * @param string $string
     * @param string $glue
     * @return string
     */
    static public function tableizer($string, $glue = '_')
    {
        return \trim(\strtolower(\preg_replace('~[\W_'.$glue.']+~', $glue, \preg_replace('~(?<=\w)([A-Z])~', $glue.'$1', $string))), $glue);
    }

    /**
     * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
     *
     * @param string $string
     * @param string $glue
     * @return mixed
     */
    static public function classifier($string, $glue = '')
    {
        return \str_replace('_', $glue, \ucwords(static::tableizer($string), '_'));
    }

    /**
     * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'Table name'.
     *
     * @param string $string
     * @return mixed
     */
    static public function humanizer($string)
    {
        return \ucfirst(static::tableizer($string, ' '));
    }

    /**
     * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'Table Name'.
     *
     * @param string $string
     * @return mixed
     */
    static public function labelizer($string)
    {
        return \ucwords(static::humanizer($string));
    }

    /**
     * Camelizes a word. This uses the \classify() method and turns the first character to lowercase.
     *
     * @param string $string
     * @param string $glue
     * @return string
     */
    static public function camelizer($string, $glue = '')
    {
        return \lcfirst(static::classify($string, $glue));
    }
}