summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/orm/src/ColumnDefinition.php
blob: ddb806213784ed0545f48c5b7585af37a2fc894b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

namespace ipl\Orm;

use InvalidArgumentException;
use LogicException;

class ColumnDefinition
{
    /** @var string The name of the column */
    protected $name;

    /** @var ?string The label of the column */
    protected $label;

    /**
     * Create a new column definition
     *
     * @param string $name
     */
    public function __construct(string $name)
    {
        $this->name = $name;
    }

    /**
     * Get the column name
     *
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * Get the column label
     *
     * @return ?string
     */
    public function getLabel(): ?string
    {
        return $this->label;
    }

    /**
     * Set the column label
     *
     * @param ?string $label
     *
     * @return $this
     */
    public function setLabel(?string $label): self
    {
        $this->label = $label;

        return $this;
    }

    /**
     * Create a new column definition based on the given options
     *
     * @param array $options
     *
     * @return self
     */
    public static function fromArray(array $options): self
    {
        if (! isset($options['name'])) {
            throw new InvalidArgumentException('$options must provide a name');
        }

        $self = new static($options['name']);
        if (isset($options['label'])) {
            $self->setLabel($options['label']);
        }

        return $self;
    }
}