private $headerCollection;
/** @var array */
- private $attributes = [];
+ private $pathParams = [];
/** @var string */
private $cookiePrefix;
return $this->headerCollection->getHeaderLine( $name );
}
- public function setAttributes( $attributes ) {
- $this->attributes = $attributes;
+ public function setPathParams( $params ) {
+ $this->pathParams = $params;
}
- public function getAttributes() {
- return $this->attributes;
+ public function getPathParams() {
+ return $this->pathParams;
}
- public function getAttribute( $name, $default = null ) {
- if ( array_key_exists( $name, $this->attributes ) ) {
- return $this->attributes[$name];
- } else {
- return $default;
- }
+ public function getPathParam( $name ) {
+ return $this->pathParams[$name] ?? null;
}
public function getCookiePrefix() {
* - queryParams: Equivalent to $_GET
* - uploadedFiles: An array of objects implementing UploadedFileInterface
* - postParams: Equivalent to $_POST
- * - attributes: The attributes, usually from path template parameters
+ * - pathParams: The path template parameters
* - headers: An array with the the key being the header name
* - cookiePrefix: A prefix to add to cookie names in getCookie()
*/
$this->queryParams = $params['queryParams'] ?? [];
$this->uploadedFiles = $params['uploadedFiles'] ?? [];
$this->postParams = $params['postParams'] ?? [];
- $this->setAttributes( $params['attributes'] ?? [] );
+ $this->setPathParams( $params['pathParams'] ?? [] );
$this->setHeaders( $params['headers'] ?? [] );
parent::__construct( $params['cookiePrefix'] ?? '' );
}
*/
function getUploadedFiles();
+ // MediaWiki extensions to PSR-7
+
/**
- * Retrieve attributes derived from the request.
- *
- * The request "attributes" may be used to allow injection of any
- * parameters derived from the request: e.g., the results of path
- * match operations; the results of decrypting cookies; the results of
- * deserializing non-form-encoded message bodies; etc. Attributes
- * will be application and request specific, and CAN be mutable.
+ * Get the parameters derived from the path template match
*
- * @return array Attributes derived from the request.
+ * @return string[]
*/
- function getAttributes();
+ function getPathParams();
/**
- * Retrieve a single derived request attribute.
+ * Retrieve a single path parameter.
*
- * Retrieves a single derived request attribute as described in
- * getAttributes(). If the attribute has not been previously set, returns
- * the default value as provided.
+ * Retrieves a single path parameter as described in getPathParams(). If
+ * the attribute has not been previously set, returns null.
*
- * This method obviates the need for a hasAttribute() method, as it allows
- * specifying a default value to return if the attribute is not found.
- *
- * @see getAttributes()
- * @param string $name The attribute name.
- * @param mixed|null $default Default value to return if the attribute does not exist.
- * @return mixed
+ * @see getPathParams()
+ * @param string $name The parameter name.
+ * @return string|null
*/
- function getAttribute( $name, $default = null );
-
- // MediaWiki extensions to PSR-7
+ function getPathParam( $name );
/**
- * Erase all attributes from the object and set the attribute array to the
- * specified value
+ * Erase all path parameters from the object and set the parameter array
+ * to the one specified.
*
- * @param mixed[] $attributes
+ * @param string[] $params
*/
- function setAttributes( $attributes );
+ function setPathParams( $params );
/**
* Get the current cookie prefix
}
}
- $request->setAttributes( $match['params'] );
+ $request->setPathParams( $match['params'] );
$spec = $match['userData'];
$objectFactorySpec = array_intersect_key( $spec,
[ 'factory' => true, 'class' => true, 'args' => true ] );
namespace MediaWiki\Rest;
/**
- * A handler base class which unpacks attributes from the path template and
+ * A handler base class which unpacks parameters from the path template and
* passes them as formal parameters to run().
*
* run() must be declared in the subclass. It cannot be declared as abstract
*/
class SimpleHandler extends Handler {
public function execute() {
- $params = array_values( $this->getRequest()->getAttributes() );
+ $params = array_values( $this->getRequest()->getPathParams() );
return $this->run( ...$params );
}
}