Continued:
[core.git] / framework / bootstrap / class_FrameworkBootstrap.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Bootstrap;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration;
7 use Org\Mxchange\CoreFramework\Connection\Database\DatabaseConnection;
8 use Org\Mxchange\CoreFramework\Connector\Database\DatabaseConnector;
9 use Org\Mxchange\CoreFramework\Console\Tools\ConsoleTools;
10 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
11 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
12 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
13 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
14 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
15 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
16 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
17 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
18 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
19 use Org\Mxchange\CoreFramework\Request\Requestable;
20 use Org\Mxchange\CoreFramework\Response\Responseable;
21
22 // Import SPL stuff
23 use \BadMethodCallException;
24 use \InvalidArgumentException;
25 use \SplFileInfo;
26
27 /**
28  * A framework-bootstrap class which helps the frameworks to bootstrap ... ;-)
29  *
30  * @author              Roland Haeder <webmaster@ship-simu.org>
31  * @version             0.0.0
32  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
33  * @license             GNU GPL 3.0 or any newer version
34  * @link                http://www.ship-simu.org
35  *
36  * This program is free software: you can redistribute it and/or modify
37  * it under the terms of the GNU General Public License as published by
38  * the Free Software Foundation, either version 3 of the License, or
39  * (at your option) any later version.
40  *
41  * This program is distributed in the hope that it will be useful,
42  * but WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44  * GNU General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License
47  * along with this program. If not, see <http://www.gnu.org/licenses/>.
48  */
49 final class FrameworkBootstrap {
50
51         /**
52          * Detected server address
53          */
54         private static $serverAddress = NULL;
55
56         /**
57          * Instance of a Requestable class
58          */
59         private static $requestInstance = NULL;
60
61         /**
62          * Instance of a Responseable class
63          */
64         private static $responseInstance = NULL;
65
66         /**
67          * Instance of a FrameworkConfiguration class
68          */
69         private static $configurationInstance = NULL;
70
71         /**
72          * Database instance
73          */
74         private static $databaseInstance = NULL;
75
76         /*
77          * Includes applications may have. They will be tried in the given order,
78          * some will become soon deprecated.
79          */
80         private static $configAppIncludes = array(
81                 // The ApplicationHelper class (required)
82                 'class_ApplicationHelper' => 'required',
83                 // Some debugging stuff (optional but can be committed)
84                 'debug'                   => 'optional',
85                 // Application's exception handler (optional but can be committed)
86                 'exceptions'              => 'optional',
87                 // Application's configuration file (committed, non-local specific)
88                 'config'                  => 'required',
89                 // Local configuration file (optional, not committed, listed in .gitignore)
90                 'config-local'            => 'optional',
91                 // Application data (deprecated)
92                 'data'                    => 'deprecated',
93                 // Application loader (deprecated)
94                 'loader'                  => 'deprecated',
95                 // Application initializer (deprecated)
96                 'init'                    => 'deprecated',
97                 // Application starter (deprecated)
98                 'starter'                 => 'deprecated',
99         );
100
101         /**
102          * Private constructor, no instance is needed from this class as only
103          * static methods exist.
104          */
105         private function __construct () {
106                 // Prevent making instances from this "utilities" class
107         }
108
109         /**
110          * Some "getter" for a configuration instance, making sure, it is unique
111          *
112          * @return      $configurationInstance  An instance of a FrameworkConfiguration class
113          */
114         public static function getConfigurationInstance () {
115                 // Is the instance there?
116                 if (is_null(self::$configurationInstance)) {
117                         // Init new instance
118                         self::$configurationInstance = new FrameworkConfiguration();
119                 } // END - if
120
121                 // Return it
122                 return self::$configurationInstance;
123         }
124
125         /**
126          * "Getter" to get response/request type from analysis of the system.
127          *
128          * @return      $requestType    Analyzed request type
129          */
130         public static function getRequestTypeFromSystem () {
131                 // Default is console
132                 $requestType = 'console';
133
134                 // Is 'HTTP_HOST' set?
135                 if (isset($_SERVER['HTTP_HOST'])) {
136                         // Then it is a HTML response/request.
137                         $requestType = 'html';
138                 } // END - if
139
140                 // Return it
141                 return $requestType;
142         }
143
144         /**
145          * Checks whether the given file/path is in open_basedir(). This does not
146          * gurantee that the file is actually readable and/or writeable. If you need
147          * such gurantee then please use isReadableFile() instead.
148          *
149          * @param       $fileInstance   An instance of a SplFileInfo class
150          * @return      $isReachable    Whether it is within open_basedir()
151          */
152         public static function isReachableFilePath (SplFileInfo $fileInstance) {
153                 // Is not reachable by default
154                 $isReachable = false;
155
156                 // Get open_basedir parameter
157                 $openBaseDir = trim(ini_get('open_basedir'));
158
159                 // Is it set?
160                 if (!empty($openBaseDir)) {
161                         // Check all entries
162                         foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) {
163                                 // Check on existence
164                                 if (substr($fileInstance->getPathname(), 0, strlen($dir)) == $dir) {
165                                         // Is reachable
166                                         $isReachable = true;
167
168                                         // Abort lookup as it has been found in open_basedir
169                                         break;
170                                 } // END - if
171                         } // END - foreach
172                 } else {
173                         // If open_basedir is not set, all is allowed
174                         $isReachable = true;
175                 }
176
177                 // Return status
178                 return $isReachable;
179         }
180
181         /**
182          * Checks whether the give file is within open_basedir() (done by
183          * isReachableFilePath()), is actually a file and is readable.
184          *
185          * @param       $fileInstance   An instance of a SplFileInfo class
186          * @return      $isReadable             Whether the file is readable (and therefor exists)
187          */
188         public static function isReadableFile (SplFileInfo $fileInstance) {
189                 // Default is not readable
190                 $isReadable = false;
191
192                 // Check if it is a file and readable
193                 $isReadable = (
194                         (
195                                 self::isReachableFilePath($fileInstance)
196                         ) && (
197                                 $fileInstance->isFile()
198                         ) && (
199                                 $fileInstance->isReadable()
200                         )
201                 );
202
203                 // Return status
204                 return $isReadable;
205         }
206
207         /**
208          * Loads given include file
209          *
210          * @param       $fileInstance   An instance of a SplFileInfo class
211          * @return      void
212          * @throws      InvalidArgumentException        If file was not found or not readable or deprecated
213          */
214         public static function loadInclude (SplFileInfo $fileInstance) {
215                 // Trace message
216                 //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance);
217
218                 // Should be there ...
219                 if (!self::isReadableFile($fileInstance)) {
220                         // Abort here
221                         throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname()));
222                 } // END - if
223
224                 // Load it
225                 require_once $fileInstance->getPathname();
226
227                 // Trace message
228                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
229         }
230
231         /**
232          * Does the actual bootstrap
233          *
234          * @return      void
235          */
236         public static function doBootstrap () {
237                 // Load basic include files to continue bootstrapping
238                 self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
239                 self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sclass_BaseFrameworkSystem.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
240                 self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
241                 self::loadInclude(new SplFileInfo(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR)));
242
243                 // Load global configuration
244                 self::loadInclude(new SplFileInfo(sprintf('%s%s', ApplicationEntryPoint::detectFrameworkPath(), 'config-global.php')));
245         }
246
247         /**
248          * Initializes the framework by scanning for all framework-relevant
249          * classes, interfaces and exception. Then determine the request type and
250          * initialize a Requestable instance which will then contain all request
251          * parameter, also from CLI. Next step is to validate the application
252          * (very basic).
253          *
254          * @return      void
255          */
256         public static function initFramework () {
257                 /**
258                  * 1) Load class loader and scan framework classes, interfaces and
259                  *    exceptions.
260                  */
261                 self::scanFrameworkClasses();
262
263                 /*
264                  * 2) Determine the request type, console or web and store request and
265                  *    response here. This also initializes the request instance will
266                  *    all given parameters (see doc-tag for possible sources of
267                  *    parameters).
268                  */
269                 self::determineRequestType();
270
271                 /*
272                  * 3) Now, that there are all request parameters being available, check
273                  *    if 'application' is supplied. If it is not found, abort execution, if
274                  *    found, continue below with next step.
275                  */
276                 self::validateApplicationParameter();
277         }
278
279         /**
280          * Initializes the detected application. This may fail if required files
281          * are not found in the application's base path (not to be confused with
282          * 'application_base_path' which only points to /some/foo/application/.
283          *
284          * @return      void
285          */
286         public static function prepareApplication () {
287                 // Configuration entry 'detected_app_name' must be set, get it here, including full path
288                 $application = self::getConfigurationInstance()->getConfigEntry('detected_app_name');
289                 $fullPath    = self::getConfigurationInstance()->getConfigEntry('detected_full_app_path');
290
291                 /*
292                  * Now check and load all files, found deprecated files will throw a
293                  * warning at the user.
294                  */
295                 foreach (self::$configAppIncludes as $fileName => $status) {
296                         // Construct file instance
297                         $fileInstance = new SplFileInfo(sprintf('%s%s.php', $fullPath, $fileName));
298
299                         // Determine if this file is wanted/readable/deprecated
300                         if (($status == 'required') && (!self::isReadableFile($fileInstance))) {
301                                 // Nope, required file cannot be found/read from
302                                 ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', $application, $fileInstance->getBasename()));
303                         } elseif (($fileInstance->isFile()) && (!$fileInstance->isReadable())) {
304                                 // Found, not readable file
305                                 ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), $application));
306                         } elseif (($status != 'required') && (!self::isReadableFile($fileInstance))) {
307                                 // Not found but optional/deprecated file, skip it
308                                 continue;
309                         }
310
311                         // Is the file deprecated?
312                         if ($status == 'deprecated') {
313                                 // Issue warning
314                                 trigger_error(sprintf('Deprecated file "%s.php" found, will not load it to avoid problems. Please remove it from your application "%s" to avoid this warning.', $fileName, $application), E_USER_WARNING);
315
316                                 // Skip loading deprecated file
317                                 continue;
318                         } // END - if
319
320                         // Load it
321                         self::loadInclude($fileInstance);
322                 } // END - foreach
323
324                 // Scan for application's classes, exceptions and interfaces
325                 ClassLoader::scanApplicationClasses();
326         }
327
328         /**
329          * Starts a fully initialized application, the class ApplicationHelper must
330          * be loaded at this point.
331          *
332          * @return      void
333          */
334         public static function startApplication () {
335                 // Configuration entry 'detected_app_name' must be set, get it here
336                 $application = self::getConfigurationInstance()->getConfigEntry('detected_app_name');
337
338                 // Is there an application helper instance?
339                 $applicationInstance = call_user_func_array(
340                         array(
341                                 'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper', 'getSelfInstance'
342                         ), array()
343                 );
344
345                 // Some sanity checks
346                 if ((empty($applicationInstance)) || (is_null($applicationInstance))) {
347                         // Something went wrong!
348                         ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because the helper class <span class="class_name">%s</span> is not loaded.',
349                                 $application,
350                                 'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper'
351                         ));
352                 } elseif (!is_object($applicationInstance)) {
353                         // No object!
354                         ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because &#39;app&#39; is not an object (%s).',
355                                 $application,
356                                 gettype($applicationInstance)
357                         ));
358                 } elseif (!($applicationInstance instanceof ManageableApplication)) {
359                         // Missing interface
360                         ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because &#39;app&#39; is lacking required interface ManageableApplication.',
361                                 $application
362                         ));
363                 }
364
365                 // Set it in registry
366                 GenericRegistry::getRegistry()->addInstance('application', $applicationInstance);
367
368                 // Now call all methods in one go
369                 foreach (array('setupApplicationData', 'initApplication', 'launchApplication') as $methodName) {
370                         // Debug message
371                         //*NOISY-DEBUG: */ printf('[%s:%d]: Calling methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName);
372
373                         // Call method
374                         call_user_func(array($applicationInstance, $methodName));
375                 } // END - foreach
376         }
377
378         /**
379          * Initializes database instance, no need to double-call this method
380          *
381          * @return      void
382          */
383         public static function initDatabaseInstance () {
384                 // Get application instance
385                 $applicationInstance = ApplicationHelper::getSelfInstance();
386
387                 // Is the database instance already set?
388                 if (self::getDatabaseInstance() instanceof DatabaseConnector) {
389                         // Yes, then abort here
390                         throw new BadMethodCallException('Method called twice.');
391                 } // END - if
392
393                 // Initialize database layer
394                 $databaseInstance = ObjectFactory::createObjectByConfiguredName(self::getConfigurationInstance()->getConfigEntry('database_type') . '_class');
395
396                 // Prepare database instance
397                 $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
398
399                 // Set it in application helper
400                 self::setDatabaseInstance($connectionInstance);
401         }
402
403         /**
404          * Detects the server address (SERVER_ADDR) and set it in configuration
405          *
406          * @return      $serverAddress  The detected server address
407          * @throws      UnknownHostnameException        If SERVER_NAME cannot be resolved to an IP address
408          * @todo        Have to check some more entries from $_SERVER here
409          */
410         public static function detectServerAddress () {
411                 // Is the entry set?
412                 if (!isset(self::$serverAddress)) {
413                         // Is it set in $_SERVER?
414                         if (!empty($_SERVER['SERVER_ADDR'])) {
415                                 // Set it from $_SERVER
416                                 self::$serverAddress = $_SERVER['SERVER_ADDR'];
417                         } elseif (isset($_SERVER['SERVER_NAME'])) {
418                                 // Resolve IP address
419                                 $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']);
420
421                                 // Is it valid?
422                                 if ($serverIp === false) {
423                                         /*
424                                          * Why is gethostbyname() returning the host name and not
425                                          * false as many other PHP functions are doing? ;-(
426                                          */
427                                         throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME']));
428                                 } // END - if
429
430                                 // Al fine, set it
431                                 self::$serverAddress = $serverIp;
432                         } else {
433                                 // Run auto-detecting through console tools lib
434                                 self::$serverAddress = ConsoleTools::acquireSelfIpAddress();
435                         }
436                 } // END - if
437
438                 // Return it
439                 return self::$serverAddress;
440         }
441
442         /**
443          * Setter for default time zone (must be correct!)
444          *
445          * @param       $timezone       The timezone string (e.g. Europe/Berlin)
446          * @return      $success        If timezone was accepted
447          * @throws      NullPointerException    If $timezone is NULL
448          * @throws      InvalidArgumentException        If $timezone is empty
449          */
450         public static function setDefaultTimezone ($timezone) {
451                 // Is it null?
452                 if (is_null($timezone)) {
453                         // Throw NPE
454                         throw new NullPointerException(NULL, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
455                 } elseif (!is_string($timezone)) {
456                         // Is not a string
457                         throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone)));
458                 } elseif ((is_string($timezone)) && (empty($timezone))) {
459                         // Entry is empty
460                         throw new InvalidArgumentException('timezone is empty');
461                 }
462
463                 // Default success
464                 $success = FALSE;
465
466                 /*
467                  * Set desired time zone to prevent date() and related functions to
468                  * issue an E_WARNING.
469                  */
470                 $success = date_default_timezone_set($timezone);
471
472                 // Return status
473                 return $success;
474         }
475
476         /**
477          * Checks whether HTTPS is set in $_SERVER
478          *
479          * @return      $isset  Whether HTTPS is set
480          * @todo        Test more fields
481          */
482         public static function isHttpSecured () {
483                 return (isset($_SERVER['HTTPS']));
484         }
485
486         /**
487          * Dectect and return the base URL for all URLs and forms
488          *
489          * @return      $baseUrl        Detected base URL
490          */
491         public static function detectBaseUrl () {
492                 // Initialize the URL
493                 $protocol = 'http';
494
495                 // Do we have HTTPS?
496                 if (self::isHttpSecured()) {
497                         // Add the >s< for HTTPS
498                         $protocol = 's';
499                 } // END - if
500
501                 // Construct the full URL and secure it against CSRF attacks
502                 $baseUrl = sprintf('%s://%s%s', $protocol, self::detectDomain(), self::detectScriptPath());
503
504                 // Return the URL
505                 return $baseUrl;
506         }
507
508         /**
509          * Detect safely and return the full domain where this script is installed
510          *
511          * @return      $fullDomain             The detected full domain
512          */
513         public static function detectDomain () {
514                 // Full domain is localnet.invalid by default
515                 $fullDomain = 'localnet.invalid';
516
517                 // Is the server name there?
518                 if (isset($_SERVER['SERVER_NAME'])) {
519                         // Detect the full domain
520                         $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
521                 } // END - if
522
523                 // Return it
524                 return $fullDomain;
525         }
526
527         /**
528          * Detect safely the script path without trailing slash which is the glue
529          * between "http://your-domain.invalid/" and "script-name.php"
530          *
531          * @return      $scriptPath             The script path extracted from $_SERVER['SCRIPT_NAME']
532          */
533         public static function detectScriptPath () {
534                 // Default is empty
535                 $scriptPath = '';
536
537                 // Is the scriptname set?
538                 if (isset($_SERVER['SCRIPT_NAME'])) {
539                         // Get dirname from it and replace back-slashes with slashes for lame OSes...
540                         $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME']));
541                 } // END - if
542
543                 // Return it
544                 return $scriptPath;
545         }
546
547         /**
548          * 1) Loads class scanner and scans all framework's classes and interfaces.
549          * This method also registers the class loader's method autoLoad() for the
550          * SPL auto-load feature. Remember that you can register additional methods
551          * (not functions, please) for other libraries.
552          *
553          * Yes, I know about Composer, but I like to keep my class loader around.
554          * You can always use mine as long as your classes have a namespace
555          * according naming-convention: Vendor\Project\Group[\SubGroup]
556          *
557          * @return      void
558          */
559         private static function scanFrameworkClasses () {
560                 // Include the class loader function
561                 require self::getConfigurationInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php';
562
563                 // Register auto-load function with the SPL
564                 spl_autoload_register('Org\Mxchange\CoreFramework\Loader\ClassLoader::autoLoad');
565
566                 // Scan for all framework classes, exceptions and interfaces
567                 ClassLoader::scanFrameworkClasses();
568         }
569
570         /**
571          * 2) Determines request/response type and stores the created
572          * request/response instances in this object for later usage.
573          *
574          * @return      void
575          */
576         private static function determineRequestType () {
577                 // Determine request type
578                 $request = self::getRequestTypeFromSystem();
579                 $requestType = self::getRequestTypeFromSystem();
580
581                 // Create a new request object
582                 $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', BaseFrameworkSystem::convertToClassName($request)));
583
584                 // Remember request instance here
585                 self::setRequestInstance($requestInstance);
586
587                 // Do we have another response?
588                 if ($requestInstance->isRequestElementSet('request')) {
589                         // Then use it
590                         $request = strtolower($requestInstance->getRequestElement('request'));
591                         $requestType = $request;
592                 } // END - if
593
594                 // ... and a new response object
595                 $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', BaseFrameworkSystem::convertToClassName($request));
596                 $responseInstance = ObjectFactory::createObjectByName($responseClass);
597
598                 // Remember response instance here
599                 self::setResponseInstance($responseInstance);
600         }
601
602         /**
603          * 3) Validate parameter 'application' if it is set and the application is there.
604          *
605          * @return      void
606          */
607         private static function validateApplicationParameter () {
608                 // Is the parameter set?
609                 if (!self::getRequestInstance()->isRequestElementSet('app')) {
610                         /*
611                          * Don't continue here, the application 'selector' is no longer
612                          * supported and only existed as an idea to select the proper
613                          * application (by user).
614                          */
615                         ApplicationEntryPoint::exitApplication('No application specified. Please provide a parameter "app" and retry.');
616                 } // END - if
617
618                 // Get it for local usage
619                 $application = self::getRequestInstance()->getRequestElement('app');
620
621                 // Secure it, by keeping out tags
622                 $application = htmlentities(strip_tags($application), ENT_QUOTES);
623
624                 // Secure it a little more with a reg.exp.
625                 $application = preg_replace('/([^a-z0-9_-])+/i', '', $application);
626
627                 // Construct FQPN (Full-Qualified Path Name) for ApplicationHelper class
628                 $applicationPath = sprintf(
629                         '%s%s%s',
630                         self::getConfigurationInstance()->getConfigEntry('application_base_path'),
631                         $application,
632                         DIRECTORY_SEPARATOR
633                 );
634
635                 // Full path for application
636                 // Is the path there? This secures a bit the parameter (from untrusted source).
637                 if ((!is_dir($applicationPath)) || (!is_readable($applicationPath))) {
638                         // Not found or not readable
639                         ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $application));
640                 } // END - if
641
642                 // Set the detected application's name and full path for later usage
643                 self::getConfigurationInstance()->setConfigEntry('detected_full_app_path', $applicationPath);
644                 self::getConfigurationInstance()->setConfigEntry('detected_app_name'     , $application);
645         }
646
647         /**
648          * Getter for request instance
649          *
650          * @return      $requestInstance        An instance of a Requestable class
651          */
652         public static function getRequestInstance () {
653                 return self::$requestInstance;
654         }
655
656         /**
657          * Getter for response instance
658          *
659          * @return      $responseInstance       An instance of a Responseable class
660          */
661         public static function getResponseInstance () {
662                 return self::$responseInstance;
663         }
664
665         /**
666          * Setter for request instance
667          *
668          * @param       $requestInstance        An instance of a Requestable class
669          * @return      void
670          */
671         private static function setRequestInstance (Requestable $requestInstance) {
672                 self::$requestInstance = $requestInstance;
673         }
674
675         /**
676          * Setter for response instance
677          *
678          * @param       $responseInstance       An instance of a Responseable class
679          * @return      void
680          */
681         private static function setResponseInstance (Responseable $responseInstance) {
682                 self::$responseInstance = $responseInstance;
683         }
684
685         /**
686          * Setter for database instance
687          *
688          * @param       $databaseInstance       An instance of a DatabaseConnection class
689          * @return      void
690          */
691         public static function setDatabaseInstance (DatabaseConnection $databaseInstance) {
692                 self::$databaseInstance = $databaseInstance;
693         }
694
695         /**
696          * Getter for database instance
697          *
698          * @return      $databaseInstance       An instance of a DatabaseConnection class
699          */
700         public static function getDatabaseInstance () {
701                 // Return instance
702                 return self::$databaseInstance;
703         }
704
705 }