UnionOfRAD/lithium — pull request #865 by jails (2013-03-25 17:34:42+00:00)
Title: Instanciation of `Document\DocumentSet` should be delegated to the model's connection when possible

Delegating instanciations to the datasource allow for example this kind of abstraction:

```php
/**
* Example of Single Table Inheritance implementation based on `'_type'`.
*/
class MongoDb extends \lithium\data\source\MongoDb {

public function item($model, array $data = array(), array $options = array()) {
$defaults = array('class' => 'entity');
$options += $defaults;

//Dynamically change the `$class` model according a `'_type'` field.
if (isset($data['_type']) && $data['_type']) {
list($namespace, $name) = preg_split("/\\\[^\\\]*$/", $model);
$model = $namespace . '\\' . Inflector::humanize(Inflector::pluralize($data['_type']));
if (!class_exists($model)) {
throw new RuntimeException("Class `{$model}` not found.");
}
}

$class = $options['class'];
unset($options['class']);
return $this->_instance($class, compact('model', 'data') + $options);
}
}
```