示例#1
0
 /**
  * Returns a message according to locale
  * @param $key String Name of the key in I18n YAML file
  * @param $args Array Associative array string=>mixed for arguments replacement
  * @param $locale String Current locale overriding
  * @return String The translated message with arguments
  */
 public static function t($key, $args = [], $locale = null)
 {
     Arguments::validate($key, ['string']);
     if ($locale === null) {
         $locale = self::getLocale();
     }
     $yml = Yaml::parse(file_get_contents(self::LOCALES_PATH . "/{$locale}.yml"));
     $defaultMessage = strtr($key, [self::YAML_WORD_SEPARATOR => " "]);
     $message = self::traverse($yml, "{$locale}.{$key}", $defaultMessage);
     $injectedMessage = self::injectArguments($message, $args);
     return $injectedMessage;
 }
示例#2
0
 /**
  * Apply styles to output
  * @param $str String to be styled
  * @param $styles String or Array<String> with styles to apply
  * Examples:
  *
  * Console::apply('Bob is going home', 'italic');
  * Console::apply('Bob is going home', ['italic', 'red']);
  *
  * @return String styled
  */
 public static function apply($str, $styles)
 {
     Arguments::validate($str, ['string']);
     Arguments::validate($styles, ['string', 'array']);
     if (!is_array($styles)) {
         $styles = [$styles];
     }
     foreach ($styles as $style) {
         $str = self::_apply($str, $style);
     }
     return $str;
 }
 /**
  * Complains if argument is not one of expected types
  * @expectedException InvalidArgumentException
  */
 public function testInvalidInputAnyOf()
 {
     $this->assertTrue(Arguments::validate(false, ["array", "string"]));
 }