Download the PHP package clagiordano/weblibs-dbabstraction without Composer
On this page you can find all versions of the php package clagiordano/weblibs-dbabstraction. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download clagiordano/weblibs-dbabstraction
More information about clagiordano/weblibs-dbabstraction
Files in clagiordano/weblibs-dbabstraction
Package weblibs-dbabstraction
Short Description Abstraction library for the database and ORM modules
License LGPL-3.0
Homepage https://github.com/clagiordano/weblibs-dbabstraction.git
Informations about the package weblibs-dbabstraction
weblibs-dbabstraction
weblibs-dbabstraction is an simple and lightweight Abstraction library for the database and ORM modules.
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.
Installation
The recommended way to install weblibs-dbabstraction is through Composer.
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.
Adapter usage
See PDOAdapterTest class (phpunit test class) for full sample usage into tests folder.
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.
Entity usage
An entity class must be extends AbstractEntity as:
Then can be used:
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:
then must be declare two protected properties to connect database table for persistence and the related entity class:
therefore must be implements the abstract method createEntity for the correct mapping between table fields and the desidered entity properties:
You can also define additional methods if necessary or override existing ones such as insert, update, delete etc to modify its behavior.
Mapper usage
To improve control and security AbstractMapper's methods can be overrided:
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.
Legal
Copyright (C) Claudio Giordano [email protected]