2017 © Pedro Peláez
 

library lazydata

Provides lazy loading of data to views. Dot notation can be used.

image

laasti/lazydata

Provides lazy loading of data to views. Dot notation can be used.

  • Wednesday, November 16, 2016
  • by nebulousGirl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 283 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 18 Versions
  • 4 % Grown

The README.md

Laasti/Lazydata

Provides lazy loading of data to views. Dot notation can be used., (*1)

Installation

composer require laasti/lazydata

Usage

All PHP callables are supported. To pass arguments to calls, use an array like ['my_callable', [/* args here */]]., (*2)

Without League\Container:, (*3)


$data = [ 'title' => 'render_title', 'with_arguments' => ['=my_callable', [/* args here */]], 'with_class' => ['=my_class', 'my_function'], //or '=my_class::my_function', 'with_object' => [$object, 'my_function'], 'meta' => function() { return [ 'description' => 'My description' ] } ]; $viewdata = new Laasti\Lazydata\Data($data); $viewdata->set('username', function() {return 'George';}); //You can use dot notation within the lazy loaded data $viewdata->get('meta.description'); //Returns 'My description'

Using filters, you can define your own filter with setFilter or use native PHP functions that take one string argument., (*4)

    $data = [
        'native_example' => 'strtoupper:test', //I know, it's a stupid example :P
        'closure_example' => 'closure:Test',
    ];
    $resolver = new \Laasti\Lazydata\Resolvers\FilterResolver;
    $resolver->setFilter('closure', function($value) {
        return md5($value.'MYSALT');
    });
    $viewdata = new Laasti\Lazydata\Data($data, $resolver);

    $viewdata->get('native_example'); //Returns 'TEST'
    $viewdata->get('closure_example'); //Returns '56e29f03228697ad59822c71eb4d7750'

With league/container:, (*5)


//We need to setup the ContainerResolver that comes with the package $container = new League\Container\Container; $container->add('Laasti\Lazydata\Resolvers\ResolverInterface', 'Laasti\Lazydata\Resolvers\ContainerResolver')->withArgument($container); $container->add('Laasti\Lazydata\Data')->withArguments([[], 'Laasti\Lazydata\Resolvers\ResolverInterface']); $viewdata = $container->get('Laasti\Lazydata\Data);; $container->add('container_key', 'some value'); $viewdata->set('viewdata_key', '=container_key'); $viewdata->get('viewdata_key'); //Returns 'some value' //Returns the value from SomeClass->myMethod();, SomeClass is resolved with the container $viewdata->set('viewdata_callable_key', '=SomeClass::myMethod'); $viewdata->get('viewdata_callable_key'); //Returns the value from SomeClass->myMethod('George'); SomeClass is resolved with the container $viewdata->set('viewdata_callable_args_key', ['=SomeClass::myMethod', ['George']]); $viewdata->get('viewdata_callable_args_key');

The ContainerResolver falls back on the default resolver if it cannot resolve the call., (*6)

Note: Does not work with league/container invokables. It is a limitation due to the way registered callables are stored, there is no way to check if a callable is registered to the container in the public API., (*7)

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

See CHANGELOG.md for more information., (*8)

Credits

Author: Sonia Marquette (@nebulousGirl), (*9)

License

Released under the MIT License. See LICENSE.txt file., (*10)

The Versions

16/11 2016

dev-master

9999999-dev

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

16/11 2016

v0.6.3

0.6.3.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

15/11 2016

v0.6.2

0.6.2.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

23/10 2016

v0.6.1

0.6.1.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

09/03 2016

v0.6

0.6.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

14/01 2016

v0.5.6

0.5.6.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

14/01 2016

v0.5.5

0.5.5.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

13/01 2016

v0.5.4

0.5.4.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

13/01 2016

v0.5.3

0.5.3.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

29/12 2015

v0.5.2

0.5.2.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

22/12 2015

v0.5.1

0.5.1.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

04/11 2015

v0.5

0.5.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

27/10 2015

v0.4.2

0.4.2.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

12/10 2015

v0.4.1

0.4.1.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

27/09 2015

v0.4

0.4.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

24/09 2015

v0.3

0.3.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

22/09 2015

v0.2

0.2.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Development Requires

23/08 2015

v0.1

0.1.0.0

Provides lazy loading of data to views. Dot notation can be used.

  Sources   Download

MIT

The Requires

 

The Development Requires