2017 © Pedro Peláez
 

library record-status

Class Status Management

image

chippyash/record-status

Class Status Management

  • Tuesday, January 9, 2018
  • by chippyash
  • Repository
  • 1 Watchers
  • 0 Stars
  • 626 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 77 % Grown

The README.md

chippyash/RStatus

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 managing record or class status, (*3)

Why?

When dealing with database records, there is often a case for never deleting the record. This can be because you either don't want to lose the data, or you need it in place to ensure referential integrity with other data., (*4)

This small library provides the interfaces and traits to add a status functionality to any class., (*5)

Roadmap

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

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

How

A record can be in one of three states:, (*8)

  • active. An active record can have be changed to suspended or defunct
  • suspended. A suspended record can be changed to active of defunct. You should not change the attributes of a suspended reord.
  • defunct. A defunct record or class cannot have its state changed. This analogous to being deleted, except that the record data remains intact. You must not change the attributes of a defunct record.

Whilst the library provides support to manage the record status, you should also bear in mind that you will need to provide additional support to check the status in any of your other methods in a class., (*9)

In the docs directory, you'll also find an example trigger that you can use in MySql or MariaDb database server to maintain status integrity., (*10)

Coding Basics

Record Status Enum class

The Chippyash\RStatus\RecordStatus class is provided to provide the three possible states as a an Enum(erator) using the MyCLabs Enum library., (*11)

use Chippyash\RStatus\RecordStatus;

//create status objects
$status = RecordStatus::ACTIVE();
$status = RecordStatus::SUSPENDED();
$status = RecordStatus::DEFUNCT();

//test if status can be changed
if ($status->canChange()) {
    //....
}

Enabling RecordStatus for your class

Have your class implement the RecordStatusRecordable interface. Use the RecordStatusRecording trait as a convenient implementation of the interface., (*12)

use Chippyash\RStatus\RecordStatusRecordable;
use Chippyash\RStatus\RecordStatusRecording;

class MyRecord implements RecordStatusRecordable
{
    use RecordStatusRecording;
}

The RecordStatusRecording trait provides a protected $recordStatus propertyand the following methods:, (*13)

/**
 * Return the record status
 *
 * @return RecordStatus
 */
public function getStatus();

/**
 * Set the record status
 *
 * @param RecordStatus $status
 *
 * @return $this
 *
 * @throws RecordStatusException
 */
public function setStatus(RecordStatus $status);

/**
 * Is record status == active
 *
 * @return bool
 */
public function isStatusActive();

/**
 * Is record status == suspended
 *
 * @return bool
 */
public function isStatusSuspended();

/**
 * Is record status == defunct
 *
 * @return bool
 */
public function isStatusDefunct();

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?, (*14)

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

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

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

Where?

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

Installation

Install Composer, (*18)

For production

<, (*19)

pre> "chippyash/record-status": ">=1,<2" , (*20)

For development

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

    git clone git@github.com:chippyash/record-status.git
    cd record-status
    composer install

To run the tests:, (*22)

    cd record-status
    vendor/bin/phpunit -c test/phpunit.xml test/

License

This software library is released under the GNU GPL V3 or later license, (*23)

This software library is Copyright (c) 2017, Ashley Kitson, UK, (*24)

A commercial license is available for this software library, please contact the author. It is normally free to deserving causes, but gets you around the limitation of the GPL license, which does not allow unrestricted inclusion of this code in commercial works., (*25)

History

V1.0.0 Original release, (*26)

V1.0.1 build integration, (*27)

V1.0.2 typos, (*28)

The Versions

09/01 2018

dev-master

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

Class Status Management

  Sources   Download

(GPL V3+ and Proprietary)

The Requires

 

The Development Requires

class status record

09/01 2018

1.0.2

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

Class Status Management

  Sources   Download

(GPL V3+ and Proprietary)

The Requires

 

The Development Requires

class status record

31/12 2017

1.0.1

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

Class Status Management

  Sources   Download

(GPL V3+ and Proprietary)

The Requires

 

The Development Requires

class status record

31/12 2017

1.0.0

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

Class Status Management

  Sources   Download

(GPL V3+ and Proprietary)

The Requires

 

The Development Requires

class status record