Context.php (1565B)
1 <?php 2 3 /** 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 namespace fkooman\OAuth\Client; 19 20 use fkooman\OAuth\Client\Exception\ContextException; 21 use fkooman\OAuth\Common\Scope; 22 23 class Context 24 { 25 /** @var string */ 26 private $userId; 27 28 /** @var fkooman\OAuth\Common\Scope */ 29 private $scope; 30 31 public function __construct($userId, array $scope = array()) 32 { 33 $this->setUserId($userId); 34 $this->setScope($scope); 35 } 36 37 public function setUserId($userId) 38 { 39 if (!is_string($userId) || 0 >= strlen($userId)) { 40 throw new ContextException("userId needs to be a non-empty string"); 41 } 42 $this->userId = $userId; 43 } 44 45 public function getUserId() 46 { 47 return $this->userId; 48 } 49 50 public function setScope(array $scope) 51 { 52 $this->scope = new Scope($scope); 53 } 54 55 public function getScope() 56 { 57 return $this->scope; 58 } 59 }