Ejemplo n.º 1
0
	public function cast($entity, array $data, array $options = array()) {
		$defaults = array('schema' => null, 'first' => false);
		$options += $defaults;
		$model = null;
		$exists = false;

		if (!$data) {
			return $data;
		}

		if (is_string($entity)) {
			$model = $entity;
			$entity = null;
			$options['schema'] = $options['schema'] ?: $model::schema();
		} elseif ($entity) {
			$options['schema'] = $options['schema'] ?: $entity->schema();
			$model = $entity->model();

			if (is_a($entity, $this->_classes['entity'])) {
				$exists = $entity->exists();
			}
		}
		$schema = $options['schema'] ?: array('_id' => array('type' => 'id'));
		unset($options['schema']);

		$exporter = $this->_classes['exporter'];
		$options += compact('model', 'exists') + array('handlers' => $this->_handlers);
		return parent::cast($entity, $exporter::cast($data, $schema, $this, $options), $options);
	}