From a7d0a2ec635886c97d4868fb98ade63702a2aeac Mon Sep 17 00:00:00 2001 From: Mathieu Ducharme Date: Wed, 31 Jul 2019 11:27:28 -0400 Subject: [PATCH] Properties are camel-cased by default. --- src/Charcoal/Model/AbstractMetadata.php | 7 +++++-- src/Charcoal/Model/AbstractModel.php | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Charcoal/Model/AbstractMetadata.php b/src/Charcoal/Model/AbstractMetadata.php index 4466c07f..64540cce 100644 --- a/src/Charcoal/Model/AbstractMetadata.php +++ b/src/Charcoal/Model/AbstractMetadata.php @@ -66,14 +66,17 @@ public function defaultData() } /** - * Set the properties. + * Set the properties. Ensure the property idents (keys) are camel-cased. * * @param array $properties One or more properties. * @return self */ public function setProperties(array $properties) { - $this->properties = $properties; + $this->properties = []; + foreach ($properties as $k => $v) { + $this->properties[$this->camelize($k)] = $v; + } return $this; } diff --git a/src/Charcoal/Model/AbstractModel.php b/src/Charcoal/Model/AbstractModel.php index 25f2364c..e8157255 100644 --- a/src/Charcoal/Model/AbstractModel.php +++ b/src/Charcoal/Model/AbstractModel.php @@ -111,6 +111,7 @@ public function __construct(array $data = null) * * @param array $data The entity data. Will call setters. * @return self + * @see AbstractEntity::setData() */ public function setData(array $data) { @@ -211,7 +212,8 @@ public function setFlatData(array $flatData) foreach ($fields as $k => $f) { if (is_string($k)) { $fid = $f->ident(); - $key = str_replace($propertyIdent.'_', '', $fid); + $snake = strtolower(preg_replace('/(?camelize($propertyIdent); return $this[$propertyIdent]; }