Passed
Branch feature/ide (a01864)
by Csaba
02:28
created

Schema::schema()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
namespace Fathomminds\Rest;
3
4
use Fathomminds\Rest\Contracts\ISchema;
5
use Fathomminds\Rest\Schema\TypeValidators\ValidatorFactory;
6
use Fathomminds\Rest\Exceptions\RestException;
7
8
abstract class Schema implements ISchema
9
{
10 48
    public function __construct($object = null)
11
    {
12 48
        if ($object === null) {
13 48
            return;
14
        }
15 16
        if (gettype($object) !== 'object') {
16
            throw new RestException('Schema constructor expects object or null as parameter', [
17
                'parameter' => $object,
18
            ]);
19
        }
20 16
        foreach (get_object_vars($object) as $name => $value) {
21 14
            $this->{$name} = $value;
22
        }
23 16
    }
24
25
    public function __get($name)
26
    {
27
        if (!isset($this->{$name})) {
28
            throw new RestException(
29
                'Trying to access undefined property ' . $name,
30
                []
31
            );
32
        }
33
    }
34
35
    abstract public function schema();
36
}
37