ソースを参照

Type hint options array param, use + operater for array merge, update docblocks

Bryan Crowe 11 年 前
コミット
cf19f58e53

+ 7 - 4
src/Controller/Component/FlashComponent.php

@@ -20,14 +20,15 @@ use Cake\Utility\Inflector;
 use Cake\Error\InternalErrorException;
 use Cake\Event\Event;
 
-
 /**
- * FlashComponent
+ * The CakePHP FlashComponent provides a way for you to write a flash variable
+ * to the session from your controllers, to be rendered in a view with the
+ * FlashHelper.
  */
 class FlashComponent extends Component {
 
 /**
- * The session
+ * The Session object instance
  *
  * @var \Cake\Network\Session
  */
@@ -64,7 +65,6 @@ class FlashComponent extends Component {
  *
  * - `key` The key to set under the session's Message key
  * - `element` The element used to render the flash message
- * - `escape` Whether or not to escape the flash message, defaults to true
  * - `params` An array of variables to make available when using an element
  *
  * @param string $message Message to be flashed
@@ -89,6 +89,9 @@ class FlashComponent extends Component {
 /**
  * Magic method for verbose flash methods based on element names.
  *
+ * For example: $this->Flash->success('My message') would use the
+ * flash_success.ctp element for rendering the flash message.
+ *
  * @param string $name Element name to use, omitting the "flash_" prefix.
  * @param array $args Parameters to pass when calling `FlashComponent::set`.
  * @return void

+ 3 - 11
src/View/Helper/FlashHelper.php

@@ -36,21 +36,13 @@ class FlashHelper extends Helper {
  * to consolidate all the parameters for a given type of flash message into the view.
  *
  * {{{
- * echo $this->Flash->render('flash', ['class' => 'new-flash']);
- * }}}
- *
- * The above would generate a flash message with a custom class name. Using $attrs['params'] you
- * can pass additional data into the element rendering that will be made available as local variables
- * when the element is rendered:
- *
- * {{{
  * echo $this->Flash->render('flash', ['params' => ['name' => $user['User']['name']]]);
  * }}}
  *
  * This would pass the current user's name into the flash message, so you could create personalized
  * messages without the controller needing access to that data.
  *
- * Lastly you can choose the element that is rendered when creating the flash message. Using
+ * Lastly you can choose the element that is rendered when rendering the flash message. Using
  * custom elements allows you to fully customize how flash messages are generated.
  *
  * {{{
@@ -71,7 +63,7 @@ class FlashHelper extends Helper {
  *    Supports the 'params', and 'element' keys that are used in the helper.
  * @return string
  */
-	public function render($key = 'flash', $options = []) {
+	public function render($key = 'flash', array $options = []) {
 		$flash = $this->request->session()->read("Message.$key");
 		$this->request->session()->delete("Message.$key");
 
@@ -79,7 +71,7 @@ class FlashHelper extends Helper {
 			return '';
 		}
 
-		$flash = array_merge($flash, $options);
+		$flash = $options + $flash;
 
 		if ($flash['element'] === null) {
 			return $flash['message'];