Skip to content

Commit 06c2aa9

Browse files
committed
cleanup
1 parent 84192d3 commit 06c2aa9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+87
-1364
lines changed

src/Constraint/Constraint.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
namespace Yaoi\Schema\Constraint;
44

5-
use Yaoi\Schema\Schema;
6-
75
interface Constraint
86
{
9-
/**
10-
* @param Schema $schema
11-
* @return mixed
12-
* @todo justify existence
13-
*/
14-
public function setToSchema(Schema $schema);
15-
167
}

src/Constraint/InvalidValue.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Constraint/Properties.php

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
namespace Yaoi\Schema\Constraint;
44

5-
use Yaoi\Schema\InvalidValue;
65
use Yaoi\Schema\MagicMap;
76
use Yaoi\Schema\Schema;
8-
use Yaoi\Schema\SchemaLoader;
9-
use Yaoi\Schema\Structure\ObjectItem;
107

118
/**
129
* @method Schema __get($key)
@@ -18,79 +15,14 @@ class Properties extends MagicMap implements Constraint
1815

1916
public function __set($name, $column)
2017
{
21-
if ($column instanceof Constraint) {
22-
$schema = new Schema();
23-
$column->setToSchema($schema);
24-
return parent::__set($name, $schema);
25-
}
26-
2718
return parent::__set($name, $column);
2819
}
2920

30-
public function setToSchema(Schema $schema)
31-
{
32-
$schema->properties = $this;
33-
}
34-
3521
public static function create()
3622
{
3723
return new static;
3824
}
3925

40-
/**
41-
* @param $data
42-
* @param ObjectItem $result
43-
* @param Schema|null $schema
44-
* @throws InvalidValue
45-
* @throws \Exception
46-
* @deprecated move relevant code to Schema
47-
*/
48-
public function import($data, ObjectItem $result, Schema $schema = null)
49-
{
50-
$traceHelper = Schema::$traceHelper;
51-
52-
$additionalProperties = $schema->additionalProperties;
53-
54-
foreach ($data as $key => $value) {
55-
if (isset($this->_arrayOfData[$key])) {
56-
$traceHelper->push()->addData(SchemaLoader::PROPERTIES . ':' . $key);
57-
$result->$key = $this->_arrayOfData[$key]->import($value);
58-
$traceHelper->pop();
59-
} else {
60-
// todo remove code duplication
61-
62-
$found = false;
63-
if ($schema->patternProperties !== null) {
64-
foreach ($schema->patternProperties as $pattern => $propertySchema) {
65-
if (preg_match($pattern, $key)) {
66-
$found = true;
67-
$value = $propertySchema->import($value);
68-
//break; // todo manage multiple import data properly (pattern accessor)
69-
}
70-
}
71-
}
72-
if (!$found && null !== $additionalProperties) {
73-
$traceHelper->push()->addData(SchemaLoader::ADDITIONAL_PROPERTIES);
74-
if ($additionalProperties === false) {
75-
throw new InvalidValue('Additional properties not allowed', InvalidValue::INVALID_VALUE);
76-
}
77-
$value = $additionalProperties->import($value);
78-
$traceHelper->pop();
79-
}
80-
$result->$key = $value;
81-
}
82-
}
83-
}
84-
85-
public function export(ObjectItem $data)
86-
{
87-
$result = array();
88-
foreach ($this->_arrayOfData as $key => $value) {
89-
$result[$key] = $value->export($data->$key);
90-
}
91-
return $result;
92-
}
93-
9426
/** @var Schema */
9527
private $additionalProperties;
9628

src/Constraint/Ref.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ public function __construct($ref, Schema $schema)
1313
$this->schema = $schema;
1414
}
1515

16-
public function setToSchema(Schema $schema)
17-
{
18-
$schema->ref = $this;
19-
}
20-
21-
2216
/** @var Schema */
2317
private $schema;
2418

src/Constraint/Type.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public function __construct($type)
2222
$this->types = is_array($type) ? $type : array($type);
2323
}
2424

25-
public function setToSchema(Schema $schema)
26-
{
27-
$schema->type = $this;
28-
}
29-
3025
public function has($type)
3126
{
3227
return in_array($type, $this->types);

src/Exception/ArrayException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Exception;
4+
5+
6+
use Yaoi\Schema\InvalidValue;
7+
8+
class ArrayException extends InvalidValue
9+
{
10+
11+
}

src/Exception/TypeException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Exception;
4+
5+
6+
use Yaoi\Schema\InvalidValue;
7+
8+
class TypeException extends InvalidValue
9+
{
10+
11+
}

src/InvalidValue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
class InvalidValue extends \Exception
66
{
7+
private $path;
8+
9+
public function addPath($path)
10+
{
11+
$this->message .= ' at ' . $path;
12+
}
13+
14+
public function getPath()
15+
{
16+
return $this->path;
17+
}
18+
719
const INVALID_VALUE = 1;
820
const NOT_IMPLEMENTED = 2;
921
}

src/Legacy/AbstractConstraint.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Legacy/Constraint.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)