Skip to content

Reply Class Reference

Ryan Durham edited this page Jan 23, 2016 · 6 revisions

The methods in the authManager class all return instances of the Centaur\Replies\Reply class, which is designed to be a general purpose data transfer object with a few Laravel niceties thrown in for good measure. There are three types of Reply object:

  • Centaur\Replies\SuccessReply - Returned when the requested action was accomplished successfully.
  • Centaur\Replies\FailureReply - Returned when the requested action failed.
  • Centaur\Replies\ExceptionReply - Returned if the requested action caught an exception.

The Reply may contain a payload containing objects relevant to the requested action. Payload objects can be accessed through the __get() magic method. For example, if the payload has a $user, you can retrieve it like so: $user = $reply->user;.

Api

$reply->isSuccessful()

Returns: Boolean

Indicates whether the requested action was successful.

$reply->isFailure()

Returns: Boolean

Indicates whether the requested action failed.

$reply->has($key)

Returns: Boolean

Indicates whether the requested value exists within the object. For example: $reply->has('message'), $reply->has('user') or $reply->has('exception')

$reply->remove($key)

Returns: void

Remove the requested value from the object if it exists.

$reply->clearPayload()

Returns: void

Remove the entire payload from this object, whatever it may be.

$reply->setRedirectUrl()

Returns: void

Occasionally you may want to override the default redirect location in the dispatch() method; this method lets you do that.

$reply->toArray()

Returns: array

Convert the object to an array

$reply->toJson()

Returns: string

Convert the object to a json string.

$reply->dispatch($url)

Returns: Illuminate\Http\RedirectResponse or Illuminate\Http\JsonResponse

A helper method for determining how a controller should respond to the authManager results. It will automatically return json for ajax request, or redirects for http requests. Successful or failed replies will redirect to the specified $url, whereas a reply that caught an exception will redirect to the previous url (unless you manually specify a different redirect location.)

Clone this wiki locally