1e536a2013a172414ec2ea65d9063178d7030757
[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                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Ist <strong>%s</strong>=<strong>%s</strong>?<br />\n",
573                         $this->__toString(),
574                         $this->__toString(),
575                         $object->__toString()
576                 ));
577                 return ($this->getUniqueID() == $object->getUniqueID());
578         }
579
580         /**
581          * Compare if both simulation part description and class name matches
582          * (shall be enougth)
583          *
584          * @param               $itemInstance   An object instance to an other class
585          * @return      boolean         The result of comparing class name simulation part description
586          */
587         public function itemMatches ($itemInstance) {
588                 return (
589                            ($this->__toString()   == $itemInstance->__toString())
590                         && ($this->getPartDescr() == $itemInstance->getPartDescr())
591                 );
592         }
593
594         /**
595          * Compare class name of this and given class name
596          *
597          * @param               $class  The class name as string from the other class
598          * @return      boolean The result of comparing both class names
599          */
600         public final function isClass ($class) {
601                 if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%s</strong>=<strong>%s</strong>?<br />\n",
602                         $this->__toString(),
603                         $this->__toString(),
604                         $class
605                 ));
606                 return ($this->__toString() == $class);
607         }
608
609         /**
610          * Stub method (only real cabins shall override it)
611          *
612          * @return      boolean false = is no cabin, true = is a cabin
613          */
614         public function isCabin () {
615                 return false;
616         }
617
618         /**
619          * Stub method for tradeable objects
620          *
621          * @return      boolean false = is not tradeable by the Merchant class,
622          *                                      true  = is a tradeable object
623          */
624         public function isTradeable () {
625                 return false;
626         }
627
628         /**
629          * Formats computer generated price values into human-understandable formats
630          * with thousand and decimal seperators.
631          *
632          * @param               $value  The in computer format value for a price
633          * @param               $currency       The currency symbol (use HTML-valid characters!)
634          * @param               $decNum Number of decimals after commata
635          * @return      $price  The for the current language formated price string
636          * @throws      MissingDecimalsThousandsSeperatorException      If decimals or
637          *                                                                                              thousands seperator
638          *                                                                                              is missing
639          */
640         public function formatCurrency ($value, $currency = "&euro;", $decNum = 2) {
641                 // Are all required attriutes set?
642                 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
643                         // Throw an exception
644                         throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
645                 }
646
647                 // Cast the number
648                 $value = (float) $value;
649                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%d</strong> wird umformatiert.<br />\n",
650                         $this->__toString(),
651                         $value
652                 ));
653
654                 // Reformat the US number
655                 $price = sprintf("%s %s",
656                         number_format($value, $decNum, $this->decimals, $this->thousands),
657                         $currency
658                 );
659
660                 // Return as string...
661                 return $price;
662         }
663
664         /**
665          * Removes number formating characters
666          *
667          * @return      void
668          */
669         public final function removeNumberFormaters () {
670                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] Zahlenumformatierungszeichen werden entfernt.<br />\n",
671                         $this->__toString()
672                 ));
673                 unset($this->thousands);
674                 unset($this->decimals);
675         }
676
677         /**
678          * Getter for database layer
679          *
680          * @return      $dbInstance     The database layer instance
681          */
682         public final function getDatabaseInstance () {
683                 if (defined('DEBUG_CORE') && is_object($this->getDebugInstance())) $this->getDebugInstance()->output(sprintf("[%s:] Datenbank-Instanz <u>%s</u> angefordert.<br />\n",
684                         $this->__toString(),
685                         $this->dbInstance
686                 ));
687                 return $this->dbInstance;
688         }
689
690         /**
691          * Setter for compressor channel
692          *
693          * @param               $compressorChannel      An instance of CompressorChannel
694          * @return      void
695          */
696         public final function setCompressorChannel (CompressorChannel $compressorChannel) {
697                 self::$compressor = $compressorChannel;
698         }
699
700         /**
701          * Getter for compressor channel
702          *
703          * @return      $compressor     The compressor channel
704          */
705         public final function getCompressorChannel () {
706                 return self::$compressor;
707         }
708
709         /**
710          * Remove the $systemClasses array from memory
711          *
712          * @return      void
713          */
714         public final function removeSystemArray () {
715                 unset($this->systemClasses);
716         }
717
718         /**
719          * Create a file name and path name from the object's unique ID number.
720          * The left part of the ID shall always be a valid class name and the
721          * right part an ID number.
722          *
723          * @return      $pfn            The file name with a prepended path name
724          * @throws      NoArrayCreatedException If explode() fails to create an array
725          * @throws      InvalidArrayCountException      If the array contains less or
726          *                                                                      more than two elements
727          */
728         public function getPathFileNameFromObject () {
729                 // Get the main object's unique ID. We use this as a path/filename combination
730                 $pathFile = $this->getUniqueID();
731
732                 // Split it up in path and file name
733                 $pathFile = explode("@", $pathFile);
734
735                 // Are there two elements? Index 0 is the path, 1 the file name + global extension
736                 if (!is_array($pathFile)) {
737                         // No array found
738                         throw new NoArrayCreatedException(array($this, "pathFile"), self::EXCEPTION_ARRAY_EXPECTED);
739                 } elseif (count($pathFile) != 2) {
740                         // Invalid ID returned!
741                         throw new InvalidArrayCountException(array($this, "pathFile", count($pathFile), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
742                 }
743
744                 // Auto-append missing trailing slash
745                 $pathFile[0] = $this->addMissingTrailingSlash($pathFile[0]);
746
747                 // Create the file name and return it
748                 $pfn = ($pathFile[0] . $pathFile[1]);
749                 return $pfn;
750         }
751
752         /**
753          * Appends a trailing slash to a string
754          *
755          * @param               $str            A string (maybe) without trailing slash
756          * @return      $str            A string with an auto-appended trailing slash
757          */
758         public final function addMissingTrailingSlash ($str) {
759                 // Is there a trailing slash?
760                 if (substr($str, -1, 1) != "/") $str .= "/";
761                 return $str;
762         }
763 }
764
765 // [EOF]
766 ?>