| 1: | <?php |
| 2: | /* |
| 3: | * SimpleID |
| 4: | * |
| 5: | * Copyright (C) Kelvin Mo 2014-2025 |
| 6: | * |
| 7: | * This program is free software; you can redistribute it and/or |
| 8: | * modify it under the terms of the GNU General Public |
| 9: | * License as published by the Free Software Foundation; either |
| 10: | * version 2 of the License, or (at your option) any later version. |
| 11: | * |
| 12: | * This program is distributed in the hope that it will be useful, |
| 13: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15: | * General Public License for more details. |
| 16: | * |
| 17: | * You should have received a copy of the GNU General Public |
| 18: | * License along with this program; if not, write to the Free |
| 19: | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20: | * |
| 21: | */ |
| 22: | |
| 23: | namespace SimpleID\Models; |
| 24: | |
| 25: | use SimpleID\Util\ArrayWrapper; |
| 26: | use SimpleID\Store\Storable; |
| 27: | |
| 28: | /** |
| 29: | * A class representing a client. A client is an application that is |
| 30: | * requesting to obtain authentication, authorisation or user information |
| 31: | * from the SimpleID installation. |
| 32: | * |
| 33: | * Different protocols may call clients different names. For example, |
| 34: | * clients are known as *relying parties* in OpenID 2. |
| 35: | */ |
| 36: | class Client extends ArrayWrapper implements Storable { |
| 37: | /** @var string */ |
| 38: | public $cid; |
| 39: | |
| 40: | /** @var bool */ |
| 41: | protected $dynamic; |
| 42: | |
| 43: | /** |
| 44: | * @param array<string, mixed> $data |
| 45: | */ |
| 46: | public function __construct($data = []) { |
| 47: | parent::__construct($data); |
| 48: | } |
| 49: | |
| 50: | /** |
| 51: | * Loads fields from another client. |
| 52: | * |
| 53: | * @param Client $from the client from which fields are to be loaded |
| 54: | * @return void |
| 55: | */ |
| 56: | public function loadFieldsFrom($from) { |
| 57: | $this->cid = $from->cid; |
| 58: | $this->dynamic = $from->dynamic; |
| 59: | } |
| 60: | |
| 61: | /** |
| 62: | * Returns whether this client is dynamically registered. |
| 63: | * |
| 64: | * A client is *dynamically registered* if it is registered via |
| 65: | * an API rather than through a client file. |
| 66: | * |
| 67: | * @return bool true if the client is dynamically registered |
| 68: | */ |
| 69: | public function isDynamic() { |
| 70: | return $this->dynamic; |
| 71: | } |
| 72: | |
| 73: | /** |
| 74: | * Returns the plain-text display name for this client. |
| 75: | * |
| 76: | * @return string the display name |
| 77: | */ |
| 78: | public function getDisplayName() { |
| 79: | if (isset($this->container['client_name'])) return $this->container['client_name']; |
| 80: | return $this->cid; |
| 81: | } |
| 82: | |
| 83: | /** |
| 84: | * Returns the HTML display name for this client. |
| 85: | * Unlike {@link getDisplayName()}, the string returned by this |
| 86: | * method can have HTML formatting. |
| 87: | * |
| 88: | * @return string the display name |
| 89: | */ |
| 90: | public function getDisplayHTML() { |
| 91: | return $this->getDisplayName(); |
| 92: | } |
| 93: | |
| 94: | public function getStoreType() { |
| 95: | return 'client'; |
| 96: | } |
| 97: | |
| 98: | public function getStoreID() { |
| 99: | return $this->cid; |
| 100: | } |
| 101: | |
| 102: | public function setStoreID($id) { |
| 103: | $this->cid = $id; |
| 104: | } |
| 105: | } |
| 106: | |
| 107: | ?> |