fkooman\OAuth\Client\Scope::fromString PHP Method

fromString() public static method

public static fromString ( $scope, $separator = ' ' )
    public static function fromString($scope, $separator = ' ')
    {
        if (null === $scope) {
            return new self();
        }
        if (!is_string($scope)) {
            throw new ScopeException('scope must be string');
        }
        if (0 === strlen($scope)) {
            return new self();
        }
        if (!is_string($separator)) {
            throw new ScopeException('separator must be string');
        }
        return new self(explode($separator, $scope));
    }

Usage Example

 public function testXYZ()
 {
     $client = new Client();
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200, null, json_encode(array('access_token' => 'my_access_token', 'token_type' => 'BeArEr', 'refresh_token' => 'why_not_a_refresh_token'))));
     $client->addSubscriber($mock);
     $state = new State(array('state' => 'my_state', 'client_config_id' => 'foo', 'issue_time' => time() - 100, 'user_id' => 'my_user_id', 'scope' => Scope::fromString('foo bar')));
     $this->storage->storeState($state);
     $guzzle3Client = new Guzzle3Client($client);
     $callback = new Callback('foo', $this->clientConfig[0], $this->storage, $guzzle3Client);
     $tokenResponse = $callback->handleCallback(array('state' => 'my_state', 'code' => 'my_code'));
     $this->assertEquals('my_access_token', $tokenResponse->getAccessToken());
 }
All Usage Examples Of fkooman\OAuth\Client\Scope::fromString