2017 © Pedro Peláez
 

library php-consistentor

The easies way to deal with PHP function name inconsistency

image

manulaiko/php-consistentor

The easies way to deal with PHP function name inconsistency

  • Thursday, July 21, 2016
  • by manulaiko
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHPConsistentor

Content

, (*1)

Introduction

One of the worst things of PHP is its lack of consistency in function names, even between similar/related functions:, (*2)

<?php

/*
 * Some functions use underscores (_) to separate words
 * while other similar functions don't
 */
gettype("foo");            // No separation between words
get_class(new stdClass()); // Words separated by underscores

/*
 * Other functions mix `to` with 2
 */
bin2hex("foo");    // 2
strtolower("FOO"); // to

This library provides a quick and simple fix for those issues, it's as easy to use as this:, (*3)

<?php
/**
 * Load PHPConsistentor
 */
require_once("PHPConsistentor.php");

// Call `PHPConsistentor::init` with the preferred settings
PHPConsistentor::init([
    "word_separation" => PHPConsistentor::WORD_SEPARATION_UNDERSCORE,
    "word_cut"        => PHPConsistentor::WORD_CUT_NO_CUT,
    "to_2"            => PHPConsistentor::TO_2_TO,
]);

get_type("foo");           //gettype
get_class(new stdClass()); //get_class

binary_to_hexadecimal("foo"); //bin2hex
string_to_lowercase("FOO");   //strtolower
new_line_to_br("f
o
o");                          //nl2br

And that's all, now you can code without worrying about function names consistency., (*4)

, (*5)

Installation

You can either download it directly through github, composer or by downloading Alexya Framework, (*6)

Manual installation

To manual install PHPConsistentor just clone this repository (or download the latest release) and include the file in your PHP script:, (*7)

<?php
/**
 * Load PHPConsistentor
 */
require_once("path/to/PHPConsistentor.php");

// Pretty hard, right?

Composer

The easiest way is probably install it through composer, so just add the followin lines to your composer.php file and execute composer update:, (*8)

{
    "require": {
        "manulaiko/php-consistentor": "dev-master"
    }
}

Or by executing the followin command:, (*9)

composer require manulaiko/php-consistentor:dev-master

Alexya Framework

PHPConsistentor comes prebuild with the latest Alexya Framework version and is located under the namespace \Alexya\PHPConsistentor:, (*10)

<?php
/**
 * Load Alexya's core
 */
require_once("bootstrap.php");

\Alexya\PHPConsistentor::init([
    "word_separation" => PHPConsistentor::WORD_SEPARATION_UNDERSCORE,
    "word_cut"        => PHPConsistentor::WORD_CUT_NO_CUT,
    "to_2"            => PHPConsistentor::TO_2_TO,
]);

, (*11)

Getting Started

Getting started with PHPConsistentor is as easy as including the PHPConsistentor.php file in your script and calling the PHPConsistentor::init method., (*12)

This method will automatically add the aliases of the function based on the configuration array (which is sent as a parameter)., (*13)

The array may contain the followin indexes:, (*14)

<?php
/**
 * Load PHPConsistentor
 */
require_once("PHPConsistentor.php");

/**
 * PHPConsistentor's configuration array
 */
$configuration = [
    /**
     * The way on which word separation will look.
     *
     * Possible values:
     *
     * - `PHPConsistentor::WORD_SEPARATION_UNDERSCORE`
     *       Separates the words with underscores like `get_class()`
     * - `PHPConsistentor::WORD_SEPARATION_NO_SEPARATION`
     *       Don't separates the words like `getclass()`
     * - `PHPConsistentor::WORD_SEPARATION_CAMEL_CASE`
     *       Separates the words with camelCase like `getClass()`
     */
    "word_separation" => PHPConsistentor::WORD_SEPARATION_UNDERSCORE, //Default

    /**
     * The way on which words will be cutted
     *
     * Possible values:
     *
     * - `PHPConsistentor::WORD_CUT_NO_CUT`
     *       Don't cuts the words like `binary2hexadecimal()`
     * - `PHPConsistentor::WORD_CUT_CUT`
     *       Conserves the default word cuts like `bin2hex()`
     */
    "word_cut" => PHPConsistentor::WORD_CUT_CUT, // Default

    /**
     * The way on which `2`, `to` functions should look
     *
     * Possible values:
     *
     * - `PHPConsistentor::TO_2_TO`
     *        Translates `2` functions to `to` functions like `nltobr()`
     *
     * - `PHPConsistentor::TO_2_2`
     *       Translates `to` functions to `2` functions like `str2lower()`
     */
    "to_2" => PHPConsistentor::TO_2_TO // Default
];

PHPConsistentor::init($configuration);

If you're using PHPConsistentor through the Alexya Framework the default settings can be edited in config/alexya.php under the PHPConsistentor index.git, (*15)

The Versions

21/07 2016

dev-master

9999999-dev

The easies way to deal with PHP function name inconsistency

  Sources   Download

GNU

The Requires

  • php >=5.0

 

by Avatar manulaiko

function php library functions tools tool naming consistency