ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
IsSuccessful.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
10 class IsSuccessful implements
12 {
13  public function validate(
16  ) {
17  if (!$response->isSuccess()) {
18  $result->addError($this->buildMessage($response->getStatus()));
19  }
20  }
21 
27  private function buildMessage(array $responseStatus)
28  {
29  return sprintf(
30  '%s%s%s',
31  $this->truncateStatus($responseStatus['Code']),
32  $responseStatus['SubCode'] ? '/' . $this->truncateStatus($responseStatus['SubCode']) : '',
33  $responseStatus['Message'] ? ' ' . $responseStatus['Message'] : ''
34  );
35  }
36 
43  private function truncateStatus($status)
44  {
45  $prefixLength = strlen(Constants::STATUS_PREFIX);
46  if (strpos($status, Constants::STATUS_PREFIX) !== 0) {
47  return $status;
48  }
49 
50  return substr($status, $prefixLength);
51  }
52 }
truncateStatus($status)
Truncate the status if it is prefixed by its urn.
Simple Result object.
Definition: Result.php:10
$result
getStatus()
Retrieve the status code.
const STATUS_PREFIX
The status namespace.
Definition: Constants.php:245
isSuccess()
Determine whether this is a successful response.
Create styles array
The data for the language used.
$response