Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

restclient.php
Go to the documentation of this file.
1 <?php
15 class ezpRestClient
16 {
17 public $id = null;
18
23 public $name = null;
24
29 public $description = null;
30
35 public $client_id = null;
36
41 public $client_secret = null;
42
47 public $endpoint_uri = null;
48
53 public $owner_id = null;
54
59 public $created = null;
60
65 public $updated = null;
66
71 public $version = null;
72
73 public function getState()
74 {
75 $result = array();
76 $result['id'] = $this->id;
77 $result['name'] = $this->name;
78 $result['description'] = $this->description;
79 $result['client_id'] = $this->client_id;
80 $result['client_secret'] = $this->client_secret;
81 $result['endpoint_uri'] = $this->endpoint_uri;
82 $result['owner_id'] = $this->owner_id;
83 $result['created'] = $this->created;
84 $result['updated'] = $this->updated;
85 $result['version'] = $this->version;
86 return $result;
87 }
88
89 public function setState( array $properties )
90 {
91 foreach( $properties as $key => $value )
92 {
93 $this->$key = $value;
94 }
95 }
96
102 public function attribute( $attributeName )
103 {
104 if ( property_exists( $this, $attributeName ) )
105 return $this->$attributeName;
106 elseif ( $this->__isset( $attributeName ) )
107 return $this->__get( $attributeName );
108 else
109 eZDebug::writeError( "Attribute '$attributeName' does not exist", __METHOD__ );
110 }
111
117 public function hasAttribute( $attributeName )
118 {
119 return property_exists( $this, $attributeName ) or $this->__isset( $attributeName );
120 }
121
128 public function __get( $propertyName )
129 {
130 switch( $propertyName )
131 {
132 case 'owner':
133 {
134 return $this->_owner();
135 } break;
136
137 default:
138 throw new ezcBasePropertyNotFoundException( $propertyName );
139 }
140 }
141
146 protected function _owner()
147 {
148 static $owner = false;
149
150 if ( $owner === false )
151 {
152 $owner = eZUser::fetch( $this->owner_id );
153 }
154
155 return $owner;
156 }
157
158 public function __isset( $propertyName )
159 {
160 return in_array( $propertyName, array( 'owner' ) );
161 }
162
173 public static function authorizeApplication( $clientId, $endPointUri, $clientSecret = null )
174 {
175 $client = self::fetchByClientId( $clientId );
176
177 // no client found with this ID
178 if ( $client === false )
179 return false;
180
181 if ( $clientSecret !== null && ( $clientSecret !== $client->client_secret ) )
182 return false;
183
184 if ( ( $client->endpoint_uri !== '' ) && ( $endPointUri !== $client->endpoint_uri ) )
185 return false;
186
187 return true;
188 }
189
195 public static function fetchByClientId( $clientId )
196 {
197 $session = ezcPersistentSessionInstance::get();
198
199 $q = $session->createFindQuery( __CLASS__ );
200 $q->where( $q->expr->eq( 'client_id', $q->bindValue( $clientId ) ) );
201 $results = $session->find( $q, __CLASS__ );
202 if ( count( $results ) != 1 )
203 return false;
204 else
205 return array_shift( $results );
206 }
207
214 public function validateSecret( $secret )
215 {
216 return $secret === $this->client_secret;
217 }
218
229 public function isAuthorizedByUser( $scope, $user = null )
230 {
231 if ( $user === null )
232 $user = eZUser::currentUser();
233
234 if ( !$user->isRegistered() )
235 throw new Exception( "Anonymous user can not authorize an application" );
236
237 $authorized = ezpRestAuthorizedClient::fetchForClientUser( $this, $user );
238 return ( $authorized instanceof ezpRestAuthorizedClient );
239 }
240
246 public function authorizeFor( $user = null )
247 {
248 $authorization = new ezpRestAuthorizedClient();
249 $authorization->rest_client_id = $this->id;
250 $authorization->user_id = $user->attribute( 'contentobject_id' );
251
252 $session = ezcPersistentSessionInstance::get();
253 $session->save( $authorization );
254 }
255
263 public function isEndPointValid( $endPointUri )
264 {
265 return ( $endPointUri === $this->endpoint_uri );
266 }
267
268 const STATUS_DRAFT = 1;
269 const STATUS_PUBLISHED = 0;
270 }
271 ?>
$session
$session
Definition: admin/articlelist.php:44
$owner
$owner
Definition: bugedit.php:555
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
ezpRestAuthorizedClient
Definition: restauthorizedclient.php:17
ezpRestAuthorizedClient\fetchForClientUser
static fetchForClientUser(ezpRestClient $client, eZUser $user)
Definition: restauthorizedclient.php:61
ezpRestClient
Definition: restclient.php:16
ezpRestClient\isEndPointValid
isEndPointValid( $endPointUri)
Definition: restclient.php:263
ezpRestClient\_owner
_owner()
Definition: restclient.php:146
ezpRestClient\$version
$version
Definition: restclient.php:71
ezpRestClient\$updated
$updated
Definition: restclient.php:65
ezpRestClient\__isset
__isset( $propertyName)
Definition: restclient.php:158
ezpRestClient\$description
$description
Definition: restclient.php:29
ezpRestClient\setState
setState(array $properties)
Definition: restclient.php:89
ezpRestClient\attribute
attribute( $attributeName)
Definition: restclient.php:102
ezpRestClient\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: restclient.php:269
ezpRestClient\$client_id
$client_id
Definition: restclient.php:35
ezpRestClient\$owner_id
$owner_id
Definition: restclient.php:53
ezpRestClient\$endpoint_uri
$endpoint_uri
Definition: restclient.php:47
ezpRestClient\__get
__get( $propertyName)
Definition: restclient.php:128
ezpRestClient\STATUS_DRAFT
const STATUS_DRAFT
Definition: restclient.php:268
ezpRestClient\isAuthorizedByUser
isAuthorizedByUser( $scope, $user=null)
Definition: restclient.php:229
ezpRestClient\hasAttribute
hasAttribute( $attributeName)
Definition: restclient.php:117
ezpRestClient\$id
$id
Definition: restclient.php:17
ezpRestClient\$client_secret
$client_secret
Definition: restclient.php:41
ezpRestClient\fetchByClientId
static fetchByClientId( $clientId)
Definition: restclient.php:195
ezpRestClient\authorizeFor
authorizeFor( $user=null)
Definition: restclient.php:246
ezpRestClient\$name
$name
Definition: restclient.php:23
ezpRestClient\validateSecret
validateSecret( $secret)
Definition: restclient.php:214
ezpRestClient\$created
$created
Definition: restclient.php:59
ezpRestClient\getState
getState()
Definition: restclient.php:73
ezpRestClient\authorizeApplication
static authorizeApplication( $clientId, $endPointUri, $clientSecret=null)
Definition: restclient.php:173
$result
$result
Definition: companysearch.php:94
$results
$results
Definition: companysearch.php:81
ezpRestAuthorizedClient
$def class ezpRestAuthorizedClient
Definition: ezprestauthorizedclient.php:14
$q
$q
Definition: modules/oauthadmin/list.php:17
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.