2017 © Pedro Peláez
 

library lazyaccess

Provides LazyAccess posiblity to array elements

image

p1ratrulezzz/lazyaccess

Provides LazyAccess posiblity to array elements

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

LazyAccess

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

LazyAccess is a wrapper around any arrays. Provides easy way of getting it's values or get a default value instead., (*2)

Replaces stupid long constructions like, (*3)

isset($var) ? $var : NULL.

Installation

Using composer

Update your composer.json with following:, (*4)

    require: {
        "p1ratrulezzz/lazyaccess": "master"
    }

and run, (*5)

composer install  

or (recommended), (*6)

composer require p1ratrulezzz/lazyaccess master

Second method will allow you to install this package without manual changes in composer.lock file., (*7)

Manual installation

git clone --branch master https://github.com/p1ratrulezzz/LazyAccess-to-PHP-arrays.git lazyaccess

Then in PHP code include the files, (*8)

require_once 'lazyaccess/src/LazyAccess.php';
require_once 'lazyaccess/src/LazyAccessTyped.php';

Description

For example: usual PHP code is, (*9)

$somevar = isset($array[$key]['key2'][0]) ? $array[$key]['key2'][0] : 'some_default_value';

This code is long and duplicates same things. With LazyAccess same code will be, (*10)

$wrapper = new LazyAccessTyped($array); //Define it once somewhere in your code
$somevar = $array[$key]->key2[0]->value('some_default_value');
//or
$somevar = $array[$key]['key2'][0]->value('some_default_value'); //the same as the above
//or
$somevar = $array->$key->key2->0->value('some_default_value'); //the same as the above
// Also there are some wrappers with types: asString(), asInteger(), asDouble()
$somevar = $array->{$key}->key2->0->asString('some_default_value');
$somevar = $array->{$key}->key2->0->asInteger(0); // It will perform intval() operation before returning, so you can be sure that there will be an integer value.
// asDouble() also will replace comma "," to a point ".", for example value 1,93 will be converted to 1.93
$floating_point_value = new LazyAccessTyped(['test_float' => ['inner' => '1,93']])->test_float->inner->asDouble(0); // Will return 1.93

It provides ability to use array operator ("[]") or object operator ("->") to access nesting array elements!, (*11)

Note

There are two classes LazyAccess and LazyAccessTyped. LazyAccessTyped provides ability to use converters such as asFloat(), asInteger() and etc., (*12)

Please, do not use LazyAccess, cause it can behave unpredictible with it's return value. LazyAccessTyped is much better and safer., (*13)

The Versions

05/04 2018

dev-master

9999999-dev

Provides LazyAccess posiblity to array elements

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0
  • php >=5.3.2

 

The Development Requires

26/11 2017

v2.0.x-dev

2.0.9999999.9999999-dev

Provides LazyAccess posiblity to array elements

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0
  • php >=5.3.2

 

The Development Requires

26/11 2017

2.0.2

2.0.2.0

Provides LazyAccess posiblity to array elements

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0
  • php >=5.3.2

 

The Development Requires

16/11 2017

2.0.1

2.0.1.0

Provides LazyAccess posiblity to array elements

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0
  • php >=5.3.2

 

The Development Requires

19/04 2016

2.0

2.0.0.0

Provides LazyAccess posiblity to array elements

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1.0
  • php >=5.3.2

 

The Development Requires