Completed
Push — master ( fe927c...366a13 )
by Rasmus
15:55
created

Schema::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace mindplay\sql\model\schema;
4
5
use mindplay\sql\model\TableFactory;
6
7
/**
8
 * This is an abstract base-class for user-defined Schema-types.
9
 */
10
abstract class Schema
11
{
12
    /**
13
     * @var TableFactory
14
     */
15
    private $factory;
16
17
    /**
18
     * @param TableFactory $factory
19
     */
20 1
    public function __construct(TableFactory $factory)
21
    {
22 1
        $this->factory = $factory;
23 1
    }
24
25
    /**
26
     * This name is used to qualify table-references, e.g. using schema-names in Postgres, or
27
     * table-name prefixes in MySQL.
28
     *
29
     * The default implementation returns NULL - override this in your Schema implementation, if needed.
30
     *
31
     * @return string|null optional Schema-name, or NULL
32
     */
33
    public function getName()
34
    {
35
        return null;
36
    }
37
38
    /**
39
     * @param string      $class_name Table class-name
40
     * @param string      $table_name relational table-name
41
     * @param string|null $alias      optional Table alias
42
     *
43
     * @return Table
44
     */
45 1
    protected function createTable($class_name, $table_name, $alias = null)
46
    {
47 1
        return $this->factory->createTable($this, $class_name, $table_name, $alias);
48
    }
49
50
    /**
51
     * @ignore
52
     *
53
     * @param string $name
54
     *
55
     * @return Table
56
     */
57 1
    public function __get($name)
58
    {
59
        // TODO caching
60
61 1
        return $this->$name(null);
62
    }
63
}
64