Skip to content

Commit

Permalink
Skeleton of marshaller.
Browse files Browse the repository at this point in the history
Add safe mode as I hope to re-use the same marshalling code for building
enities from statements as well as building entities from request data.
  • Loading branch information
markstory committed Dec 11, 2013
1 parent bd5029a commit 433815e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
73 changes: 73 additions & 0 deletions Cake/ORM/Marshaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\ORM;

use Cake\ORM\Table;

/**
* Contains logic to convert array data into entities.
*
* Useful when converting request data into entities.
*
* @see Cake\ORM\Table::newEntity()
* @see Cake\ORM\Table::newEntities()
*/
class Marshaller {

/**
* Whether or not this marhshaller is in safe mode.
*
* @var boolean
*/
protected $_safe;

/**
* The table instance this marshaller is for.
*
* @var Cake\ORM\Table
*/
protected $_table;

/**
* Constructor.
*
* @param Cake\ORM\Table $table
*/
public function __construct(Table $table, $safe = false) {
$this->_table = $table;
$this->_safe = $safe;
}

/**
* Hydrate one entity and its associated data.
*
* @param array $data The data to hydrate.
* @param array $associations The associations to include.
* @return Cake\ORM\Entity
*/
public function one(array $data, $associations = []) {
}

/**
* Hydrate many entities and their associated data.
*
* @param array $data The data to hydrate.
* @param array $associations The associations to include.
* @return array An array of hydrated records.
*/
public function many(array $data, $associations = []) {
}

}
7 changes: 5 additions & 2 deletions Cake/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1509,10 +1509,13 @@ public function __call($method, $args) {
* Override this method if you want a table object to use custom
* marshalling logic.
*
* @param boolean $safe Whether or not this marshaller
* should be in safe mode.
* @return Cake\ORM\Marhsaller;
* @see Cake\ORM\Marshaller
*/
public function marshaller() {
return new Marshaller($this);
public function marshaller($safe = false) {
return new Marshaller($this, $safe);
}

/**
Expand Down

0 comments on commit 433815e

Please sign in to comment.