Passed
Push — develop ( 9ff5e0...4357d1 )
by Nikolay
04:17
created

AuthTokens::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 14
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\Common\Models;
21
22
use Phalcon\Mvc\Model\Behavior\Timestampable;
23
24
/**
25
 * Class AuthTokens
26
 *
27
 * @package MikoPBX\Common\Models
28
 */
29
class AuthTokens extends ModelsBase
30
{
31
    /**
32
     * @Primary
33
     * @Identity
34
     * @Column(type="integer", nullable=false)
35
     */
36
    public $id;
37
38
    /**
39
     * @Column(type="string", nullable=true)
40
     */
41
    public ?string $tokenHash = '';
42
43
    /**
44
     * @Column(type="string", nullable=true)
45
     */
46
    public ?string $sessionParams = '';
47
48
    /**
49
     * @Column(type="string", nullable=false)
50
     */
51
    public ?string $expiryDate = '';
52
53
54
    /**
55
     * Class initialization
56
     */
57
    public function initialize(): void
58
    {
59
        $this->setSource('m_AuthTokens');
60
        parent::initialize();
61
        $this->addBehavior(
62
            new Timestampable(
63
                [
64
                    'beforeValidationOnCreate' => [
65
                        'field'  => 'expiryDate',
66
                        'format' => 'Y-m-d H:i:s',
67
                    ],
68
                    'beforeValidationOnUpdate' => [
69
                        'field'  => 'expiryDate',
70
                        'format' => 'Y-m-d H:i:s',
71
                    ],
72
                ]
73
            )
74
        );
75
    }
76
77
}