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  
Name: Maik Greubel <contact>
Classes: 6 packages by
Country: Germany Germany
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

  Files folder image Files  /  contrib  
File Role Description
  Accessible without login Plain text file phpcs.xsd Data Code style schema
  Accessible without login Plain text file phpunit.xsd Data PHPUnit schema

  Files folder image Files  /  src  
File Role Description
Files folder imageModel (1 file)
Files folder imageOrm (15 files)
Files folder imageType (6 files)

  Files folder image Files  /  src  /  Model  
File Role Description
  Plain text file AbstractModel.php Class Test model

  Files folder image Files  /  src  /  Orm  
File Role Description
  Plain text file Orm.php Class Caribu ORM main class
  Plain text file OrmAnnotation.php Class Caribu ORM annotation provider
  Plain text file OrmClassUtil.php Class Class analysis functionality
  Plain text file OrmConnection.php Class Connection related functionality
  Plain text file OrmDataType.php Class Data type enumeration
  Plain text file OrmDataTypeConverter.php Class Data type conversion provider
  Plain text file OrmEntityAnalyzer.php Class Entity analyzing functionality
  Plain text file OrmException.php Class Derived exception
  Plain text file OrmExceptionHandler.php Class Exception handling related functionality
  Plain text file OrmMapping.php Class Mapping functionality
  Plain text file OrmPersister.php Class Persisting functionality
  Plain text file OrmStatement.php Class Statement related functionality
  Plain text file OrmTransaction.php Class Transaction related functionality
  Plain text file OrmTypeUtil.php Class Type analysis functionality
  Plain text file OrmUtil.php Class Common utility functionality

  Files folder image Files  /  src  /  Type  
File Role Description
  Plain text file AbstractType.php Class Abstract database type
  Plain text file IType.php Class Database type interface
  Plain text file MySQL.php Class MySQL database type
  Plain text file Postgres.php Class PostgreSQL database type
  Plain text file Sqlite.php Class Sqlite database type
  Plain text file TypeFactory.php Class Database type factory

  Files folder image Files  /  tests  
File Role Description
Files folder imagecomplex-tests (9 files)
Files folder imagefailure-tests (6 files)
Files folder imageModel (13 files)
Files folder imagesimple-tests (2 files)
Files folder image_files (4 files)
  Accessible without login Plain text file AbstractDatabaseTestCase.php Test Abstract test case
  Accessible without login Plain text file demo.php Example Example
  Accessible without login Plain text file MySqlAbstractDatabaseTestCase.php Test Test case abstraction
  Accessible without login Plain text file PostgresAbstractDatabaseTestCase.php Test Abstract test case for postgresql

  Files folder image Files  /  tests  /  complex-tests  
File Role Description
  Accessible without login Plain text file ComplexTest.php Test Complex unit test
  Accessible without login Plain text file EntityListTest.php Test Referenced entity unit test
  Accessible without login Plain text file MySQLComplexTest.php Test Unit test for MySQL complex tests
  Accessible without login Plain text file MySQLEntityListTest.php Test MySQL test version of entity list unit test
  Accessible without login Plain text file MySQLPersistComplexTypesTest.php Test Unit test for complex type mapping in MySQL
  Accessible without login Plain text file PostgresComplexTest.php Test Unit test for postgresql
  Accessible without login Plain text file PostgresPersistComplexTypesTest.php Test Unit test for complex type mapping in Postgres
  Accessible without login Plain text file ReferencesTest.php Test Unit test for referencial persistence and retrieval
  Accessible without login Plain text file SimpleReferenceTest.php Test Relationship many-to-one unit test

  Files folder image Files  /  tests  /  failure-tests  
File Role Description
  Accessible without login Plain text file DuplicateIdTest.php Test Test duplicate id behaviour
  Accessible without login Plain text file FailureTest.php Test Failures unit test
  Accessible without login Plain text file InvalidConnectionSettingsTest.php Test Unit test for invalid connection settings
  Accessible without login Plain text file InvalidModelTest.php Test Unit test for invalid model
  Accessible without login Plain text file InvalidReferenceTest.php Test Unit test for invalid mapping
  Accessible without login Plain text file InvalidTypeTest.php Test Another failing unit test

  Files folder image Files  /  tests  /  Model  
File Role Description
  Accessible without login Plain text file AnnotatedGuestBookModel.php Test Annotation test model
  Accessible without login Plain text file Author.php Test Another unit test model
  Accessible without login Plain text file BlogPost.php Test Referenced entity test model
  Accessible without login Plain text file BlogUser.php Test Referenced entity test model
  Accessible without login Plain text file Book.php Test Another unit test model
  Accessible without login Plain text file GuestBookModel.php Test Test model
  Accessible without login Plain text file InvalidModel.php Test Test entity containing errors
  Accessible without login Plain text file InvalidReferenceModel.php Test Testing model for invalid mapping
  Accessible without login Plain text file MockedModel.php Test Test model
  Accessible without login Plain text file NoteModel.php Test Test model
  Accessible without login Plain text file ReferencedGuestBook.php Test Entity for referenced tests
  Accessible without login Plain text file User.php Test Entity for referenced tests
  Accessible without login Plain text file ValidNoteModel.php Test Test entity for valid tests

  Files folder image Files  /  tests  /  simple-tests  
File Role Description
  Accessible without login Plain text file NonAnnotationTestTest.php Test Unit test for non-annotated entities
  Accessible without login Plain text file SimpleTest.php Test Simple unit test

  Files folder image Files  /  tests  /  _files  
File Role Description
  Accessible without login Plain text file blog-seed.xml Data Referenced entity test data
  Accessible without login Plain text file guestbook-seed.xml Data Test data
  Accessible without login Plain text file notes-seed.xml Data Test data
  Accessible without login Plain text file referenced-guestbook-seed.xml Data Dataset for testing reference retrieval and persistence

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