getter, setter are all final; several code clean-ups
[mailer.git] / inc / classes / main / class_BaseFrameworkSystem.php
1 <?php
2 /**
3  * The simulator system class is the super class of all other classes. This
4  * class handles saving of games etc.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.3.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.mxchange.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
26         /**
27          * The instance to the debug output handler (should be DebugConsoleOutput or DebugWebOutput)
28          *
29          * @see         DebugConsoleOutput
30          * @see         DebugWebOutput
31          */
32         private static $debug       = null;
33
34         /**
35          * The instance to the web output handler (should be WebOutput)
36          *
37          * @see         WebOutput
38          */
39         private static $webOutput   = null;
40
41         /**
42          * The instance to the compression layer which should be CompressorChannel
43          */
44         private static $compressor  = null;
45
46         /**
47          * The configuration instance which shall be FrameworkConfiguration
48          */
49         private static $cfgInstance = null;
50
51         /**
52          * The instance to the database layer which should be DatabaseConnection
53          */
54         private $dbInstance  = null;
55
56         /**
57          * The real class name
58          */
59         private $realClass      = "FrameworkSystem";
60
61         /**
62          * A human-readable description for this simulator part
63          */
64         private $partDescr      = "Namenlose Framework-Einheit";
65
66         /**
67          * The unique ID string for identifying all type of classes
68          */
69         private $uniqueID = "";
70
71         /**
72          * Thousands seperator
73          */
74         private $thousands = "."; // German
75
76         /**
77          * Decimal seperator
78          */
79         private $decimals  = ","; // German
80
81         /***********************
82          * Exception codes.... *
83          ***********************/
84
85         const EXCEPTION_IS_NULL_POINTER              = 0x001;
86         const EXCEPTION_IS_NO_OBJECT                 = 0x002;
87         const EXCEPTION_IS_NO_ARRAY                  = 0x003;
88         const EXCEPTION_MISSING_METHOD               = 0x004;
89         const EXCEPTION_CLASSES_NOT_MATCHING         = 0x005;
90         const EXCEPTION_INDEX_OUT_OF_BOUNDS          = 0x006;
91         const EXCEPTION_DIMENSION_ARRAY_INVALID      = 0x007;
92         const EXCEPTION_ITEM_NOT_TRADEABLE           = 0x008;
93         const EXCEPTION_ITEM_NOT_IN_PRICE_LIST       = 0x009;
94         const EXCEPTION_GENDER_IS_WRONG              = 0x00a;
95         const EXCEPTION_BIRTH_DATE_IS_INVALID        = 0x00b;
96         const EXCEPTION_EMPTY_STRUCTURES_ARRAY       = 0x00c;
97         const EXCEPTION_HAS_ALREADY_PERSONELL_LIST   = 0x00d;
98         const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES      = 0x00e;
99         const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED   = 0x00f;
100         const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS      = 0x010;
101         const EXCEPTION_CONTRACT_PARTNER_INVALID     = 0x011;
102         const EXCEPTION_CONTRACT_PARTNER_MISMATCH    = 0x012;
103         const EXCEPTION_CONTRACT_ALREADY_SIGNED      = 0x013;
104         const EXCEPTION_UNEXPECTED_EMPTY_STRING      = 0x014;
105         const EXCEPTION_PATH_NOT_FOUND               = 0x015;
106         const EXCEPTION_INVALID_PATH_NAME            = 0x016;
107         const EXCEPTION_READ_PROTECED_PATH           = 0x017;
108         const EXCEPTION_WRITE_PROTECED_PATH          = 0x018;
109         const EXCEPTION_DIR_POINTER_INVALID          = 0x019;
110         const EXCEPTION_FILE_POINTER_INVALID         = 0x01a;
111         const EXCEPTION_INVALID_DIRECTORY_POINTER    = 0x01b;
112         const EXCEPTION_UNEXPECTED_OBJECT            = 0x01c;
113         const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
114         const EXCEPTION_GETTER_IS_MISSING            = 0x01e;
115         const EXCEPTION_ARRAY_EXPECTED               = 0x01f;
116         const EXCEPTION_ARRAY_HAS_INVALID_COUNT      = 0x020;
117         const EXCEPTION_ID_IS_INVALID_FORMAT         = 0x021;
118         const EXCEPTION_MD5_CHECKSUMS_MISMATCH       = 0x022;
119         const EXCEPTION_UNEXPECTED_STRING_SIZE       = 0x023;
120         const EXCEPTION_SIMULATOR_ID_INVALID         = 0x024;
121         const EXCEPTION_MISMATCHING_COMPRESSORS      = 0x025;
122         const EXCEPTION_CONTAINER_ITEM_IS_NULL       = 0x026;
123         const EXCEPTION_ITEM_IS_NO_ARRAY             = 0x027;
124         const EXCEPTION_CONTAINER_MAYBE_DAMAGED      = 0x028;
125         const EXCEPTION_INVALID_STRING               = 0x029;
126         const EXCEPTION_VARIABLE_NOT_SET             = 0x02a;
127         const EXCEPTION_ATTRIBUTES_ARE_MISSING       = 0x02b;
128         const EXCEPTION_ARRAY_ELEMENTS_MISSING       = 0x02c;
129
130         /**
131          * In the super constructor these system classes shall be ignored or else
132          * we would get an endless calling loop.
133          *
134          *--------------------------------------------------------------------*
135          * ATTENTION: IF YOU REMOVE ONE OF THEM YOU WILL SHOOT YOUR SERVER!!! *
136          *--------------------------------------------------------------------*
137          */
138         private $systemClasses = array(
139                 "DebugMiddleware",                      // Debug middleware output sub-system
140                 "DebugWebOutput",                       // Debug web output sub-system
141                 "DebugConsoleOutput",           // Debug console output sub-system
142                 "DebugErrorLogOutput",          // Debug error_log() output sub-system
143                 "CompressorChannel",            // Compressor sub-system
144                 "FrameworkDirectoryPointer",    // Directory handler sub-system
145                 "NullCompressor",                       // Null compressor
146                 "Bzip2Compressor",                      // BZIP2 compressor
147                 "GzipCompressor",                       // GZIP compressor
148                 "WebOutput",                            // Web output sub-system
149         );
150
151         /**
152          * Private super constructor
153          *
154          * @return      void
155          */
156         private function __construct ($class) {
157                 // Set real class
158                 $this->setRealClass($class);
159         }
160
161         /**
162          * Destructor reached...
163          *
164          * @return      void
165          */
166         public function __destruct() {
167                 // Is this object already destroyed?
168                 if ($this->__toString() != "DestructedObject") {
169                         // Debug message
170                         if ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
171                                 $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt <strong>%s</strong> wird zerst&ouml;rt.<br />\n",
172                                         __CLASS__, $this->__toString()
173                                 ));
174                         }
175
176                         // Destroy all informations about this class but keep some text about it alive
177                         $this->setPartDescr(sprintf("Entferntes Objekt <em>%s</em>", $this->__toString()));
178                         $this->setRealClass("DestructedObject");
179                         $this->resetUniqueID();
180                 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
181                         // Already destructed object
182                         $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt <strong>%s</strong> wurde bereits zerst&ouml;rt.<br />\n",
183                                 __CLASS__, $this->__toString()
184                         ));
185                 }
186         }
187
188         /**
189          * The call method where all non-implemented methods end up
190          *
191          * @return      void
192          */
193         public final function __call ($methodName, $args) {
194                 // Implode all given arguments
195                 $argsString = implode("|", $args);
196                 if (empty($argsString)) $argsString = "NULL";
197
198                 $this->getDebugInstance()->output(sprintf("[%s::%s] Stub! Args: %s",
199                         $this->__toString(),
200                         $methodName,
201                         $argsString
202                 ));
203
204                 // Return nothing
205                 return null;
206         }
207
208         /**
209          * Public constructor (for initializing things, etc.)
210          *
211          * @return      void
212          */
213         public function constructor ($class) {
214                 // Call constructor
215                 $this->__construct($class);
216
217                 // Get the current (singleton) configuration instance
218                 $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration());
219
220                 // Is the class weather debug nor compressor channel?
221                 if (!in_array($class, $this->systemClasses)) {
222                         // Initialize debug instance
223                         if (is_null($this->getDebugInstance())) {
224                                 // Set the debug output system if it is not debug class ;)
225                                 $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig("debug_engine")));
226                         }
227
228                         // Initialize web instance
229                         if (is_null($this->getWebOutputInstance())) {
230                                 // Generate the eval() command
231                                 $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));",
232                                         $this->getConfigInstance()->readConfig("web_engine"),
233                                         $this->getConfigInstance()->readConfig("web_engine"),
234                                         $this->getConfigInstance()->readConfig("web_content_type")
235                                 );
236
237                                 // Debug message
238                                 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
239                                         $this->__toString(),
240                                         htmlentities($eval)
241                                 ));
242
243                                 // Run the command
244                                 eval($eval);
245                         }
246
247                         // Initialize compressor channel
248                         if (is_null($this->getCompressorChannel())) {
249                                 // Set the compressor channel
250                                 $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
251                                         PATH,
252                                         $this->getConfigInstance()->readConfig("compressor_base_path")
253                                 )));
254                         }
255
256                         // Initialize database middleware
257                         if (is_null($this->getDatabaseInstance())) {
258                                 // Get the middleware instance
259                                 $db = DatabaseConnection::getInstance();
260                                 if (is_object($db)) {
261                                         // Set the database middleware
262                                         $this->setDatabaseInstance($db);
263                                 }
264                         }
265
266                         // Debug output
267                         if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Alle Sub-Systeme sind initialisiert.<br />\n",
268                                 $this->__toString()
269                         ));
270                 }
271         }
272
273         /**
274          * Setter for language instance
275          *
276          * @param               $configInstance The configuration instance which shall
277          *                                                      be FrameworkConfiguration
278          * @return      void
279          */
280         public final function setConfigInstance (FrameworkConfiguration $configInstance) {
281                 $this->cfgInstance = $configInstance;
282                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Konfigurations-Handler auf <strong>%s</strong> gesetzt.<br />\n",
283                         $this->__toString(),
284                         $configInstance->__toString()
285                 ));
286         }
287
288         /**
289          * Getter for configuration instance
290          *
291          * @return      $cfhInstance - Configuration instance
292          */
293         public final function getConfigInstance () {
294                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Konfigurations-Handler <strong>%s</strong> angefordert.<br />\n",
295                         $this->__toString(),
296                         $this->cfgInstance->__toString()
297                 ));
298                 return $this->cfgInstance;
299         }
300
301         /**
302          * Setter for debug instance
303          *
304          * @param               $debugInstance  The instance for debug output class
305          * @return      void
306          */
307         public final function setDebugInstance (DebugMiddleware $debugInstance) {
308                 self::$debug = $debugInstance;
309                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Debug-Handler auf <strong>%s</strong> gesetzt.<br />\n",
310                         $this->__toString(),
311                         $this->getDebugInstance()->__toString()
312                 ));
313         }
314
315         /**
316          * Getter for debug instance
317          *
318          * @return      $debug - Instance to class DebugConsoleOutput or DebugWebOutput
319          */
320         public final function getDebugInstance () {
321                 return self::$debug;
322         }
323
324         /**
325          * Setter for web output instance
326          *
327          * @param               $webInstance    The instance for web output class
328          * @return      void
329          */
330         public final function setWebOutputInstance (OutputStreamer $webInstance) {
331                 self::$webOutput = $webInstance;
332                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Web-Handler auf <strong>%s</strong> gesetzt.<br />\n",
333                         $this->__toString(),
334                         $this->getWebOutputInstance()->__toString()
335                 ));
336         }
337
338         /**
339          * Getter for web output instance
340          *
341          * @return      $webOutput - Instance to class WebOutput
342          */
343         public final function getWebOutputInstance () {
344                 return self::$webOutput;
345         }
346
347         /**
348          * Static setter for database instance
349          *
350          * @param               $dbInstance     The instance for the database connection
351          *                                      (forced DatabaseConnection)
352          * @return      void
353          */
354         public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
355                 if ((defined('DEBUG_SYSTEM')) && (is_object($dbInstance->getDebugInstance()))) $dbInstance->getDebugInstance()->output(sprintf("[%s:] Datenbankschicht gesetzt.<br />\n",
356                         $dbInstance->__toString()
357                 ));
358                 $this->dbInstance = $dbInstance;
359         }
360
361         /**
362          * Getter for $realClass
363          *
364          * @return      $realClass The name of the real class (not BaseFrameworkSystem)
365          */
366         public final function __toString () {
367                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] __toString() erreicht.<br />\n",
368                         $this->realClass
369                 ));
370                 return $this->realClass;
371         }
372
373         /**
374          * Setter for the real class name
375          *
376          * @param               $realClass      Class name (string)
377          * @return      void
378          */
379         public final function setRealClass ($realClass) {
380                 // Cast to string
381                 $realClass = (string) $realClass;
382
383                 // Set real class
384                 $this->realClass = $realClass;
385         }
386
387         /**
388          * Generate unique ID from a lot entropy
389          *
390          * @return      void
391          */
392         public final function createUniqueID () {
393                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] createUniqueID aufgerufen.<br />\n",
394                         $this->__toString()
395                 ));
396
397                 // Existiert noch keine?
398                 if (empty($this->uniqueID)) {
399                         if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] createUniqueID erzeugt neue Unique-ID.<br />\n",
400                                 $this->__toString()
401                         ));
402
403                         // Correct missing class name
404                         $corrected = false;
405                         if ($this->__toString() == "") {
406                                 $this->setRealClass(__CLASS__);
407                                 $corrected = true;
408                         }
409
410                         // Neue ID erstellen
411                         $tempID = false;
412                         while (true) {
413                                 // Generate a unique ID number
414                                 $tempID = $this->generateIdNumber();
415                                 $isUsed = false;
416
417                                 // Try to figure out if the ID number is not yet used
418                                 try {
419                                         if (is_object($this->getDatabaseInstance())) {
420                                                 $isUsed = $this->getDatabaseInstance()->isUniqueIdUsed($tempID, true);
421                                         }
422                                 } catch (FrameworkException $e) {
423                                         // Catches all and ignores all ;-)
424                                 }
425
426                                 if (
427                                         (
428                                                 $tempID !== false
429                                         ) && (
430                                                 (
431                                                         $this->getDatabaseInstance() === null
432                                                 ) || (
433                                                         (
434                                                                 is_object($this->getDatabaseInstance())
435                                                         ) && (
436                                                                 !$isUsed
437                                                         )
438                                                 )
439                                         )
440                                 ) {
441                                         // Abort the loop
442                                         break;
443                                 }
444                         }
445
446                         // Debug message
447                         if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] uniqueID ist auf <strong>%s</strong> gesetzt.<br />\n",
448                                 $this->__toString(),
449                                 $tempID
450                         ));
451
452                         // Apply the new ID
453                         $this->setUniqueID($tempID);
454
455                         // Revert maybe corrected class name
456                         if ($corrected) {
457                                 $this->setRealClass("");
458                         }
459
460                         // Remove system classes if we are in a system class
461                         if ((isset($this->systemClasses)) && (in_array($this->__toString(), $this->systemClasses))) {
462                                 // This may save some RAM...
463                                 $this->removeSystemArray();
464                         }
465                 }
466         }
467
468         /**
469          * Generates a new ID number for classes based from the class' real name,
470          * the description and some random data
471          *
472          * @return      $tempID The new (temporary) ID number
473          */
474         private final function generateIdNumber () {
475                 return sprintf("%s@%s",
476                         $this->__toString(),
477                         md5(sprintf("%s:%s:%s:%s:%s:%s",
478                                 $this->__toString(),
479                                 $this->getPartDescr(),
480                                 time(),
481                                 getenv('REMOTE_ADDR'),
482                                 getenv('SERVER_ADDR'),
483                                 mt_rand()
484                         ))
485                 );
486         }
487
488         /**
489          * Setter for unique ID
490          *
491          * @param               $uniqueID               The newly generated unique ID number
492          * @return      void
493          */
494         private final function setUniqueID ($uniqueID) {
495                 // Cast to string
496                 $uniqueID = (string) $uniqueID;
497
498                 // Debug message
499                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Unique-ID gesetzt auf <u>%s</u>.<br />\n",
500                         $this->__toString(),
501                         $uniqueID
502                 ));
503
504                 // Set the ID number
505                 $this->uniqueID = $uniqueID;
506         }
507
508         /**
509          * Getter for unique ID
510          *
511          * @return      $uniqueID               The unique ID of this class
512          */
513         public final function getUniqueID () {
514                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Unique-ID angefordert.<br />\n",
515                         $this->__toString()
516                 ));
517                 return $this->uniqueID;
518         }
519
520         /**
521          * Resets or recreates the unique ID number
522          *
523          * @return      void
524          */
525         public final function resetUniqueID() {
526                 // Sweet and simple... ;-)
527                 $newUniqueID = $this->generateIdNumber();
528                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Unique-ID zur&uuml;ckgesetzt auf <u>%s</u>.<br />\n",
529                         $this->__toString(),
530                         $newUniqueID
531                 ));
532                 $this->setUniqueID($newUniqueID);
533         }
534
535         /**
536          * Getter for simulator description
537          *
538          * @return      $partDescr      The description of this simulation part
539          */
540         public final function getPartDescr () {
541                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] getPartDescr erreicht.<br />\n",
542                         $this->__toString()
543                 ));
544                 if (isset($this->partDescr)) {
545                         return $this->partDescr;
546                 } else {
547                         return null;
548                 }
549         }
550
551         /**
552          * Setter for simulation part description
553          *
554          * @param               $partDescr      The description as string for this simulation part
555          * @return      void
556          */
557         public final function setPartDescr ($partDescr) {
558                 $this->partDescr = (String) $partDescr;
559                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Teilbeschreibung wird auf <strong>%s</strong> gesetzt.<br />\n",
560                         $this->__toString(),
561                         $this->partDescr
562                 ));
563         }
564
565         /**
566          * Validate if given object is the same as current
567          *
568          * @param               $object An object instance for comparison with this class
569          * @return      boolean The result of comparing both's unique ID
570          */
571         public final function equals ($object) {
572                 return ($this->getUniqueID() == $object->getUniqueID());
573         }
574
575         /**
576          * Compare if both simulation part description and class name matches
577          * (shall be enougth)
578          *
579          * @param               $itemInstance   An object instance to an other class
580          * @return      boolean         The result of comparing class name simulation part description
581          */
582         public function itemMatches ($itemInstance) {
583                 return (
584                         (
585                                 $this->__toString()   == $itemInstance->__toString()
586                         ) && (
587                                 $this->getPartDescr() == $itemInstance->getPartDescr()
588                         )
589                 );
590         }
591
592         /**
593          * Compare class name of this and given class name
594          *
595          * @param               $class  The class name as string from the other class
596          * @return      boolean The result of comparing both class names
597          */
598         public final function isClass ($class) {
599                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%s</strong>=<strong>%s</strong>?<br />\n",
600                         $this->__toString(),
601                         $this->__toString(),
602                         $class
603                 ));
604                 return ($this->__toString() == $class);
605         }
606
607         /**
608          * Stub method (only real cabins shall override it)
609          *
610          * @return      boolean false = is no cabin, true = is a cabin
611          */
612         public function isCabin () {
613                 return false;
614         }
615
616         /**
617          * Stub method for tradeable objects
618          *
619          * @return      boolean false = is not tradeable by the Merchant class,
620          *                                      true  = is a tradeable object
621          */
622         public function isTradeable () {
623                 return false;
624         }
625
626         /**
627          * Formats computer generated price values into human-understandable formats
628          * with thousand and decimal seperators.
629          *
630          * @param               $value  The in computer format value for a price
631          * @param               $currency       The currency symbol (use HTML-valid characters!)
632          * @param               $decNum Number of decimals after commata
633          * @return      $price  The for the current language formated price string
634          * @throws      MissingDecimalsThousandsSeperatorException      If decimals or
635          *                                                                                              thousands seperator
636          *                                                                                              is missing
637          */
638         public function formatCurrency ($value, $currency = "&euro;", $decNum = 2) {
639                 // Are all required attriutes set?
640                 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
641                         // Throw an exception
642                         throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
643                 }
644
645                 // Cast the number
646                 $value = (float) $value;
647                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%d</strong> wird umformatiert.<br />\n",
648                         $this->__toString(),
649                         $value
650                 ));
651
652                 // Reformat the US number
653                 $price = sprintf("%s %s",
654                         number_format($value, $decNum, $this->decimals, $this->thousands),
655                         $currency
656                 );
657
658                 // Return as string...
659                 return $price;
660         }
661
662         /**
663          * Removes number formating characters
664          *
665          * @return      void
666          */
667         public final function removeNumberFormaters () {
668                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] Zahlenumformatierungszeichen werden entfernt.<br />\n",
669                         $this->__toString()
670                 ));
671                 unset($this->thousands);
672                 unset($this->decimals);
673         }
674
675         /**
676          * Getter for database layer
677          *
678          * @return      $dbInstance     The database layer instance
679          */
680         public final function getDatabaseInstance () {
681                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] Datenbank-Instanz <u>%s</u> angefordert.<br />\n",
682                         $this->__toString(),
683                         $this->dbInstance
684                 ));
685                 return $this->dbInstance;
686         }
687
688         /**
689          * Setter for compressor channel
690          *
691          * @param               $compressorChannel      An instance of CompressorChannel
692          * @return      void
693          */
694         public final function setCompressorChannel (CompressorChannel $compressorChannel) {
695                 self::$compressor = $compressorChannel;
696         }
697
698         /**
699          * Getter for compressor channel
700          *
701          * @return      $compressor     The compressor channel
702          */
703         public final function getCompressorChannel () {
704                 return self::$compressor;
705         }
706
707         /**
708          * Remove the $systemClasses array from memory
709          *
710          * @return      void
711          */
712         public final function removeSystemArray () {
713                 unset($this->systemClasses);
714         }
715
716         /**
717          * Create a file name and path name from the object's unique ID number.
718          * The left part of the ID shall always be a valid class name and the
719          * right part an ID number.
720          *
721          * @return      $pfn            The file name with a prepended path name
722          * @throws      NoArrayCreatedException If explode() fails to create an array
723          * @throws      InvalidArrayCountException      If the array contains less or
724          *                                                                      more than two elements
725          */
726         public final function getPathFileNameFromObject () {
727                 // Get the main object's unique ID. We use this as a path/filename combination
728                 $pathFile = $this->getUniqueID();
729
730                 // Split it up in path and file name
731                 $pathFile = explode("@", $pathFile);
732
733                 // Are there two elements? Index 0 is the path, 1 the file name + global extension
734                 if (!is_array($pathFile)) {
735                         // No array found
736                         throw new NoArrayCreatedException(array($this, "pathFile"), self::EXCEPTION_ARRAY_EXPECTED);
737                 } elseif (count($pathFile) != 2) {
738                         // Invalid ID returned!
739                         throw new InvalidArrayCountException(array($this, "pathFile", count($pathFile), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
740                 }
741
742                 // Auto-append missing trailing slash
743                 $pathFile[0] = $this->addMissingTrailingSlash($pathFile[0]);
744
745                 // Create the file name and return it
746                 $pfn = ($pathFile[0] . $pathFile[1]);
747                 return $pfn;
748         }
749
750         /**
751          * Appends a trailing slash to a string
752          *
753          * @param               $str            A string (maybe) without trailing slash
754          * @return      $str            A string with an auto-appended trailing slash
755          */
756         public final function addMissingTrailingSlash ($str) {
757                 // Is there a trailing slash?
758                 if (substr($str, -1, 1) != "/") $str .= "/";
759                 return $str;
760         }
761 }
762
763 // [EOF]
764 ?>