Code Monkey home page Code Monkey logo

dot's Introduction

Dot

Build Status Total Downloads Latest Stable Version

Description

Dot is a tiny library and implements array dot notation for PHP written by Selvin Ortiz

Requirements

Install

composer require selvinortiz/dot

Test

sh spec.sh

Usage

To use Dot after proper installation, just autoload it, use it, and call methods on it:)

$input = [
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Kelly'
        ],
        'mood' => 'Happy',
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];

Dot::has($input, 'spouse');
// true

Dot::has($input, 'mistress.relationship');
// false

Dot::get($input, 'spouse.name.last');
// 'Kelly'

Dot::get($input, 'spouse');
/*
[
    'name' => [
        'first' => 'Brandon',
        'last'  => 'Kelly'
    ],
    'mood' => 'Happy',
    'age'  => '75'
]
*/

Dot::set($input, 'spouse.name.last', 'Bell');
/* $input will be mutated with a changed value
[
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Bell'
        ],
        'mood' => 'Happy',
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];
*/

Dot::delete($input, 'spouse.mood');
/* $input will be mutated with a key/value deleted
[
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Bell'
        ]
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];
*/

API

Dot has a very small API and hoping to keep it small and to the point.

Dot::has($arr, $key)

Returns whether or not $arr has $key. Put another way, $key exists in $arr

Dot::get($arr, $key, $default = null)

Returns the value found in $arr by $key or $default provided

Dot::set(array &$arr, $key, $value)

Mutates the $arr by adding a new $key with $value provided

Dot::delete(array &$arr, $key)

Mutates the $arr by delete $key and its associated value if found

Contribute

Dot wants to be friendly to first time contributors. Just follow the steps below and if you have questions along the way, please reach out.

  1. Fork it!
  2. Create your bugfix or feature branch
  3. Commit and push your changes
  4. Submit a pull request

License

Dot is open source software licensed under the MIT License

dot's People

Contributors

selvinortiz avatar peter279k avatar

Stargazers

spamhater avatar André Philip avatar  avatar  avatar Simon Eddy avatar Daniel Sentker avatar  avatar

Watchers

André Philip avatar James Cloos avatar  avatar  avatar

Forkers

peter279k

dot's Issues

PHP Unit conflict

I'm running into an upgrade issue where the dot package seems to be the blocker. The conflict seems to have to do with the phpunit/phpunit requirement and its symfony/yaml dependency

- Root composer.json requires selvinortiz/dot ^1.1 -> satisfiable by selvinortiz/dot[v1.1.0].
- Conclusion: don't install symfony/yaml v3.4.47 (conflict analysis result)
- selvinortiz/dot v1.1.0 requires phpunit/phpunit ^4.8 -> satisfiable by phpunit/phpunit[4.8.0, ..., 4.8.36].
- phpunit/phpunit[4.8.0, ..., 4.8.36] require symfony/yaml ~2.1|~3.0 -> satisfiable by symfony/yaml[v2.1.0, ..., v2.8.52, v3.0.0, ..., v3.4.47].
- You can only install one version of a package, so only one of these can be installed: symfony/yaml[v2.1.0, ..., v2.8.52, v3.0.0, ..., v3.4.47, v5.2.1, ..., v5.4.11].
- craftcms/cms 3.7.27.2 requires symfony/yaml ^5.2.1 -> satisfiable by symfony/yaml[v5.2.1, ..., v5.4.11].
- Conclusion: don't install symfony/yaml[v5.3.14] | install symfony/yaml[v3.4.47] (conflict analysis result)

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.