PHP Classes

File: include/core/WAMessage.lib

Recommend this page to a friend!
  Classes of philippe thomassigny  >  Dominion  >  include/core/WAMessage.lib  >  Download  
File: include/core/WAMessage.lib
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dominion
Build and execute portable SQL queries
Author: By
Last change: patch 8.00.05
Date: 5 years ago
Size: 4,189 bytes


Class file image Download

    WAMessage.lib, DomCore, the WebAbility(r) Core System
    Contains the static system messages
    (c) 2008-2010 Philippe Thomassigny

    This file is part of DomCore

    DomCore is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DomCore is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DomCore.  If not, see <>.

/* @UML_Box
| WAMessage: DomCore Static Messages                               |
| - ::messagesfile: array(filename => boolean)                     |
| - ::messagesloaded: boolean                                      |
| - ::messages: Array(string)                                      |
| + ::addMessages($messages: array(string) )                       |
| + ::setMessagesFile($file: string file path)                     |
| + ::getMessage($id: string) : string                             |
@End_UML_Box */

class WAMessage
  // directory to search for the static messages
  private static $messagesfiles = array();
  private static $messagesloaded = true;
  private static $messages = array(
    'WAMessage.notfound' => 'Error: The message was not found for the ID: ',
    'WAObject.badget' => 'Error: the attribute to read does not exist: ',
    'WAObject.badset' => 'Error: the attribute to write does not exist: ',
    'WAObject.badcall' => 'Error: the called method does not exist: ',
    'WAClass.serial' => 'Error: you must declare your own serial() method.',
    'WAClass.unserial' => 'Error: you must declare your own unserial() method.',
    'WAFile.mkdirproblem' => 'Error: the directory could not be created: ',
    'WAFile.unknownfile' => 'Error: the file is not recognized: ',
    'WAFile.baddir' => 'Error: the path to delete recursively is not compliant to be deleted: ',
    'WASHM.nosharedmemory' => 'Error: There is no available shared memory.',
    'WASHM.noattach' => 'Error: We could not attach to our shared memory.',
    'FileSource.file eerror' => 'Error: The file could not be opened for writing: ',
    'Singleton.noclone' => 'Error: the singleton already exists and cannot be cloned: ',
    'Multiton.noclone' => 'Error: the multiton already exists and cannot be cloned: '

  // adds messages for an external static class
  public static function addMessages($messages)
    foreach($messages as $k => $m)
      self::$messages[$k] = $m;

  // Sets the language messages file at the beginning of the application
  // If there is a need, the file will be loaded
  public static function setMessagesFile($file)
    self::$messagesloaded = false;
    self::$messagesfiles[$file] = false;

  // Get a message entry. If needed the file will be loaded
  public static function getMessage($id)
    if (!self::$messagesloaded)
      foreach(self::$messagesfiles as $file => $loaded)
        if ($loaded)
        // we read the static directory and load the language
        $size = @filesize($file);
        if ($size)
          $msg = WALanguageCompiler::compile(file_get_contents($file));

          if ($msg && is_array($msg))
            foreach(self::$messages as $k => $m)
              if (isset($msg[$k]))
                self::$messages[$k] = $msg[$k];
      self::$messagesloaded = true;
    if (isset(self::$messages[$id]))
      return self::$messages[$id];
    return self::$messages['WAMessage.notfound'].$id;