2011-01-24 09:00:29 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-10 16:48:59 -08:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-24 09:00:29 -08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-07-04 12:03:36 -07:00
|
|
|
/**
|
|
|
|
* @group conduit
|
|
|
|
*/
|
2011-01-24 09:00:29 -08:00
|
|
|
class ConduitAPIRequest {
|
|
|
|
|
|
|
|
protected $params;
|
2011-04-07 18:27:39 -07:00
|
|
|
private $user;
|
2011-01-24 09:00:29 -08:00
|
|
|
|
|
|
|
public function __construct(array $params) {
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2012-03-06 15:12:27 -08:00
|
|
|
public function getValue($key, $default = null) {
|
|
|
|
return coalesce(idx($this->params, $key), $default);
|
2011-01-24 09:00:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllParameters() {
|
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
2012-01-10 16:48:59 -08:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
2011-04-07 18:27:39 -07:00
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the authentic identity of the user making the request. If a
|
|
|
|
* method requires authentication (the default) the user object will always
|
|
|
|
* be available. If a method does not require authentication (i.e., overrides
|
|
|
|
* shouldRequireAuthentication() to return false) the user object will NEVER
|
|
|
|
* be available.
|
|
|
|
*
|
|
|
|
* @return PhabricatorUser Authentic user, available ONLY if the method
|
|
|
|
* requires authentication.
|
|
|
|
*/
|
|
|
|
public function getUser() {
|
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception(
|
|
|
|
"You can not access the user inside the implementation of a Conduit ".
|
|
|
|
"method which does not require authentication (as per ".
|
|
|
|
"shouldRequireAuthentication()).");
|
|
|
|
}
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2011-01-24 09:00:29 -08:00
|
|
|
}
|