ActiveRecord

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

The Active Record Component.

Example

<?php

use miBadger\ActiveRecord\AbstractActiveRecord;

/**
 * The user class.
 */
class User extends AbstractActiveRecord
{
    /** @var string The name. */
    private $name;

    /**
     * {@inheritdoc}
     */
    public function getActiveRecordTable()
    {
        return 'example';
    }

    /**
     * {@inheritdoc}
     */
    public function getActiveRecordColumns()
    {
        return [
            'name' => &$name
        ];
    }

    /**
     * Returns the name.
     *
     * @return string the name.
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the name.
     *
     * @param string $name
     * @return $this
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }
}
<?php

/**
 * Create an active record instance.
 */
$user = new User($pdo);

/**
 * Read the row with the given ID from the database.
 */
$user->read($id);

/**
 * Returns the name.
 */
$user->getName(); // John

/**
 * Set a new name.
 */
$user->setName('Jane');

/**
 * Synchronize the active record with the database.
 */
$user->sync();