sweiguny/php-persistence-api

Interface for PHP-Applications to access Object-Relational data.

dev-master 2021-03-18 07:56 UTC

README

Build Status

The PHP Persistence API (PPA) is an Interface for PHP-Applications to access Object-Relational data.

Note: this project currently underlies a huge refactoring process.

Features:

Features in spe:

  • Inheritance

Examples:

Configuring your entities:

namespace PPA\examples\entity;
use PPA\core\Entity;

/**
 * @table(name="role")
 */
class Role extends Entity {

    /**
     * @id
     * @column(name="id")
     */
    private $id;

    /** @column(name="name") */
    private $name;

    /**
     * @manyToMany(fetch = "eager", mappedBy = "_PPA_examples_entity_Right")
     * @joinTable(name = "role2right", column = "role_id", x_column = "right_id")
     */
    private $rights = array();
}

Retrieving data:

A TypedQuery can automatically resolve all the relations and give an appropriate output.

$query = new \PPA\core\query\TypedQuery("SELECT * FROM `role` WHERE id = 1", "\\PPA\\examples\\entity\\Role");
$query->getSingleResult();

Returns:
PPA\examples\entity\Role Object
(
    [id:PPA\examples\entity\Role:private] => 1
    [name:PPA\examples\entity\Role:private] => admin
    [rights:PPA\examples\entity\Role:private] => Array
        (
            [0] => PPA\examples\entity\Right Object
                (
                    [id:PPA\examples\entity\Right:private] => 3
                    [desc:PPA\examples\entity\Right:private] => ch-pw
                )
            [1] => PPA\examples\entity\Right Object
                (
                    [id:PPA\examples\entity\Right:private] => 1
                    [desc:PPA\examples\entity\Right:private] => login
                )
        )
)