|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 François Kooman <[email protected]>. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace fkooman\RemoteStorage\OAuth\Storage; |
|
20
|
|
|
|
|
21
|
|
|
use fkooman\RemoteStorage\OAuth\ResourceServer; |
|
22
|
|
|
use fkooman\RemoteStorage\OAuth\ResourceServerStorageInterface; |
|
23
|
|
|
use PDO; |
|
24
|
|
|
|
|
25
|
|
|
class PdoResourceServerStorage extends PdoBaseStorage implements ResourceServerStorageInterface |
|
26
|
|
|
{ |
|
27
|
|
|
public function __construct(PDO $db, $dbPrefix = '') |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($db, $dbPrefix); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
public function getResourceServer($resourceServerId) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$stmt = $this->db->prepare( |
|
35
|
|
|
sprintf( |
|
36
|
|
|
'SELECT id, scope, secret FROM %s WHERE id = :id', |
|
37
|
|
|
$this->dbPrefix.'resource_server' |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$stmt->bindValue(':id', $resourceServerId, PDO::PARAM_STR); |
|
42
|
|
|
$stmt->execute(); |
|
43
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC); |
|
44
|
|
|
if (false === $result) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return new ResourceServer( |
|
49
|
|
|
$result['id'], |
|
50
|
|
|
$result['scope'], |
|
51
|
|
|
$result['secret'] |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function createTableQueries($dbPrefix) |
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
|
|
sprintf( |
|
59
|
|
|
'CREATE TABLE IF NOT EXISTS %s ( |
|
60
|
|
|
id VARCHAR(255) NOT NULL, |
|
61
|
|
|
scope VARCHAR(255) NOT NULL, |
|
62
|
|
|
secret VARCHAR(255) NOT NULL, |
|
63
|
|
|
PRIMARY KEY (id) |
|
64
|
|
|
)', |
|
65
|
|
|
$dbPrefix.'resource_server' |
|
66
|
|
|
), |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.