Skip to content

Commit 9bbf292

Browse files
committed
Use TypeCheck interface for object manipulation
1 parent 1cab31d commit 9bbf292

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public static function propertyGet($value, $property)
2727
return $value[$property];
2828
}
2929

30+
public static function propertySet($value, $property, $data)
31+
{
32+
if (is_object($value)) {
33+
$value->{$property} = $data;
34+
}
35+
36+
$value[$property] = $data;
37+
}
38+
39+
3040
public static function propertyExists($value, $property)
3141
{
3242
if (is_object($value)) {

src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static function propertyGet($value, $property)
1919
return $value->{$property};
2020
}
2121

22+
public static function propertySet($value, $property, $data)
23+
{
24+
$value->{$property} = $data;
25+
}
26+
2227
public static function propertyExists($value, $property)
2328
{
2429
return property_exists($value, $property);

src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public static function isArray($value);
1010

1111
public static function propertyGet($value, $property);
1212

13+
public static function propertySet($value, $property, $data);
14+
1315
public static function propertyExists($value, $property);
1416

1517
public static function propertyCount($value);

src/JsonSchema/Constraints/UndefinedConstraint.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
123123
if ($coerce && $this->factory->getCheckMode() & self::CHECK_MODE_APPLY_DEFAULTS) {
124124
if ($this->getTypeCheck()->isObject($value) && isset($schema->properties)) {
125125
foreach ($schema->properties as $i => $propertyDefinition) {
126-
if (!isset($value->$i) && isset($propertyDefinition->default)) {
127-
$value->$i = $propertyDefinition->default;
126+
if (!$this->getTypeCheck()->propertyExists($value, $i) && isset($propertyDefinition->default)) {
127+
$this->getTypeCheck()->propertySet($value, $i, $propertyDefinition->default);
128128
}
129129
}
130-
} elseif (is_array($value)) {
130+
} elseif ($this->getTypeCheck()->isArray($value)) {
131131
if (isset($schema->properties)) {
132132
foreach ($schema->properties as $i => $propertyDefinition) {
133133
if (!isset($value[$i]) && isset($propertyDefinition->default)) {

0 commit comments

Comments
 (0)