Skip to content

Instantly share code, notes, and snippets.

@rossriley
Last active August 29, 2015 14:23
Show Gist options
  • Save rossriley/a1647629c70a0336df4f to your computer and use it in GitHub Desktop.
Save rossriley/a1647629c70a0336df4f to your computer and use it in GitHub Desktop.
Custom Configuration
<?php
namespace Boorj\Bolt;
use Bolt\Configuration\Standard;
use Symfony\Component\HttpFoundation\Request;
class Configuration extends Standard
{
/**
* Constructor initialises on the app root path.
*
* @param string $path
* @param Request $request
*/
public function __construct($path, Request $request = null)
{
parent::__construct($path, $request);
$this->setPath('vendor', 'app/vendor');
$this->setPath('cache', 'app/vars/cache');
$this->setPath('logs', 'app/vars/logs');
$this->setPath('database', 'app/database');
$this->setPath('extensionspath', 'app/extensions');
$this->setPath("themebase", 'src');
$this->setPath('config', 'src/config');
$this->setPath('extensionsconfig', 'src/config/extensions');
$this->setPath("web", 'web');
$this->setPath('files', 'web/up');
}
}
// New index.php
use Boorj\Bolt\Configuration;
$configuration = new Configuration(dirname(__DIR__);
$configuration->getVerifier()->disableApacheChecks();
$configuration->verify();
$app = new Bolt\Application(array('resources'=>$configuration));
$app->initialize();
.......
@Boorj
Copy link

Boorj commented Jul 7, 2015

Sorry for stupid question, but where should i put this file? To /extensions/local/boorj or somewhere else? Usually i have to put there and create init.php file so bolt sees this extension and uses it.

@rossriley
Copy link
Author

It can go anywhere in your autoloaded paths. So for example if I'm starting a new Bolt project I'll also define a root composer.json for that site and put a line like this in it.

    "autoload": {
        "psr-4": {
            "MySite\\": "src",
            "MySite\\Tests\\": "tests"
        }
    }

Then you can autoload any classes eg: MySite\Bolt\Configuration will be loaded from src/Bolt/Configuration.php

That way you can swap out any individual services within Bolt for your own, if you want to change any of the core functionality. The line below now uses your custom Confguration class rather than the Bolt default.

use MySite\Bolt\Configuration;
$configuration = new Configuration(dirname(__DIR__);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment