-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from conord33/conor/develop/userupdatebugfix
Conor/develop/userupdatebugfix
- Loading branch information
Showing
43 changed files
with
983 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace MABI; | ||
|
||
include_once __DIR__ . '/ErrorResponseDictionary.php'; | ||
|
||
class DefaultAppErrors extends ErrorResponseDictionary { | ||
public static $NOT_AUTHORIZED = array( | ||
'NOT_AUTHORIZED' => array( | ||
'message' => 'Not properly authenticated for this route', | ||
'httpcode' => 401, | ||
'code' => 1007 | ||
) | ||
); | ||
|
||
public static $ENTRY_EXISTS = array( | ||
'ENTRY_EXISTS' => array( | ||
'message' => 'An entry with the id !modelid already exists.', | ||
'httpcode' => 409, | ||
'code' => 1008 | ||
) | ||
); | ||
|
||
public static $INVALID_JSON = array( | ||
'INVALID_JSON' => array( | ||
'message' => 'Could not load model from json: !message', | ||
'httpcode' => 400, | ||
'code' => 1009 | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace MABI; | ||
|
||
class ErrorResponseDictionary { | ||
/** | ||
* @var ErrorResponse[] | ||
*/ | ||
protected $errorResponses = array(); | ||
|
||
/** | ||
* Should be in the format (all required): | ||
* static $SAMPLE_ERROR_KEY = array( | ||
* 'message' => 'sample error message', | ||
* 'httpcode' => '401', | ||
* 'code' => 1); // optional | ||
*/ | ||
function __construct() { | ||
$rClass = new \ReflectionClass(get_called_class()); | ||
$rProperties = $rClass->getProperties(\ReflectionProperty::IS_STATIC); | ||
$defaultProps = $rClass->getDefaultProperties(); | ||
foreach ($rProperties as $rProperty) { | ||
$ignoreAnnotation = ReflectionHelper::getDocDirective($rProperty->getDocComment(), 'ignore'); | ||
if (!empty($ignoreAnnotation) || !is_array($defaultProps[$rProperty->getName()]) || | ||
empty($defaultProps[$rProperty->getName()]) | ||
) { | ||
continue; | ||
} | ||
|
||
$propertyKeys = array_keys($defaultProps[$rProperty->getName()]); | ||
$key = $propertyKeys[0]; | ||
$errorResponseArray = $defaultProps[$rProperty->getName()][$key]; | ||
if (empty($errorResponseArray['message']) || empty($errorResponseArray['httpcode'])) { | ||
continue; | ||
} | ||
|
||
$this->errorResponses[$key] = ErrorResponse::FromArray($errorResponseArray); | ||
} | ||
} | ||
|
||
/** | ||
* Creates or overrides error responses with an initialization array in mass | ||
* | ||
* @param $initArray | ||
*/ | ||
public function overrideErrorResponses(ErrorResponseDictionary $overridingDictionary) { | ||
foreach ($overridingDictionary->errorResponses as $key => $errorResponse) { | ||
$this->errorResponses[$key] = $errorResponse; | ||
} | ||
} | ||
|
||
public function overrideErrorResponse($key, ErrorResponse $errorResponse) { | ||
$this->errorResponses[$key] = $errorResponse; | ||
} | ||
|
||
/** | ||
* todo: docs | ||
* | ||
* @param $key | ||
* | ||
* @return ErrorResponse|null | ||
*/ | ||
public function getErrorResponse($key) { | ||
if (empty($this->errorResponses[$key])) { | ||
return NULL; | ||
} | ||
|
||
return $this->errorResponses[$key]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.