Skip to content

Commit

Permalink
Update Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonsimaogoncalves committed May 30, 2018
1 parent 336d199 commit 1117b26
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ApiController extends AppController
/**Before render callback.
*
* @param Event $event The beforeRender event.
*
* @return \Cake\Http\Response|null
* @throws \Exception
*/
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/ApiErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ApiErrorController extends AppController
* beforeRender callback.
*
* @param \Cake\Event\Event $event Event.
*
* @return null
* @throws \Exception
*/
Expand All @@ -27,7 +28,9 @@ public function beforeRender(Event $event)
$this->httpStatusCode = $this->getResponse()->getStatusCode();

if (Configure::read('ApiRequest.debug') && isset($this->viewVars['error'])) {
$this->apiResponse[$this->responseFormat['messageKey']] = $this->viewVars['error']->getMessage();
$error = $this->viewVars['error'];
/** @var \Exception $error */
$this->apiResponse[$this->responseFormat['messageKey']] = $error->getMessage();
} else {
$this->apiResponse[$this->responseFormat['messageKey']] = !empty($messageArr[$this->httpStatusCode]) ? $messageArr[$this->httpStatusCode] : 'Unknown error!';
}
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function initialize()
* Before render callback.
*
* @param Event $event The beforeRender event.
*
* @return \Cake\Http\Response|null
* @throws \Exception
*/
Expand Down Expand Up @@ -130,6 +131,7 @@ public function beforeRender(Event $event)

/**
* @param $data
*
* @return array
* @throws \Exception
* @throws \Exception
Expand Down Expand Up @@ -166,7 +168,8 @@ public function getSerializer()

/**
* @param \League\Fractal\Manager $manager
* @param $var
* @param $var
*
* @return array
* @throws \Exception
*/
Expand All @@ -189,6 +192,7 @@ protected function transform(Manager $manager, $var)

/**
* @param $var
*
* @return bool|\League\Fractal\TransformerAbstract
* @throws \Exception
*/
Expand Down Expand Up @@ -218,6 +222,7 @@ protected function getTransformer($var)

