This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
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 #30 from burzum/develop
Merging develop to master for 1.0.4
- Loading branch information
Showing
5 changed files
with
416 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* FlashAndRedirectTrait | ||
* | ||
* @author Florian Krämer | ||
* @copyright 2013 - 2016 Florian Krämer | ||
* @license MIT | ||
*/ | ||
namespace Burzum\UserTools\Controller\Component; | ||
|
||
trait FlashAndRedirectTrait { | ||
|
||
/** | ||
* Helper property to detect a redirect | ||
* | ||
* @see UserToolComponent::handleFlashAndRedirect(); | ||
* @var \Cake\Network\Response | ||
*/ | ||
protected $_redirectResponse = null; | ||
|
||
/** | ||
* Handles flashes and redirects | ||
* | ||
* @param string $type Prefix for the array key, mostly "success" or "error" | ||
* @param array $options Options | ||
* @return mixed | ||
*/ | ||
public function handleFlashAndRedirect($type, $options) { | ||
$this->_handleFlash($type, $options); | ||
return $this->_handleRedirect($type, $options); | ||
} | ||
|
||
/** | ||
* Handles the redirect options. | ||
* | ||
* @param string $type Prefix for the array key, mostly "success" or "error" | ||
* @param array $options Options | ||
* @return mixed | ||
*/ | ||
protected function _handleRedirect($type, $options) { | ||
if (isset($options[$type . 'RedirectUrl']) && $options[$type . 'RedirectUrl'] !== false) { | ||
$controller = $this->_registry->getController(); | ||
$result = $controller->redirect($options[$type . 'RedirectUrl']); | ||
$this->_redirectResponse = $result; | ||
return $result; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Handles the flash options. | ||
* | ||
* @param string $type Prefix for the array key, mostly "success" or "error" | ||
* @param array $options Options | ||
* @return boolean | ||
*/ | ||
protected function _handleFlash($type, $options) { | ||
if (isset($options[$type . 'Message']) && $options[$type . 'Message'] !== false) { | ||
if (is_string($options[$type . 'Message'])) { | ||
$flashOptions = []; | ||
if (isset($options[$type . 'FlashOptions'])) { | ||
$flashOptions = $options[$type . 'FlashOptions']; | ||
} | ||
$this->Flash->$type($options[$type . 'Message'], $flashOptions); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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.