Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 20, 2013
@jeremiahsmall Merge pull request #17 from jeremiahsmall/development
Add fieldMap and toArray support
8884bba
@jeremiahsmall Hotfix missed fieldMap injection in AbstractGateway methods aeeea78
Commits on Mar 21, 2013
@jeremiahsmall Refactor fieldMaps out of config because there seemed to be no advant…
…age to injecting the maps, as opposed to defining the maps directly in the entity. Provide abstract methods on AbstractEntity for fieldMaps. Update Version due to BC break.
641d2f3
View
2  library/Soliant/SimpleFM/Version.php
@@ -11,5 +11,5 @@
final class Version
{
- const VERSION = '2.0.0beta6';
+ const VERSION = '2.0.0beta7';
}
View
72 library/Soliant/SimpleFM/ZF2/Entity/AbstractEntity.php
@@ -31,11 +31,6 @@
/**
* @var array
*/
- protected $fieldMap;
-
- /**
- * @var array
- */
protected $entityAsArray;
/**
@@ -48,27 +43,9 @@
/**
* @param array $simpleFMAdapterRow
*/
- public function __construct($fieldMap, $simpleFMAdapterRow = array())
+ public function __construct($simpleFMAdapterRow = array())
{
$this->simpleFMAdapterRow = $simpleFMAdapterRow;
-
- if (empty($fieldMap)){
- throw new InvalidArgumentException(get_class($this) . ' is empty or missing.');
- }
-
- if (!array_key_exists(get_class($this), $fieldMap)){
- throw new InvalidArgumentException(get_class($this) . ' is missing from $fieldMap.');
- }
-
- $this->fieldMap = $fieldMap;
- if (!array_key_exists('writeable', $this->fieldMap[get_class($this)])){
- throw new InvalidArgumentException(get_class($this) . ' fieldMap must contain a "writeable" array.');
- }
-
- if (!array_key_exists('readonly', $this->fieldMap[get_class($this)])){
- throw new InvalidArgumentException(get_class($this) . ' fieldMap must contain a "readonly" array.');
- }
-
$this->isSerializable = TRUE;
if (!empty($this->simpleFMAdapterRow)) $this->unserialize();
}
@@ -142,7 +119,35 @@ public function setIsSerializable ($isSerializable)
}
/**
- * Default FileMaker layout for the Entity which should include all the writable fields
+ * An array of properties and FileMaker field names each maps to which are writeable/serializable .
+ * List fields in this map which the web app can modify, such as text and number fields. Normally
+ * it will be most convenient to define the array directly in the method implementation.
+ * Example: return array ('myEntityName' => 'My Entity Name', 'status' => 'SomeTableOccurance::Status');
+ * @return array
+ */
+ abstract public function getFieldMapWriteable();
+
+ /**
+ * An array of properties and FileMaker field names each maps to which are readonly. List fields
+ * in this map which cannot be updated by the web app, such a s primary keys and calc fields.
+ * Normally it will be most convenient to define the array directly in the method implementation.
+ * Example: return array ('id' => 'PrimaryKey', 'total' => 'Total');
+ * @return array
+ */
+ abstract public function getFieldMapReadonly();
+
+ /**
+ * Utility function combines both field maps into a single map.
+ * @return array
+ */
+ public function getFieldMapMerged()
+ {
+ return array_merge($this->getFieldMapWriteable(), $this->getFieldMapReadOnly());
+ }
+
+ /**
+ * Default FileMaker layout for the Entity. This layout should usually at least include all the
+ * writable fields, but it may also include readonly fields and portals/associations.
*/
abstract public function getDefaultWriteLayoutName();
@@ -161,11 +166,11 @@ public function unserialize()
$this->unserializeField('recid', 'recid');
$this->unserializeField('modid', 'modid');
- foreach ($this->fieldMap[get_class($this)]['writeable'] as $property=>$field) {
+ foreach ($this->getFieldMapWriteable() as $property=>$field) {
$this->unserializeField($property, $field, true);
}
- foreach ($this->fieldMap[get_class($this)]['readonly'] as $property=>$field) {
+ foreach ($this->getFieldMapReadOnly() as $property=>$field) {
$this->unserializeField($property, $field, false);
}
}
@@ -182,14 +187,9 @@ public function serialize()
$this->serializeField('-recid', 'getRecid');
$this->serializeField('-modid', 'getModid');
- foreach ($this->fieldMap[get_class($this)]['writeable'] as $property=>$field) {
+ foreach ($this->getFieldMapMerged() as $property=>$field) {
$this->serializeField($field, $property);
}
-
- foreach ($this->fieldMap[get_class($this)]['readonly'] as $property=>$field) {
- $this->serializeField($field, $property);
- }
-
}
/**
@@ -200,11 +200,7 @@ public function toArray() {
$this->addPropertyToEntityAsArray('recid');
$this->addPropertyToEntityAsArray('modid');
- foreach ($this->fieldMap[get_class($this)]['writeable'] as $property=>$field) {
- $this->addPropertyToEntityAsArray($property);
- }
-
- foreach ($this->fieldMap[get_class($this)]['readonly'] as $property=>$field) {
+ foreach ($this->getFieldMapMerged() as $property=>$field) {
$this->addPropertyToEntityAsArray($property);
}
View
41 library/Soliant/SimpleFM/ZF2/Gateway/AbstractGateway.php
@@ -36,11 +36,6 @@
protected $entityLayout;
/**
- * @var array
- */
- protected $fieldMap;
-
- /**
* @var \Soliant\SimpleFM\Adapter
*/
protected $simpleFMAdapter;
@@ -50,30 +45,12 @@
* @param AbstractEntity $entity
* @param SimpleFMAdapter $simpleFMAdapter
*/
- public function __construct($fieldMap, AbstractEntity $entity, SimpleFMAdapter $simpleFMAdapter, Identity $identity=NULL, $encryptionKey=NULL )
+ public function __construct(AbstractEntity $entity, SimpleFMAdapter $simpleFMAdapter, Identity $identity=NULL, $encryptionKey=NULL )
{
- if (!is_array($fieldMap)){
- throw new InvalidArgumentException('$fieldMap must be an array.');
- }
-
$this->setSimpleFMAdapter($simpleFMAdapter);
$this->setEntityName(get_class($entity));
$this->setEntityLayout($entity->getDefaultWriteLayoutName());
- if (!array_key_exists($this->getEntityName(), $fieldMap)){
- throw new InvalidArgumentException($this->getEntityName() . ' is missing from $fieldMap.');
- }
-
- $this->fieldMap = $fieldMap;
-
- if (!array_key_exists('writeable', $this->fieldMap[$this->getEntityName()])){
- throw new InvalidArgumentException($this->getEntityName() . ' fieldMap is missing from "writeable" array.');
- }
-
- if (!array_key_exists('readonly', $this->fieldMap[$this->getEntityName()])){
- throw new InvalidArgumentException($this->getEntityName() . ' fieldMap is missing from "readonly" array.');
- }
-
if (!empty($identity) && !empty($encryptionKey)) {
$this->simpleFMAdapter->setUsername($identity->getUsername());
$this->simpleFMAdapter->setPassword($identity->getPassword($encryptionKey));
@@ -257,20 +234,6 @@ public function setEntityName ($entityName)
}
/**
- * @return the $fieldMap
- */
- public function getFieldMap() {
- return $this->fieldMap;
- }
-
- /**
- * @param multitype: $fieldMap
- */
- public function setFieldMap($fieldMap) {
- $this->fieldMap = $fieldMap;
- }
-
- /**
* @param int $max
* @param int $skip
* @return array:
@@ -346,7 +309,7 @@ protected function rowsToArrayCollection(array $rows)
$collection = new ArrayCollection();
if (!empty($rows)){
foreach($rows as $row){
- $collection[] = new $this->entityName($this->fieldMap, $row);
+ $collection[] = new $this->entityName($row);
}
}

No commit comments for this range

Something went wrong with that request. Please try again.