2017 © Pedro Peláez
 

library identity

Class Identity Management

image

chippyash/identity

Class Identity Management

  • Thursday, July 5, 2018
  • by chippyash
  • Repository
  • 1 Watchers
  • 0 Stars
  • 610 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 63 % Grown

The README.md

chippyash/Identity

Quality Assurance

PHP 5.6 PHP 7 Build Status Test Coverage Maintainability, (*1)

See the Test Contract, (*2)

What?

Provides a simple helper capability for class Identity management, (*3)

Why?

This is one of those bits of code you write over and over. Many applications require the classes they use to have some form of Identity. Typically in data driven applications this will equate to the id primary key field. This library provides support for that., (*4)

Roadmap

If you want more, either suggest it, or better still, fork it and provide a pull request., (*5)

Check out ZF4 Packages for more packages, (*6)

How

Coding Basics

The code is supplied as an interface and a trait. Simply declare your class as implementing the Identifiable interface and then use the Identifying trait in the class to supply the functionality., (*7)

Identities are based on Chippyash\Type\Interfaces\TypeInterface. This allows for strong typing and enforcement of identity rules. For instance, here is an example of a product id that is a fixed length digit string., (*8)

use Chippyash\Type\String\DigitType;

/**
 * A unique identifier
 */
class Identifier extends DigitType
{
    /**
     * Length of product id, it will be front padded with zeros to this length
     * or cut to this length
     *
     * @var int
     */
    protected $length = 10;

    /**
     * @return int
     */
    public function getLength()
    {
        return $this->length;
    }

    /**
     * @param mixed $value
     *
     * @return string
     */
    protected function typeOf($value)
    {
        $v = parent::typeOf($value);
        if (strlen($v) > $this->length) {
            return substr($v, -$this->length);
        }

        return str_pad($v, $this->length, '0',STR_PAD_LEFT);
    }
}

Your class can then simpy use it thus:, (*9)

use Chippyash\Identity\Identifiable;
use Chippyash\Identity\Identifying;

class Product implements Identifiable
{
    use Identifying;
    
    public function __construct(Identifier $id)
    {
        $this->id = $id;
        //or maybe there is some other way of establishing the identity
    }
}

$product = new Product(new Identifier(53));
$id = $product->id(); // returns Identifier
$vId = $product->vId(); //returns '0000000053'
$vId = $product->id()->get(); //returns '0000000053'

Changing the library

  1. fork it
  2. write the test
  3. amend it
  4. do a pull request

Found a bug you can't figure out?, (*10)

  1. fork it
  2. write the test
  3. do a pull request

NB. Make sure you rebase to HEAD before your pull request, (*11)

Or - raise an issue ticket., (*12)

Where?

The library is hosted at Github. It is available at Packagist.org, (*13)

Installation

Install Composer, (*14)

For production

<, (*15)

pre> "chippyash/identity": ">=1,<2" , (*16)

For development

Clone this repo, and then run Composer in local repo root to pull in dependencies, (*17)

    git clone git@github.com:chippyash/identity.git
    cd identity
    composer update

To run the tests:, (*18)

    cd identity
    vendor/bin/phpunit -c test/phpunit.xml test/

License

This software library is released under the BSD 3 Clause license, (*19)

This software library is Copyright (c) 2015, Ashley Kitson, UK, (*20)

History

V1.0.0 Original release, (*21)

V1.0.1 Updates for build running, (*22)

V1.0.2 Documentation update, (*23)

V1.0.3 composer.json fix, (*24)

V1.0.4 dependency update, (*25)

V1.1.0 Change of license from GPL V3 to BSD 3 Clause, (*26)

The Versions

05/07 2018

dev-master

9999999-dev http://zf4.biz/packages?utm_source=packagist&utm_medium=web&utm_campaign=blinks&utm_content=identity

Class Identity Management

  Sources   Download

BSD-3-Clause (GPL V3+ and Proprietary) GPL-3.0-or-later

The Requires

 

The Development Requires

identity

05/07 2018
03/04 2018
30/12 2017