123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace Goodquestiondev;
- use Illuminate\Support\Str;
- /**
- * Simple application
- */
- class Application
- {
- /**
- * The Application version.
- *
- * @var string
- */
- const VERSION = '0.1';
- /**
- * The Application instance.
- *
- * @var self
- */
- private static $instance = null;
- /**
- * The base path for the installation.
- *
- * @var string
- */
- protected $basePath;
- /**
- * The available controllers
- *
- * @var array
- */
- public $controllerUris = [];
- /**
- * Create a new application instance.
- *
- * @param string|null $basePath
- * @return void
- */
- public function __construct($basePath = null)
- {
- if ($basePath) {
- $this->basePath = rtrim($basePath, '\/');
- }
- $this->setControllerUris();
- }
- /**
- * Create a new application instance following singleton pattern
- *
- * @return self
- */
- public static function getInstance()
- {
- if (self::$instance == null) {
- self::$instance = new Application(__DIR__);
- }
- return self::$instance;
- ;
- }
- /**
- * Get the path to the public directory.
- *
- * @return string
- */
- public function publicPath()
- {
- return $this->basePath.DIRECTORY_SEPARATOR.'public';
- }
- /**
- * Get all available controller URIs
- *
- * @return array An array of all the available controller URIs
- */
- public function setControllerUris() : void
- {
- $files = array_diff(scandir($this->basePath . '/Controllers'), ['..', '.']);
- $uris = [];
- foreach ($files as $file) {
- $withoutExtension = Str::before($file, 'Controller.php');
- if (!$withoutExtension) {
- continue;
- }
- $uris[Str::snake($withoutExtension, '.')] = Str::before($file, '.php');
- }
- $this->controllerUris = $uris;
- }
- /**
- * Get all available controller URIs
- *
- * @return array An array of all the available controller URIs
- */
- public function getControllerUris() : array
- {
- return $this->controllerUris;
- }
- /**
- * Handles the response
- *
- */
- public function respond()
- {
- return "<html>
- <head>
- <title>
- A Simple HTML Document
- </title>
- </head>
- <body>
- <p>This is a very simple HTML document</p>
- <p>It only has two paragraphs</p>
- </body>
- </html>";
- }
- }
|