GithubHelp home page GithubHelp logo

type-identifier's Introduction

type-identifier

Effective primitive type identifier. A free library to identify and sanitize data from associative array, super global array or Http Request

Prerequisites

This library can ben instaled inside a projeti with PHP 5.6, but is 100% ready for PHP 8.1 and PHP doc is PHP 8.1 oriented. PHP 5.6 need this library more than newest version, but it can be useful inside a brand new project too to handle and sanitize, HTTP Request values or heterogeneous associative array

Some example

Load dependencie

use TypeIdentifier\Service\EffectivePrimitiveTypeIdentifierService;
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue(1);   // Result will be 1 with type int
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue("1");   // Result will be 1 with type int
$array["value"] = "1.1";
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue($array["value"]);  // Result will be 1.1 with type float
$value = "1.1a";
$array["value"] = $value;
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue($array["value"]); // Result will be "1.1a" with type string
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue(1 === 1); // result will be true type bool
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValue("snipershady       ", true); // Trim enabled. Result will be "snipershady" without any whitespace and type string

Force string sanitizing

$ept = new EffectivePrimitiveTypeIdentifierService();
$trim = true; // Can be false, is not mandatory if you want to force string sanitizing
$forceString = true;
$result = $ept->getTypedValue("1", $trim, $forceString);   // Result will be "1" with type string and will not handled as integer

Array sanitizing with offset validation

$value = "snipershady";
$array["value"] = $value;
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValueFromArray("value", $array);  // Result will be "snipershady" sanitized and type string

Array sanitizing retrurn null on invalid offset

$value = "snipershady";
$array["value"] = $value;
$ept = new EffectivePrimitiveTypeIdentifierService();
$result = $ept->getTypedValueFromArray("invalid_offset", $array);  // Result null. "invalid_offset" is not a valid offset for the array.

type-identifier's People

Contributors

snipershady avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.