Skip to content

Commit 72687b8

Browse files
committed
Merge branch 'refac'
# Conflicts: # src/Constraint.php
2 parents eb79962 + baaed55 commit 72687b8

36 files changed

+394
-116
lines changed

src/AbstractConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function setOwnerSchema(Schema $ownerSchema)
2020
*/
2121
public static function getFromSchema(Schema $schema)
2222
{
23-
$class = self::className();
23+
$class = static::className();
2424
if (isset($schema->constraints[$class])) {
2525
return $schema->constraints[$class];
2626
}

src/AbstractFlavour.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Yaoi\Schema;
44

55

6-
class AbstractFlavour extends AbstractConstraint implements Flavour
6+
abstract class AbstractFlavour extends AbstractConstraint implements Flavour
77
{
88
public $value;
99

10-
public function __construct($value)
10+
public function __construct($schemaValue, Schema $ownerSchema = null)
1111
{
12-
$this->value = $value;
12+
$this->value = $schemaValue;
1313
}
1414

1515
}

src/ArrayFlavour/Items.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
class Items extends AbstractConstraint implements Schematic
1010
{
11-
const KEY = 'items';
11+
public static function getSchemaKey()
12+
{
13+
return 'items';
14+
}
1215

1316
/**
1417
* @var Schema

src/ArrayFlavour/MinItems.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,13 @@
33
namespace Yaoi\Schema\ArrayFlavour;
44

55

6-
use Yaoi\Schema\AbstractConstraint;
6+
use Yaoi\Schema\AbstractFlavour;
77
use Yaoi\Schema\Flavour;
8-
use Yaoi\Schema\Validator;
98

10-
class MinItems extends AbstractConstraint implements Flavour
9+
class MinItems extends AbstractFlavour implements Flavour
1110
{
12-
const KEY = 'minItems';
13-
14-
/** @var int */
15-
public $minItems;
16-
public function __construct($minItems)
17-
{
18-
$this->minItems = $minItems;
19-
}
20-
21-
22-
public function isValid($data)
11+
public static function getSchemaKey()
2312
{
24-
return count($data) >= $this->minItems;
13+
return 'minItems';
2514
}
26-
2715
}

src/CodeBuilder/PHPCodeBuilder.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Yaoi\Schema\CodeBuilder\Templates\ClassStructurePhp;
66
use Yaoi\Schema\Exception;
7+
use Yaoi\Schema\Logic\AllOf;
78
use Yaoi\Schema\ObjectFlavour\Properties;
89
use Yaoi\Schema\Ref;
910
use Yaoi\Schema\Schema;
@@ -22,10 +23,6 @@ class PHPCodeBuilder
2223

2324
public function getSchemaInstantiationCode(Schema $schema)
2425
{
25-
foreach ($schema->getConstraints() as $constraintClass => $constraint) {
26-
27-
}
28-
2926
switch (true) {
3027
case StringType::getFromSchema($schema):
3128
return StringType::className() . '::makeSchema(' . ');';
@@ -48,10 +45,18 @@ public function getTypeHint(Schema $schema)
4845

4946
public function getPhpDocType(Schema $schema)
5047
{
48+
if (!$contraints = $schema->getConstraints()) {
49+
return '';
50+
}
51+
5152
if ($ref = Ref::getFromSchema($schema)) {
5253
return $this->getPhpDocType($ref->constraintSchema);
5354
}
5455

56+
if ($allOf = AllOf::getFromSchema($schema)) {
57+
return 'bitch';
58+
}
59+
5560
switch (true) {
5661
case StringType::getFromSchema($schema):
5762
return 'string';
@@ -68,7 +73,9 @@ public function getPhpDocType(Schema $schema)
6873
return 'object';
6974
}
7075

71-
//throw new Exception("Please im");
76+
//print_r($schema->getPath());
77+
//print_r($schema->getSchemaData());
78+
throw new Exception("Please im");
7279
return '';
7380
}
7481

@@ -158,7 +165,7 @@ public function makeClassName($tracePath)
158165

159166
public function storeToDisk($srcPath)
160167
{
161-
print_r($this->classes);
168+
//print_r($this->classes);
162169

163170
}
164171

src/Constraint.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
interface Constraint
66
{
7+
public static function getSchemaKey();
78
public function setOwnerSchema(Schema $ownerSchema);
89
}

src/Flavour.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Yaoi\Schema;
44

5-
interface Flavour extends Constraint
5+
interface Flavour extends Schematic
66
{
7-
public function __construct($value);
87
}

src/Logic/AllOf.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
class AllOf extends AbstractConstraint implements Transformer, Constraint
1212
{
13-
const KEY = 'allOf';
13+
public static function getSchemaKey()
14+
{
15+
return 'allOf';
16+
}
1417

1518
/** @var Schema[] */
1619
private $composition;
@@ -29,6 +32,9 @@ public function __construct($schemaValue, Schema $ownerSchema = null)
2932

3033
public function import($data)
3134
{
35+
foreach ($this->composition as $item) {
36+
37+
}
3238
// @todo implement
3339
return $data;
3440
}

src/NumberFlavour/Minimum.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66

77
class Minimum extends AbstractFlavour
88
{
9-
9+
public static function getSchemaKey()
10+
{
11+
return 'minimum';
12+
}
1013
}

src/ObjectFlavour/AdditionalProperties.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
class AdditionalProperties extends AbstractConstraint implements Schematic
1111
{
12-
const KEY = 'additionalProperties';
12+
public static function getSchemaKey()
13+
{
14+
return 'additionalProperties';
15+
}
1316

1417
/**
1518
* @var Schema

0 commit comments

Comments
 (0)