|
@@ -104,21 +104,18 @@ class Marshaller
|
|
|
$propertyMap = $this->_buildPropertyMap($options);
|
|
$propertyMap = $this->_buildPropertyMap($options);
|
|
|
|
|
|
|
|
$schema = $this->_table->schema();
|
|
$schema = $this->_table->schema();
|
|
|
- $tableName = $this->_table->alias();
|
|
|
|
|
$entityClass = $this->_table->entityClass();
|
|
$entityClass = $this->_table->entityClass();
|
|
|
$entity = new $entityClass();
|
|
$entity = new $entityClass();
|
|
|
$entity->source($this->_table->alias());
|
|
$entity->source($this->_table->alias());
|
|
|
|
|
|
|
|
- if (isset($data[$tableName])) {
|
|
|
|
|
- $data = $data[$tableName];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (isset($options['accessibleFields'])) {
|
|
if (isset($options['accessibleFields'])) {
|
|
|
foreach ((array)$options['accessibleFields'] as $key => $value) {
|
|
foreach ((array)$options['accessibleFields'] as $key => $value) {
|
|
|
$entity->accessible($key, $value);
|
|
$entity->accessible($key, $value);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $data = $this->_prepareData($data, $options);
|
|
|
|
|
+
|
|
|
$errors = $this->_validate($data, $options, true);
|
|
$errors = $this->_validate($data, $options, true);
|
|
|
$primaryKey = $schema->primaryKey();
|
|
$primaryKey = $schema->primaryKey();
|
|
|
$properties = [];
|
|
$properties = [];
|
|
@@ -186,6 +183,27 @@ class Marshaller
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Returns data prepared to validate and marshall.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $data The data to prepare.
|
|
|
|
|
+ * @param array $options The options passed to this marshaller.
|
|
|
|
|
+ * @return array Prepared data.
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function _prepareData($data, $options)
|
|
|
|
|
+ {
|
|
|
|
|
+ $tableName = $this->_table->alias();
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($data[$tableName])) {
|
|
|
|
|
+ $data = $data[$tableName];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $dataObject = new \ArrayObject($data);
|
|
|
|
|
+ $this->_table->dispatchEvent('Model.beforeMarshal', compact('dataObject', 'options'));
|
|
|
|
|
+
|
|
|
|
|
+ return (array)$dataObject;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Create a new sub-marshaller and marshal the associated data.
|
|
* Create a new sub-marshaller and marshal the associated data.
|
|
|
*
|
|
*
|
|
|
* @param \Cake\ORM\Association $assoc The association to marshall
|
|
* @param \Cake\ORM\Association $assoc The association to marshall
|
|
@@ -326,18 +344,15 @@ class Marshaller
|
|
|
{
|
|
{
|
|
|
$options += ['validate' => true];
|
|
$options += ['validate' => true];
|
|
|
$propertyMap = $this->_buildPropertyMap($options);
|
|
$propertyMap = $this->_buildPropertyMap($options);
|
|
|
- $tableName = $this->_table->alias();
|
|
|
|
|
$isNew = $entity->isNew();
|
|
$isNew = $entity->isNew();
|
|
|
$keys = [];
|
|
$keys = [];
|
|
|
|
|
|
|
|
- if (isset($data[$tableName])) {
|
|
|
|
|
- $data = $data[$tableName];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (!$isNew) {
|
|
if (!$isNew) {
|
|
|
$keys = $entity->extract((array)$this->_table->primaryKey());
|
|
$keys = $entity->extract((array)$this->_table->primaryKey());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $data = $this->_prepareData($data, $options);
|
|
|
|
|
+
|
|
|
$errors = $this->_validate($data + $keys, $options, $isNew);
|
|
$errors = $this->_validate($data + $keys, $options, $isNew);
|
|
|
$schema = $this->_table->schema();
|
|
$schema = $this->_table->schema();
|
|
|
$properties = [];
|
|
$properties = [];
|