PHPackages                             chippyash/record-status - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chippyash/record-status

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chippyash/record-status
=======================

Class Status Management

1.0.2(8y ago)02.4k11(GPL V3+ and Proprietary)PHPPHP &gt;=5.6CI failing

Since Dec 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/chippyash/record-status)[ Packagist](https://packagist.org/packages/chippyash/record-status)[ Docs](http://zf4.biz/packages?utm_source=packagist&utm_medium=web&utm_campaign=blinks&utm_content=identity)[ RSS](/packages/chippyash-record-status/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (4)Used By (1)

chippyash/RStatus
=================

[](#chippyashrstatus)

Quality Assurance
-----------------

[](#quality-assurance)

[![PHP 5.6](https://camo.githubusercontent.com/88093c79af42bd3c07f4d6aa378289e1f5450411c56753b0323bd7d8b9b1f9ee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d626c75652e737667)](https://camo.githubusercontent.com/88093c79af42bd3c07f4d6aa378289e1f5450411c56753b0323bd7d8b9b1f9ee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d626c75652e737667)[![PHP 7](https://camo.githubusercontent.com/d23ce60b89c28c023d0ca69981ec9afbb17eb08a9cd1b609fd84c15d0732b7ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372d626c75652e737667)](https://camo.githubusercontent.com/d23ce60b89c28c023d0ca69981ec9afbb17eb08a9cd1b609fd84c15d0732b7ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372d626c75652e737667)[![Build Status](https://camo.githubusercontent.com/542e6eae3b3c597a1f8041dcbb560fa17563e60e007217f20dbf167743d02c73/68747470733a2f2f7472617669732d63692e6f72672f6368697070796173682f7265636f72642d7374617475732e737667)](https://travis-ci.org/chippyash/record-status)[![Test Coverage](https://camo.githubusercontent.com/9518db3fb3624512dbe52d3ad57a4e39c7f028b1fca8ea8e5980d6670f3364da/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61613031646464356430663363636430653133372f746573745f636f766572616765)](https://codeclimate.com/github/chippyash/record-status/test_coverage)[![Maintainability](https://camo.githubusercontent.com/2e82678cf1d85078471971f74a794e5d8ab7a283559ff7727d894332f2f79b63/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61613031646464356430663363636430653133372f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/chippyash/record-status/maintainability)

See the [Test Contract](https://github.com/chippyash/record-status/blob/master/docs/Test-Contract.md)

What?
-----

[](#what)

Provides a simple helper capability for managing record or class status

Why?
----

[](#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.

This small library provides the interfaces and traits to add a status functionality to any class.

### Roadmap

[](#roadmap)

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

Check out [ZF4 Packages](http://zf4.biz/packages?utm_source=github&utm_medium=web&utm_campaign=blinks&utm_content=record-status) for more packages

How
---

[](#how)

A record can be in one of three states:

- 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](https://www.google.co.uk/search?q=dictionary+defunct&oq=dictionary+defunct&aqs=chrome..69i57j0.6782j1j7&sourceid=chrome&ie=UTF-8)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.

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.

### Coding Basics

[](#coding-basics)

#### Record Status Enum class

[](#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](https://github.com/myclabs/php-enum)library.

```
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

[](#enabling-recordstatus-for-your-class)

Have your class implement the RecordStatusRecordable interface. Use the RecordStatusRecording trait as a convenient implementation of the interface.

```
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:

```
/**
 * 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

[](#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?

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

NB. Make sure you rebase to HEAD before your pull request

Or - raise an issue ticket.

Where?
------

[](#where)

The library is hosted at [Github](https://github.com/chippyash/record-status). It is available at [Packagist.org](https://packagist.org/packages/chippyash/record-status)

### Installation

[](#installation)

Install [Composer](https://getcomposer.org/)

#### For production

[](#for-production)

```
    "chippyash/record-status": ">=1,
