Here is a recommended file structure and configation for your web app.
/app // This is the place for the app code
/bearframework // Bear Framework files (if you've downloaded the standalone version)
/autoload.php
/...
/data // The data is stored here
/logs // The place where log files are stored
/public // This must be the only public dir, so point your domain here
/index.php
/.htaccess // Apache config file that makes pretty URLs (mod_rewrite required)
Here is the content of /public/index.php:
require __DIR__ . '/../vendor/autoload.php';
// Creates a new Bear Framework application.
$app = new BearFramework\App();
// Enables and configures the error handler.
$app->enableErrorHandler(['logErrors' => false, 'displayErrors' => true]);
// Enables the data access. The data will be stored at the directory specified.
$app->data->useFileDriver(__DIR__ . '/../data');
// Enables the cache access. The cached items will be stored as a data items.
$app->cache->useAppDataDriver();
// Enables the logger. The logs will be stored at the directory specified.
$app->logs->useFileLogger(__DIR__ . '/../logs');
// Creates a new context. The index.php file at the directory specified will be run.
$app->contexts->add(__DIR__ . '/../app');
// Prepare and return the response that matches the current request.
$app->run();
And this is the content of /app/index.php. It is autoloaded by the $app->contexts->add() line. It's recommended to use directory that is not publicly accessible to store your code and assets.
use BearFramework\App;
$app = App::get();
// The specified callback will be executed when request path is '/' and response method is GET
// The text 'Hi' will be shown on the screen
$app->routes->add('/', function() {
return new App\Response('Hi');
});
Download the following code and begin building your app right away.