2017 © Pedro Peláez
 

library properties

A simple runtime package for handling properties on a class

image

benrowe/properties

A simple runtime package for handling properties on a class

  • Tuesday, June 5, 2018
  • by benrowe
  • Repository
  • 1 Watchers
  • 1 Stars
  • 535 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 13 Versions
  • 30 % Grown

The README.md

Properties

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Adds the ability to add properties to a class at runtime., (*2)

Install

Via Composer, (*3)

``` bash $ composer require benrowe/properties, (*4)


## Usage ``` php class Sample extends AbstractBase { public function __construct() { // do stuff $this->configureProperties(); // properties now available } /** * This method is automatically called by AbstractBase once * the constructor has finished executing */ public function configureProperties() { $this-> addProperty('simple') $this ->addProperty('complex', 'string', 'default value') ->setter(function($value) { return trim($value); }) ->getter(function($value) { return str_reverse($value); }) ->validate(function ($value) { return strlen($value) > 0; }); } } $sample = new Sample; $sample->simple = 'test'; $sample->undefined = 'newval'; // throws PropertyException "Undefined property 'undefined'" $sample->complex; // 'default value' $sample->complex = ''; // throws PropertyException "property 'complex' invalid value on set" $sample->complex = ' hello world'; echo $sample->complex; //'dlrow olleh';

Each property is defined programatically (at runtime), and requires the class to run this code (with a hook)., (*5)

Each property can have a, (*6)

  • name:string
  • data type(s): string
  • validation: string|closure
  • setter: closure
  • getter:string
  • default value (null): mixed
  • value: mixed (depends on data type/validation/setter)

TODO

  • add the ability for a setter to reject a value by throwing an exception
  • build custom validation support for setting the value
    • instead of providing a closure for the setter, provide a laravel style validation string.
    • add a helper function to restrict the setter to a list of known values $this->addProperty('key')->isIn(['foo', 'bar']);

Change log

Please see CHANGELOG for more information what has changed recently., (*7)

Testing

bash $ composer test, (*8)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*9)

Security

If you discover any security related issues, please email ben.rowe.83@gmail.com instead of using the issue tracker., (*10)

Credits

License

The MIT License (MIT). Please see License File for more information., (*11)

The Versions

05/06 2018

dev-master

9999999-dev https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties benrowe strict strict-typing

05/06 2018

1.1.1

1.1.1.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

18/05 2018

1.1.0

1.1.0.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

18/05 2018

dev-feature/add-type-checker

dev-feature/add-type-checker https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

07/05 2018

1.0.2

1.0.2.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

01/05 2018

1.0.1

1.0.1.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

28/04 2018

1.0.0

1.0.0.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

28/04 2018

dev-feature/type-handling

dev-feature/type-handling https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.1

 

The Development Requires

command properties strict strict-typing

14/07 2017

dev-feature/test

dev-feature/test https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

properties benrowe

05/07 2017

dev-feature/code-coverage

dev-feature/code-coverage https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

properties benrowe

27/03 2017

0.1.2

0.1.2.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

properties benrowe

22/03 2017

0.1.0

0.1.0.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

properties benrowe

22/03 2017

0.1.1

0.1.1.0 https://github.com/benrowe/properties

A simple runtime package for handling properties on a class

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

properties benrowe