Permalink
Browse files

Merge branch 'remapper' into develop

  • Loading branch information...
pmjones committed Oct 29, 2012
2 parents bee9bad + d2747df commit 4123405cbab2f8fa6ac64710fdc9c553418032ba
Showing with 710 additions and 730 deletions.
  1. +0 −4 README.md
  2. +24 −45 TODO.md
  3. +6 −0 src.php
  4. +2 −4 src/Aura/Marshal/Collection/Builder.php
  5. +1 −3 src/Aura/Marshal/Collection/BuilderInterface.php
  6. +0 −82 src/Aura/Marshal/Collection/GenericCollection.php
  7. +0 −3 src/Aura/Marshal/Manager.php
  8. +15 −0 src/Aura/Marshal/Proxy/Builder.php
  9. +9 −0 src/Aura/Marshal/Proxy/BuilderInterface.php
  10. +19 −0 src/Aura/Marshal/Proxy/GenericProxy.php
  11. +7 −0 src/Aura/Marshal/Proxy/ProxyInterface.php
  12. +13 −4 src/Aura/Marshal/Record/Builder.php
  13. +2 −5 src/Aura/Marshal/Record/BuilderInterface.php
  14. +1 −203 src/Aura/Marshal/Record/GenericRecord.php
  15. +38 −0 src/Aura/Marshal/Record/MagicArrayAccessTrait.php
  16. +38 −0 src/Aura/Marshal/Record/MagicPropertyTrait.php
  17. +69 −28 src/Aura/Marshal/Relation/AbstractRelation.php
  18. +1 −1 src/Aura/Marshal/Relation/BelongsTo.php
  19. +71 −14 src/Aura/Marshal/Relation/Builder.php
  20. +1 −1 src/Aura/Marshal/Relation/HasMany.php
  21. +2 −67 src/Aura/Marshal/Relation/HasManyThrough.php
  22. +1 −1 src/Aura/Marshal/Relation/HasOne.php
  23. +2 −0 src/Aura/Marshal/Relation/RelationInterface.php
  24. +8 −7 src/Aura/Marshal/Type/Builder.php
  25. +175 −123 src/Aura/Marshal/Type/GenericType.php
  26. +5 −25 tests/Aura/Marshal/CollectionTest.php
  27. +1 −1 tests/Aura/Marshal/ManagerTest.php
  28. +14 −0 tests/Aura/Marshal/MockRecord.php
  29. +9 −0 tests/Aura/Marshal/MockRecordBuilder.php
  30. +17 −0 tests/Aura/Marshal/MockRelation.php
  31. +59 −100 tests/Aura/Marshal/RecordTest.php
  32. +8 −7 tests/Aura/Marshal/RelationTest.php
  33. +87 −2 tests/Aura/Marshal/TypeTest.php
  34. +5 −0 tests/Aura/Marshal/fixture_data.php
