Giter Club home page Giter Club logo

php-get-typed-value's Introduction

php-get-typed-value

img php coverage

Get typed (strict mode) values from an Array / XML with basic validation.

composer require wrkflow/php-get-typed-value

Main features

  • ๐Ÿš€ Retrieve values from Array (JSON) / XML with correct return type with safe dot notation support.
  • ๐Ÿ† Makes PHPStan / IDE happy due the type strict return types.
  • ๐Ÿคนโ€ Validation: Ensures that desired value is in correct type (without additional loop validation).
  • ๐Ÿ›  Transformers: Ensures that values are in expected type.
  • โ›‘ Converts empty string values to null (can be disabled, see transformers).
use Wrkflow\GetValue\GetValue;
use Wrkflow\GetValue\DataHolders\ArrayData;

$data = new GetValue(new ArrayData([
    'address' => [
        'street' => [
            'number' => '13',
        ],
        'name' => '',
    ]   
]));
$data->getInt('address.street.number') // Returns: 13 (int)
$data->getString('address.street.name') // Returns: null because value does not exists
$data->getRequiredString('address.street.name') // Returns: throws MissingValueForKeyException exception

Documentation

Documentation is hosted on GitHub Pages.

Comment

I've created this project as part of my mission to create work flow tools / libraries to make my (and yours) dev life easier and more enjoyable.

Want more tools or want to help? Check wrk-flow.com or CONTRIBUTE. You can help me improve the documentation, add new tests and features. Are you junior developer? Don't be scared, get in touch and I will guide you in your first contribution.

php-get-typed-value's People

Contributors

pionl avatar szepeviktor avatar

Stargazers

 avatar  avatar

Watchers

 avatar

php-get-typed-value's Issues

Add static class helper for converting values

Sometimes we have value from different data source (like laravel form request) and we want to ensure that the type is correct.

For this we need only nullable values.

``php
Value::toInt($value);
Value::toString($value);
Value::toRequiredString($value);
Value::toBool($value);
Value::toArray($value);
Value::toFloat($value);


We want to reuse the basic `GetValue` logic for it.

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.