PHP Classes
elePHPant
Icontem

Caribu ORM: Map objects to databases records using annotations

Recommend this page to a friend!
  Info   View files Example   View files View files (72)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2017-08-22 (16 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: 248 This week: 5All time: 7,541 This week: 127Up
Version License PHP version Categories
caribu 1.6BSD License7PHP 5, Databases, Design Patterns
Description Author

This package can map objects to databases records using annotations.

It provides base classes that can store and retrieve objects from database tables. The base classes should be extended by implementation classes.

The object-relational mapping information is extracted from annotation comments read from the implementation classes as well using PHP reflection. So it is possible to map complex datatypes such as DateTime into database column datatypes seamlessly.

The ORM classes provide means to retrieve, store and remove objects from the configured database tables. It supports MySQL, Postgresql and SQLite using PDO.

It supports objects that reference other objects, allowing to save also the referenced objects when a given object is saved if the relationship is set to @cascade.

The package also supports mapping classes to existing database tables using the attributes @id, @table and @column to define class mapping to legacy tables.

Recommendations

Map database records to objects
Store and retrieve objects without writing native SQL again

Innovation Award
PHP Programming Innovation award nominee
May 2015
Number 11
Annotations are useful information that can be added to classes to perform other tasks besides running the class code.

This package implements object-relational mapping that reads information about the mappings from annotation comments in the class code. It can work to map objects to existing legacy database tables.

Manuel Lemos
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

Details

Build Status Code Coverage Scrutinizer Code Quality Dependency Status Codacy Badge

caribu

An annotation-based PHP Object Relational Mapper

This project aims to be an object relational mapper easy to use. The main target is to support developers writing only simple attribute containing classes and store it as entities into a database.

It has support for annotations so it is very flexible.

Here is a very basic example about the usage (for sqlite):

    CREATE TABLE super_duper_content (id INTEGER PRIMARY KEY, content TEXT);

    /SuperDuperEntity.php/
    
    /
     * @table super_duper_content
     */
    class SuperDuperEntity extends AbstractModel
    {
      /
       * @column id
       */
      private $sid;
      
      private $content;
      
      public function setSid($sid)
      {
        $this->sid = $sid;
      }
      
      public function getSid()
      {
        return $this->sid;
      }
      
      public function setContent($content)
      {
        $this->content = $content;
      }
      
      public function getContent()
      {
        return $this->content;
      }
    }

    /write-data-example.php/
    
    use \Nkey\Caribu\Orm\Orm;
    
    /First configure the ORM/
    Orm::configure(array(
      'type' => 'sqlite',
      'file' => ':memory:'
    ));
    
    // Create sqlite database table for memory storage
    // Orm::getInstance()->getConnection()->exec("CREATE TABLE super_duper_content (id INTEGER PRIMARY KEY, content TEXT)");
    
    /Now create a new entity and persist it to database/
    $entity = new SuperDuperEntity();
    $entity->setContent("Mega important content");
    $entity->persist();

    /read-data-example.php/
    
    /First read the entity from database/
    $entity = SuperDuperEntity::find(array('content' => "Mega important content"));
    
    /Display the content/
    echo $entity->getContent();

No need to write infrastructure and boilerblate code by yourself. Let the Orm do the hard work for you.

Caribu provides a convention-over-configuration behaviour by supporting annotations.

See the Wiki for more information about the capabilities and usage.

  Files folder image Files  
File Role Description
Files folder imagecontrib (2 files)
Files folder imagesrc (3 directories)
Files folder imagetests (4 files, 5 directories)
Accessible without login Plain text file .gitignore Data Ignore list
Accessible without login Plain text file .travis.yml Data Travis ci configuration
Accessible without login Plain text file build.xml Data Build script
Accessible without login Plain text file composer.json Data Composer dependencies
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file phpcs.xml Data Code style configuration
Accessible without login Plain text file phpdox.xml Data phpdox configuration
Accessible without login Plain text file phpmd.xml Data Mess detection configuration
Accessible without login Plain text file phpunit.xml Data PHPUnit configuration
Accessible without login Plain text file README.md Doc. Readme

Downloadcaribu-2017-08-22.zip 65KB
Downloadcaribu-2017-08-22.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Generics Download .zip .tar.gz Logging & Interpolation Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:248
This week:5
All time:7,541
This week:127Up