View
@@ -429,10 +429,6 @@ $manager->setType('posts', [
// Aura\Marshal\Record\Builder
'record_builder' => new \Vendor\Package\Posts\RecordBuilder,
- // the kind of objects expected from the builder; default is
- // 'Aura\Marshal\Record\GenericRecord'
- 'record_class' => 'Vendor\Package\Posts\Record',
-
// an object to build collections; default is a new instance of
// Aura\Marshal\Collection\Builder
'collection_builder' => new \Vendor\Package\Posts\CollectionBuilder,
View
69 TODO.md
@@ -1,45 +1,24 @@
-Overall
--------
-
-- Create RecordTrait and CollectionTrait, and make the Record and Collection
- classes use them. Then users don't have to extend the Record and Collection;
- they can apply the trait to their own domain objects.
-
-GenericType
------------
-
-- Add methods ...
-
- - deleteRecord() capability; note that this only marks it for deletion,
- and does not actually do anyting in a data store. Should this also
- cascade through subordinate relationships?
-
- - removeRecord() to remove from the IdentityMap without marking for
- deletion.
-
- - getDeletedRecords() to get a collection of records that were deleted
- using deleteRecord()
-
-
-GenericCollection
------------------
-
-- Add methods ...
-
- - deleteRecord() to remove from the collection and mark for deletion.
- Should this cascade through subordinate relationships?
-
- - removeRecord() to remove from the collection without marking for
- deletion (and without removing from the IdentityMap).
-
-
-GenericRecord
--------------
-
-- Add methods ...
-
- - getIdentityValue() to return the identity value for the record
-
- - getIdentityField() to return the identity field for the record
-
-
+- Do we need a "detach record" method that also removes it from indexes?
+
+- How can we make IDs update? Is that something for the UnitOfWork to do
+ as it goes? Would make rolling back more complex.
+
+- rename Record to Entity? Or, in SQL, rename Entity to Record?
+
+- can we remove Manager from the relation proper, and leave it only for the
+ relation builder? would inject the actual type object dependencies, not the
+ manager as a service locator. The *builder* should do all the checking. It's
+ OK if the builder uses the manager, as long as the relations themselves get
+ only the objects. Does the builder even need the related-field name?
+ Info keys:
+
+ - native
+ - native_type
+ - native_field
+ - foreign
+ - foreign_type
+ - foreign_field
+ - through
+ - through_type
+ - through_native_field
+ - through_foreign_field
View
@@ -6,6 +6,12 @@
require __DIR__ . '/src/Aura/Marshal/Collection/GenericCollection.php';
require __DIR__ . '/src/Aura/Marshal/Exception.php';
require __DIR__ . '/src/Aura/Marshal/Manager.php';
+require __DIR__ . '/src/Aura/Marshal/Proxy/BuilderInterface.php';
+require __DIR__ . '/src/Aura/Marshal/Proxy/Builder.php';
+require __DIR__ . '/src/Aura/Marshal/Proxy/ProxyInterface.php';
+require __DIR__ . '/src/Aura/Marshal/Proxy/GenericProxy.php';
+require __DIR__ . '/src/Aura/Marshal/Record/MagicArrayAccessTrait.php';
+require __DIR__ . '/src/Aura/Marshal/Record/MagicPropertyTrait.php';
require __DIR__ . '/src/Aura/Marshal/Record/BuilderInterface.php';
require __DIR__ . '/src/Aura/Marshal/Record/Builder.php';
require __DIR__ . '/src/Aura/Marshal/Record/GenericRecord.php';
@@ -25,15 +25,13 @@ class Builder implements BuilderInterface
*
* Creates a new collection object.
*
- * @param GenericType $type The type for this collection.
- *
* @param array $data Data to load into the collection.
*
* @return GenericCollection
*
*/
- public function newInstance(GenericType $type, array $data)
+ public function newInstance(array $data)
{
- return new GenericCollection($data, $type);
+ return new GenericCollection($data);
}
}
@@ -25,10 +25,8 @@
*
* Creates a new collection object.
*
- * @param GenericType $type The type for this collection.
- *
* @param array $data Data to load into the collection.
*
*/
- public function newInstance(GenericType $type, array $data);
+ public function newInstance(array $data);
}
@@ -22,75 +22,10 @@
*/
class GenericCollection extends Data
{
- /**
- *
- * The type for this collection.
- *
- * @var GenericType
- *
- */
- protected $type;
-
- /**
- *
- * Constructor.
- *
- * @param array $data An array of records for this collection.
- *
- * @param GenericType $type The type for this collection.
- *
- */
- public function __construct(array $data, GenericType $type)
- {
- parent::__construct($data);
- $this->type = $type;
- }
-
- /**
- *
- * ArrayAccess: Get a key value.
- *
- * This override from the parent::offsetGet() lets us convert records
- * lazily using the IdentityMap for the type.
- *
- * @param string $key The requested key.
- *
- * @return mixed
- *
- */
- public function offsetGet($key)
- {
- $record_class = $this->type->getRecordClass();
- if (! $this->data[$key] instanceof $record_class) {
- $identity_field = $this->type->getIdentityField();
- $identity_value = $this->data[$key]->$identity_field;
- $this->data[$key] = $this->type->getRecord($identity_value);
- }
-
- return $this->data[$key];
- }
-
- /**
- *
- * Returns an array of all the identity values for the collection.
- *
- * This will not convert the collection elements to record objects.
- *
- * @return array
- *
- */
- public function getIdentityValues()
- {
- $identity_field = $this->type->getIdentityField();
- return $this->getFieldValues($identity_field);
- }
-
/**
*
* Returns an array of all values for a single field in the collection.
*
- * This will not convert the collection elements to record objects.
- *
* @param string $field The field name to retrieve values for.
*
* @return array
@@ -116,21 +51,4 @@ public function isEmpty()
{
return empty($this->data);
}
-
- /**
- *
- * Adds a new record to the collection (and to the IdentityMap for the
- * type).
- *
- * @param array $data Data for the new record.
- *
- * @return object
- *
- */
- public function appendNewRecord(array $data = [])
- {
- $record = $this->type->newRecord($data);
- $this->data[] = $record;
- return $record;
- }
}
@@ -68,9 +68,6 @@ class Manager
* // fields to index against
* 'index_fields' => ['field1', 'field2'],
*
- * // the record class generated by the record builder
- * 'record_class' => 'Aura\Domain\Record',
- *
* // a record builder for the type
* 'record_builder' => new \Aura\Domain\RecordBuilder,
*
@@ -0,0 +1,15 @@
+<?php
+namespace Aura\Marshal\Proxy;
+
+use Aura\Marshal\Relation\RelationInterface;
+
+class Builder implements BuilderInterface
+{
+ protected $class = 'Aura\Marshal\Proxy\GenericProxy';
+
+ public function newInstance(RelationInterface $relation)
+ {
+ $class = $this->class;
+ return new $class($relation);
+ }
+}
@@ -0,0 +1,9 @@
+<?php
+namespace Aura\Marshal\Proxy;
+
+use Aura\Marshal\Relation\RelationInterface;
+
+interface BuilderInterface
+{
+ public function newInstance(RelationInterface $relation);
+}
@@ -0,0 +1,19 @@
+<?php
+namespace Aura\Marshal\Proxy;
+
+use Aura\Marshal\Relation\RelationInterface;
+
+class GenericProxy implements ProxyInterface
+{
+ protected $relation;
+
+ public function __construct(RelationInterface $relation)
+ {
+ $this->relation = $relation;
+ }
+
+ public function get($record)
+ {
+ return $this->relation->getForRecord($record);
+ }
+}
@@ -0,0 +1,7 @@
+<?php
+namespace Aura\Marshal\Proxy;
+
+interface ProxyInterface
+{
+ public function get($record);
+}
@@ -11,6 +11,7 @@
namespace Aura\Marshal\Record;
use Aura\Marshal\Type\GenericType;
+use Aura\Marshal\Proxy\BuilderInterface as ProxyBuilderInterface;
/**
*
@@ -21,19 +22,27 @@
*/
class Builder implements BuilderInterface
{
+ protected $class = 'Aura\Marshal\Record\GenericRecord';
+
/**
*
* Creates a new record object.
*
- * @param GenericType $type The type for this record.
- *
* @param array|object $data Data to load into the record.
*
* @return GenericRecord
*
*/
- public function newInstance(GenericType $type, $data)
+ public function newInstance(array $data)
{
- return new GenericRecord((array) $data, $type);
+ $class = $this->class;
+ $record = new $class;
+
+ // set fields
+ foreach ($data as $field => $value) {
+ $record->$field = $value;
+ }
+
+ return $record;
}
}
@@ -25,11 +25,8 @@
*
* Creates a new record object.
*
- * @param GenericType $type The type for this record.
- *
- * @param mixed $data Data to load into the record. Note that the
- * interface doesn't care what the data looks like.
+ * @param mixed $data Data to load into the record.
*
*/
- public function newInstance(GenericType $type, $data);
+ public function newInstance(array $data);
}
Oops, something went wrong.

0 comments on commit 4123405

Please sign in to comment.