Skip to content

Commit f7d5855

Browse files
committed
type propagation for classes
1 parent 716d041 commit f7d5855

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/Structure/ClassStructure.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@ public static function makeSchema()
2121
$schema->setConstraint($properties);
2222
return $schema;
2323
}
24+
25+
/**
26+
* @param $data
27+
* @return static
28+
* @throws \Yaoi\Schema\Exception
29+
*/
30+
public static function import($data)
31+
{
32+
static $schemas = array();
33+
return static::makeSchema()->import($data);
34+
}
35+
36+
/**
37+
* @param $data
38+
* @return mixed
39+
* @throws \Yaoi\Schema\Exception
40+
*/
41+
public static function export($data)
42+
{
43+
return static::makeSchema()->export($data);
44+
}
2445
}

tests/src/Helper/LevelOneClass.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use Yaoi\Schema\Schema;
88
use Yaoi\Schema\Structure\ClassStructure;
99

10-
/**
11-
* @method import
12-
*/
1310
class LevelOneClass extends ClassStructure
1411
{
1512
/**

tests/src/Schema/ParentFixedTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ protected function deepSchema()
1616
return $schema;
1717
}
1818

19-
public function testImport()
19+
public function testImportClass()
2020
{
21-
$object = $this->deepSchema()->import(array(
21+
$data = array(
2222
'level1' => array(
2323
'level2' => array(
2424
'level3' => 123 // integer required
2525
),
2626
),
27-
));
27+
);
28+
$object = LevelOneClass::import($data);
2829
$this->assertSame(123, $object->level1->level2->level3);
30+
$this->assertSame($data, LevelOneClass::export($object));
2931
}
3032

3133

0 commit comments

Comments
 (0)