Setup
Unifying common setup necessities
The Setup class
Starting from version v0.2, the app requires an instance of the setup-helper. This simplifies the setup process greatly.
Main methods
set(string $key, mixed $value)
Registers a value available throughout the app
get(string $key)
Retrieves a value
getConfiguration()
Retrieves an array of all setup values
setPublicPath(string $path)
Registers web-path
setLibraryPath(string $path)
Registers source-path
setDatabaseAdapter(Adapter $adapter)
Accepts instantiated Database adapter
setSkeletonVariables(array $skeletonVariables)
setSkeletonComponentPlacement(string $skeletonComponentPlacement)
setSkeletonHTML(string $skeletonHTML)
setUseSkeleton(bool $useSkeleton)
Set true for use of layout/frame mode
setDefault404(string $default404)
Set own 404 page html
setDefault500(string $default500)
Set own system error page html
setTemplatePath(string $templatePath)
Set relative base path for templating
Example with custom value
index.php
?php
// /public/index.php
use Neoan\NeoanApp;
use Neoan\Routing\Route;
use Neoan\Helper\Setup;
$projectPath = dirname(__DIR__);
require_once $projectPath . '/vendor/autoload.php';
$pathToSourceFiles = $projectPath . '/src';
$publicPath = __DIR__;
$setup = new Setup();
$setup->setLibraryPath($pathToSourceFiles)
->setPublicPath($publicPath)
// some arbitrary setup value
->set('globalArray', ['a']);
$app = new NeoanApp($setup);
...
// run application
$app->run();
Some controller
?php
namespace App;
use Neoan\Routing\Interfaces\Routable;
use Neoan\Helper\Setup;
class Controller implements Routable
{
// auto-wire our setup instance
public function __invoke(Setup $setup): array
{
// let's return our globalArray
return $setup->get('globalArray');
}
}
Before you move on
Many references on this page assume default settings. Your project might differ in behavior, paths etc.