public static function getMessages($directory, $exclude, $pattern, $depth=0) {

    if ($depth == 0) {
      self::$baseDir = $directory;
    }
    if (substr($directory, -1) != '/') {
      $directory .= '/';
    }
    if (is_dir($directory)) {
      $d = dir($directory);
      $d->rewind();
      while(false !== ($file = $d->read())) {
        if($file != '.' && $file != '..' && !in_array($file, $exclude)) {
          if (is_dir($directory.$file)) {
            self::getMessages($directory.$file, $exclude, $pattern, ++$depth);
          }
          elseif (preg_match($pattern, $file)) {
            $messages = self::getMessagesFromFile($directory.$file);
            if (sizeof($messages) > 0) {
              $key = str_replace(self::$baseDir, '', $directory.$file);
              self::$result[$key] = $messages;
            }
          }
        }
      }
      $d->close();
    }
    else {
      throw new IllegalArgumentException("The directory '".$directory."' does not exist.");
    }
    return self::$result;
  }