PHPackages                             yucca/yucca - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yucca/yucca

ActiveLibrary[Database &amp; ORM](/categories/database)

yucca/yucca
===========

simple multi-sources ORM for PHP 5.3

1.7.0(7y ago)301.9k5[8 issues](https://github.com/yucca-php/yucca/issues)1MITPHPPHP &gt;=5.3.0CI failing

Since Mar 11Pushed 7y ago6 watchersCompare

[ Source](https://github.com/yucca-php/yucca)[ Packagist](https://packagist.org/packages/yucca/yucca)[ Docs](http://github.com/yucca-php/yucca)[ RSS](/packages/yucca-yucca/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (8)Used By (1)

[![Build Status](https://camo.githubusercontent.com/94a59d149588c64087afba74751f226407d1de5870bdbe3ec4758b9f88dcd374/68747470733a2f2f7472617669732d63692e6f72672f79756363612d7068702f79756363612e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/yucca-php/yucca)[![Coverage Status](https://camo.githubusercontent.com/cd5c15320bcb2dcfc78afd339dc4b4f07fc0dca32da51a67b8cb03cfb9a27b2d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f79756363612d7068702f79756363612f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/yucca-php/yucca?branch=master)

Yucca
=====

[](#yucca)

Doctrine and Propel are well known ORM, they are great for websites which doesn't need hard optimizations. But which ORM can you choose :

- when you have a site that handle 500 concurrent connections ?
- when you have sharded databases ?
- when you have datas simultaneously in SQL DB (MySQL, PostgreSQL, ...) and NoSql (Mongo, Redis, Memcache, Neo4J, ...) ?

Philosophy
==========

[](#philosophy)

Yucca is designed to separate the PHP Model and the database Schema. Most of actual ORM maps strictly the design of a table to the object properties. But is it really logic ? Can't a model aggregate multiple tables ? And why an object should be mapped to a table and not simultaneously to multiple table or a table and a cache layer ?

That's the reasons that makes me create Yucca.

Model
-----

[](#model)

A Yucca Model is an active record that is linked to one or more datasources. For example, if you have a `user` table designed like this:

```
id INT PRIMARY
login VARCHAR(255)
password CHAR(40)

```

and a `user_params` table (which can handle fields like facebook\_id or site theme to use for example) designed like this:

```
id INT PRIMARY
user_id INT
param_name VARCHAR(40)
param_value TEXT

```

You can tell yucca that the model `User` has 2 different sources mapped: `user` and `user_params`

Each of these sources have one or more handlers: `user` source can read it's data from memcache and from a MySQL database. If memcache doesn't have datas, we check the next one (MySQL) and if it has datas, we bring them to memcache and after hydrate our model.

Actually, 2 handlers are given: memcache and DoctrineDbal

The DoctrineDbal handler use schema information to know which table read. Table information are for sharded tables. On huge systems, we can have for example 10 sharded tables representing the user. so for each shard we specify the connection to use. Yucca select the shard using the given shard strategy.

To summarize, we have to configure:

- connections
- schema
- source
- mapping

See more in the configuration section

Models are hydrated by a lazy loading system. This imply that getting an object with a given id doesn't make any call to the storage. The first call / connection will occur when getting or setting a property.

The model can only be accessed by it's id, which is the DB primary key (maybe an array of 2 or more fields), or the key in case of a Key/Value storage. By this way we can cache a row of data easily.

In case of reqesting a model by another field, we use Selectors and Iterators.

Selector
--------

[](#selector)

A selector is a way of retrieving models by another field than the id. But Selector doesn't retrieve datas, they only retrieve ids. So we can get model by their ids and use cache.

Iterator
--------

[](#iterator)

An iterator use a selector to get Ids and a SINGLE model (by default) which is hydrated, to preserve memory.

Getting started
===============

[](#getting-started)

The recommended way to install Yucca is through composer. If you don't know this tool, please look at [its documentation](https://getcomposer.org/)

Just create a `composer.json` file for your project, or update yours with this require statement:

```
{
    "require": {
        "yucca/yucca": "@stable"
    }
}
```

**Protip:** you should browse the [`yucca/yucca`](https://packagist.org/packages/yucca/yucca)page to choose a stable version to use, avoid `dev-master`

And run these two commands to install it:

```
$ curl -sS https://getcomposer.org/installer | php
$ composer install
```

When using Symfony2, you just have to register the bundle in the AppKernel:

```
// app/AppKernel.php

public function registerbundles()
{
    $bundles = array(
        //...
        new Yucca\Bundle\YuccaBundle\YuccaBundle(),
        //...
    );
}
```

**Protip:** Yucca is mostly intended to be use with Symfony2 and it's dependency injection. If you are not using Symfony2, you'll have to emulate the Yucca Bundle feature to be run in your application. In addition you will have to require the composer autoloader:

```
