Completed
Pull Request — master (#451)
by Anton
11:31
created

AbstractTable::getAuthRow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Auth\Model;
12
13
use Bluz\Db\RowInterface;
14
use Bluz\Db\Table;
15
16
/**
17
 * Abstract class for Auth\Table
18
 *
19
 * @package  Bluz\Auth
20
 * @author   Anton Shevchuk
21
 *
22
 * @method   static AbstractRow findRow($primaryKey)
23
 * @see      Table::findRow()
24
 *
25
 * @method   static AbstractRow findRowWhere($whereList)
26
 * @see      Table::findRowWhere()
27
 */
28
abstract class AbstractTable extends Table
29
{
30
    /**
31
     * Types
32
     */
33
    public const TYPE_ACCESS = 'access';
34
    public const TYPE_REQUEST = 'request';
35
36
    /**
37
     * Providers
38
     *  - equals - login + password
39
     *  - token  - token with ttl
40
     *  - cookie - cookie token with ttl
41
     */
42
    public const PROVIDER_COOKIE = 'cookie';
43
    public const PROVIDER_EQUALS = 'equals';
44
    public const PROVIDER_FACEBOOK = 'facebook';
45
    public const PROVIDER_GOOGLE = 'google';
46
    public const PROVIDER_LDAP = 'ldap';
47
    public const PROVIDER_TOKEN = 'token';
48
    public const PROVIDER_TWITTER = 'twitter';
49
50
    /**
51
     * @var string Table
52
     */
53
    protected $name = 'auth';
54
55
    /**
56
     * @var array Primary key(s)
57
     */
58
    protected $primary = ['provider', 'foreignKey'];
59
60
    /**
61
     * Get AuthRow
62
     *
63
     * @param  string $provider
64
     * @param  string $foreignKey
65
     *
66
     * @return RowInterface
67
     * @throws \InvalidArgumentException
68
     * @throws \Bluz\Db\Exception\DbException
69
     * @throws \Bluz\Db\Exception\InvalidPrimaryKeyException
70
     */
71
    public static function getAuthRow($provider, $foreignKey) : ?RowInterface
72
    {
73
        return static::findRow(['provider' => $provider, 'foreignKey' => $foreignKey]);
74
    }
75
}
76