2017 © Pedro PelĂĄez
 

library object-attribute-container

Allows to attach some attributes to objects

image

lukaszmakuch/object-attribute-container

Allows to attach some attributes to objects

  • Thursday, March 10, 2016
  • by lukaszmakuch
  • Repository
  • 1 Watchers
  • 0 Stars
  • 63 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ObjectAttributeContainer

Allows to associate attributes with objects., (*1)

Getting package

$ composer require lukaszmakuch/object-attribute-container

Working with the object attribute container

<?php

use lukaszmakuch\ObjectAttributeContainer\ObjectAttributeContainer;
use lukaszmakuch\ObjectAttributeContainer\Exception\AttributeNotFound;
use lukaszmakuch\ObjectAttributeContainer\Exception\ImpossibleToAddAttributes;

/* @var $attrContainer \ObjectAttributeContainer */

//create a test object
$obj = new \stdClass();

//associate parameters with the object
try {
    $attrContainer->addObjAttrs(
        $obj,
        ["attr-key" => "attr-val"]
    );
} catch (ImpossibleToAddAttributes $e) {
    //...
}

//check if there's a parameter with the given name
$attrContainer->objHasAttr($obj, "attr-key"); //true

//get that parameter value
try {
    $attrContainer->getObjAttrVal($obj, "attr-key"); //attr-val
} catch (AttributeNotFound $e) {
    //...
}

//remove that parameter
try {
    $attrContainer->remObjAttr($obj, "attr-key");
} catch (AttributeNotFound $e) {
    //...
}

Getting an instance of the container

<?php

use lukaszmakuch\ObjectAttributeContainer\Impl\ObjectAttributeContainerImpl;
use lukaszmakuch\ObjectAttributeContainer\Impl\ObjectAttributeContainerProxy;

//default
$container = new ObjectAttributeContainerImpl();

//proxy
$containerProxy = new ObjectAttributeContainerProxy();

More information

For more details check interfaces and test cases., (*2)

The Versions

10/03 2016

dev-master

9999999-dev

Allows to attach some attributes to objects

  Sources   Download

MIT

The Development Requires

10/03 2016

v0.1

0.1.0.0

Allows to attach some attributes to objects

  Sources   Download

MIT

The Development Requires