Permalink
Browse files

some tidying up

  • Loading branch information...
1 parent 9b36e4c commit b144e1206a4932221cacf7ead016542f98214a2a Jonathan Moss committed Apr 28, 2011
View
@@ -272,13 +272,14 @@ public function delete()
*/
public function __toString()
{
- $string = "";
- $string .= "Id: " . $this->id() . "\n";
- $string .= "State: " . $this->state() . "\n";
- foreach ($this->propertySet as $property) {
- $string .= (string)$property . "\n";
+ $data = array(
+ 'Id' => $this->id(),
+ 'State' => $this->state()
+ );
+ foreach ($this->propertySet as $name => $property) {
+ $data[$name] = (string)$property;
}
- return $string;
+ return \json_encode($data);
}
/**
@@ -22,22 +22,18 @@ class Enum extends Generic
private $choices;
/**
- *
* @param string $name
- * @param mixed $default
* @param array $enums An array of valid enum values
- * @return ar_Property_Enum
+ * @param mixed $default
*/
- public function __construct($name, $default, array $choices)
+ public function __construct($name, array $choices, $default = null)
{
$this->choices = $choices;
parent::__construct($name, $default);
}
/**
* Overrides parent setValue to add enum value checking
- *
- * @see classes/ar/ar_Field#setValue()
*/
public function setValue($value)
{
@@ -104,6 +104,6 @@ public function __setRawValue($value)
*/
public function __toString()
{
- return $this->getName() . ": " . $this->getValue();
+ return $this->getValue();
}
}
@@ -118,8 +118,9 @@ private function loadFromReferences()
$object = new $this->type;
- //@todo this could get nasty with large collections!
- $this->value = \morph\Storage::instance()->findByQuery($object, $query)->toCollection();
+ $this->value = \morph\Storage::instance()
+ ->findByQuery($object, $query)
+ ->toCollection(); //@todo this could get nasty with large collections!
} else {
$this->value = new \morph\Collection();
}
@@ -73,11 +73,10 @@ public function test__toArray()
public function test__toString()
{
- $expected = "Id: \nState: New\ntestField: TEST\n";
+ $expected = '{"Id":null,"State":"New","testField":"TEST"}';
$obj = new ForTesting();
$obj->testField = 'TEST';
$this->assertEquals($expected, $obj->__toString());
}
-}
-?>
+}

0 comments on commit b144e12

Please sign in to comment.