2017 © Pedro Peláez
 

library weblibs-dbabstraction

Abstraction library for the database and ORM modules

image

clagiordano/weblibs-dbabstraction

Abstraction library for the database and ORM modules

  • Wednesday, February 15, 2017
  • by clagiordano
  • Repository
  • 0 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

BuildStatus License, (*1)

weblibs-dbabstraction

weblibs-dbabstraction is an simple and lightweight Abstraction library for the database and ORM modules., (*2)

SensioLabsInsight, (*3)

Why use weblibs-dbabstraction ?

The purpose of this project is to propose a simple and lightweight alternative solution instead of more big and complex projects such as Doctrine., (*4)

Installation

The recommended way to install weblibs-dbabstraction is through Composer., (*5)

composer require clagiordano/weblibs-dbabstraction

Description of the main components

Adapter description

Is a persistence layer which interact with database or other backends. An adapter class must be implements the DatabaseAdapterInterface for compatibility with other components.
The default adapter is the already defined PDOAdapter wich simplify the access to PDO object and related methods.
Other specific adapters can be implemented to easily access to other backends., (*6)

Adapter usage

new PDOAdapter(
    $dbHost,
    $dbUser,
    $dbPassword,
    $dbName,
    $dbDriver,
    $dbCharset,
    $isPersistent
);

See PDOAdapterTest class (phpunit test class) for full sample usage into tests folder., (*7)

Entity description

An entity is an object which expose properties dynamically generated from an array of fields. It is a simple class which have defined the magic methods (__set, __get ... ).
The entity is automatically used by the mapper class for the operations and can be used to gets and sets its properties.
For more details please see the SampleEntity class into testdata folder., (*8)

Entity usage

An entity class must be extends AbstractEntity as:, (*9)

/**
 * Class SampleEntity
 */
class SampleEntity extends AbstractEntity
{
}

Then can be used:, (*10)

$entityClass->property = "value";
echo $entityClass->property;

Mapper description

A mapper is a glue between Entity and Adapter objects which expose high level method to use and persists data.
A mapper class must be extends the AbstractMapper:, (*11)

/**
 * Class SampleMapper
 */
class SampleMapper extends AbstractMapper
{

then must be declare two protected properties to connect database table for persistence and the related entity class:, (*12)

protected $entityTable = 'sample_table';
protected $entityClass = 'SampleEntity';

therefore must be implements the abstract method createEntity for the correct mapping between table fields and the desidered entity properties:, (*13)

protected function createEntity(array $fields)
{
    return new SampleEntity(
        [
            'id' => $fields['id'],
            'code' => $fields['code'],
            'brand' => $fields['brand'],
            'model' => $fields['model'],
            'description' => $fields['description']
        ]
    );
}

You can also define additional methods if necessary or override existing ones such as insert, update, delete etc to modify its behavior., (*14)

Mapper usage

To improve control and security AbstractMapper's methods can be overrided:, (*15)

/**
 * Sample overrided insert method
 *
 * @param SampleEntity $entity
 * @return mixed
 */
public function insert($entity)
{
    if (!$entity instanceof SampleEntity) {
        throw new \InvalidArgumentException(
            __METHOD__ . ": Invalid entity type."
        );
    }

    return $this->adapter->insert($this->entityTable, $entity->toArray());
}

As you can see, this overrided method require explicitly an instance of SampleEntity to works, the same way you can run a validation or additional arguments formatting/sanitizing or whatever you want., (*16)

Copyright (C) Claudio Giordano claudio.giordano@autistici.org, (*17)

The Versions

15/02 2017

dev-develop

dev-develop https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

orm database library entity pdo mysql abstraction clagiordano weblibs

13/02 2017

dev-master

9999999-dev https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

orm database library entity pdo mysql abstraction clagiordano weblibs

25/08 2016

v1.0.8

1.0.8.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

orm database library entity pdo mysql abstraction clagiordano weblibs

23/08 2016

v1.0.6

1.0.6.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

orm database library entity pdo mysql abstraction clagiordano weblibs

23/08 2016

v1.0.7

1.0.7.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

orm database library entity pdo mysql abstraction clagiordano weblibs

14/05 2016

v1.0.5

1.0.5.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

08/05 2016

v1.0.4

1.0.4.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

07/05 2016

v1.0.3

1.0.3.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

25/04 2016

v1.0.2

1.0.2.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

LGPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

30/03 2016

v1.0.1

1.0.1.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

30/03 2016

v1.0.0

1.0.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

30/03 2016

v0.9

0.9.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

28/03 2016

v0.8

0.8.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

25/03 2016

v0.7

0.7.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

16/03 2016

v0.6.1

0.6.1.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

16/03 2016

v0.6

0.6.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

16/03 2016

v0.5

0.5.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

14/03 2016

v0.4

0.4.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

23/01 2016

v0.3

0.3.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

20/01 2016

v0.2

0.2.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL3

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

19/01 2016

v0.1.1

0.1.1.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database and ORM modules

  Sources   Download

GPL3

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano

19/01 2016

v0.1

0.1.0.0 https://github.com/clagiordano/weblibs-dbabstraction.git

Abstraction library for the database

  Sources   Download

GPL3

The Requires

  • php >=5.4

 

The Development Requires

by Claudio Giordano