imponeer/properties

Add a possibility to define class variables with strict data type behaviors

dev-main 2024-07-02 11:36 UTC

This package is auto-updated.

Last update: 2024-10-08 23:54:29 UTC


README

License GitHub release Build Status Packagist Maintainability Test Coverage

Properties

PHP library for handling strict type class variables. This package can be used only for adding functionality for other classes.

Installation

composer require imponeer/properties

Usage

To add some custom properties support to a class first you need to extend that class. Here is example how to do it:

use Imponeer\Properties;

class Base extends Properties {

}

Next thing what you need is to define variables in class constructor. Here an example how to do:

use Imponeer\Properties;

class Base extends Properties {

  public function __construct() {
    $this->initVar('varA', self::DTYPE_INTEGER, null, false);
    $this->initVar('varB', self::DTYPE_STRING, null, true, 150);
    $this->initVar('varC', self::DTYPE_INTEGER, 100, false);
  }
}

Than is possible to use such vars. This would work for previous example in such way:

// Creates instance
$obj = new Base();

// Print current objects vars
var_dump($obj->toArray());

// Modify vars with some integer values and prints
$obj->varA = 57;
$obj->varB = 58;
$obj->varC = 59;
var_dump($obj->toArray());

// Modify vars with some string values and prints
$obj->varA = "A";
$obj->varB = "B";
$obj->varC = "C";
var_dump($obj->toArray());

How to contribute?

If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, tryinteractive GitHub tutorial.

If you found any bug or have some questions, use issues tab and write there your questions.