/**
* @param $var
*
* @return bool|string
*/
protected function getTransformerClass($var)
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Component/AccessControlComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AccessControlComponent extends Component
* Handles request authentication using JWT.
*
* @param Event $event The startup event
*
* @return \Cake\Http\Response|boolean
*/
public function startup(Event $event)
Expand All @@ -41,6 +42,7 @@ public function startup(Event $event)
* Performs token validation.
*
* @param Event $event The startup event
*
* @return bool
*/
protected function _performTokenValidation(Event $event)
Expand Down
6 changes: 5 additions & 1 deletion src/Error/ApiExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ApiExceptionRenderer extends ExceptionRenderer
* Handles MissingTokenException.
*
* @param $exception
*
* @return \Cake\Http\Response
*/
public function missingToken($exception)
Expand All @@ -30,7 +31,8 @@ public function missingToken($exception)
* Prepare response.
*
* @param \Exception $exception Exception
* @param array $options Array of options
* @param array $options Array of options
*
* @return \Cake\Http\Response
*/
private function __prepareResponse($exception, $options = [])
Expand Down Expand Up @@ -70,6 +72,7 @@ protected function _getController()
/**Handles InvalidTokenFormatException.
*
* @param \RestApi\Routing\Exception\InvalidTokenFormatException $exception InvalidTokenFormatException
*
* @return \Cake\Http\Response
*/
public function invalidTokenFormat($exception)
Expand All @@ -81,6 +84,7 @@ public function invalidTokenFormat($exception)
* Handles InvalidTokenException.
*
* @param \RestApi\Routing\Exception\InvalidTokenException $exception InvalidTokenException
*
* @return \Cake\Http\Response
*/
public function invalidToken($exception)
Expand Down
1 change: 1 addition & 0 deletions src/Event/ApiRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function implementedEvents()
* Handles incoming request and its data.
*
* @param Event $event The beforeDispatch event
*
* @return array|mixed|null
*/
public function beforeDispatch(Event $event)
Expand Down
7 changes: 4 additions & 3 deletions src/Middleware/RestApiMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class RestApiMiddleware extends ErrorHandlerMiddleware
/**
* Override ErrorHandlerMiddleware and add custom exception renderer
*
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
* @param \Psr\Http\Message\ResponseInterface $response The response.
* @param callable $next Callback to invoke the next middleware.
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
* @param \Psr\Http\Message\ResponseInterface $response The response.
* @param callable $next Callback to invoke the next middleware.
*
* @return \Psr\Http\Message\ResponseInterface A response
*/
public function __invoke($request, $response, $next)
Expand Down
18 changes: 9 additions & 9 deletions src/Model/Entity/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
/**
* Class ApiRequest
*
* @property string $id
* @property string $http_method
* @property string $endpoint
* @property string $token
* @property string $ip_address
* @property string $request_data
* @property int $response_code
* @property string $response_data
* @property string $exception
* @property string $id
* @property string $http_method
* @property string $endpoint
* @property string $token
* @property string $ip_address
* @property string $request_data
* @property int $response_code
* @property string $response_data
* @property string $exception
* @property \Cake\I18n\Time $created
* @property \Cake\I18n\Time $modified
*
Expand Down
1 change: 1 addition & 0 deletions src/Model/Table/ApiRequestsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ApiRequestsTable extends Table
* Initialize method
*
* @param array $config The configuration for the Table.
*
* @return void
*/
public function initialize(array $config)
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/Exception/InvalidTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class InvalidTokenException extends Exception
/**
* InvalidTokenException constructor.
*
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param \Exception|null $previous the previous exception.
*/
public function __construct($message = null, $code = 401, $previous = null)
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/Exception/InvalidTokenFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class InvalidTokenFormatException extends Exception
/**
* InvalidTokenFormatException constructor.
*
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param \Exception|null $previous the previous exception.
*/
public function __construct($message = null, $code = 401, $previous = null)
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/Exception/MissingTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class MissingTokenException extends Exception
/**
* MissingTokenException constructor.
*
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
* @param int $code The code of the error, is also the HTTP status code for the error.
* @param \Exception|null $previous the previous exception.
*/
public function __construct($message = null, $code = 401, $previous = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/ArraySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArraySerializer extends Serializer
* Serialize a collection.
*
* @param string $resourceKey resource key
* @param array $data data
* @param array $data data
*
* @return array
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Utility/ApiRequestLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ApiRequestLogger
/**
* Logs the request and response data into database.
*
* @param \Cake\Http\ServerRequest $request The \Cake\Network\Request object
* @param \Cake\Http\Response $response The \Cake\Http\Response object
* @param \Cake\Http\ServerRequest $request The \Cake\Network\Request object
* @param \Cake\Http\Response $response The \Cake\Http\Response object
*/
public static function log(ServerRequest $request, Response $response)
{
Expand Down
1 change: 1 addition & 0 deletions src/Utility/JwtToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class JwtToken
* Generates a token based on payload
*
* @param mixed $payload Payload data to generate token
*
* @return string|bool Token or false
*/
public static function generateToken($payload = null)
Expand Down
3 changes: 2 additions & 1 deletion src/View/ApiErrorView.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function initialize()
/**
* Renders custom api error view
*
* @param string|null $view Name of view file to use
* @param string|null $view Name of view file to use
* @param string|null $layout Layout to use.
*
* @return string|null Rendered content or null if content already rendered and returned earlier.
* @throws \Cake\Core\Exception\Exception If there is an error in the view.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/View/ApiView.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function initialize()
/**
* Renders api response
*
* @param string|null $view Name of view file to use
* @param string|null $view Name of view file to use
* @param string|null $layout Layout to use.
*
* @return string|null Rendered content or null if content already rendered and returned earlier.
* @throws \Cake\Core\Exception\Exception If there is an error in the view.
*/
Expand Down

0 comments on commit 1117b26

Please sign in to comment.