Skip to content

Commit

Permalink
add parseMessage in utility trait
Browse files Browse the repository at this point in the history
  • Loading branch information
PutraSudaryanto committed Jul 29, 2018
1 parent 37cac74 commit 4cb20c5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions UtilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* licenseCode
* dateFormat
* parseYML
* parseTemplate
*
*/

Expand Down Expand Up @@ -155,4 +156,27 @@ public static function parseYML($path)

return $arraySpyc;
}

/**
* Method for parsing string
*
* @param string $message Source string for parsing
* @param array $attribute of example
* [
* '{link}' => 'https://github.com/ommu/mod-mailer',
* '{author}' => Yii::$app->user->email
* ]
*
* @return string
*/
public function parseTemplate($message, $attribute)
{
foreach ($attribute as $key => $value) {
$message = strtr($message, [
'{'.$key.'}' => $value,
]);
}

return $message;
}
}

0 comments on commit 4cb20c5

Please sign in to comment.