Skip to content

Commit

Permalink
Add "theme" and authorized plugin to filesystem at boot instead of de…
Browse files Browse the repository at this point in the history
…pending on them.

This allows us to call "filesystem" whenever we want without fear of infinite loop.
Merged other filesystem DI keys back into main filesystem key.

The theme path is also added to Twig loader at boot now as well to match and reset
its internal error cache if some dummy tries to render a theme template before boot.
  • Loading branch information
CarsonF committed Mar 1, 2017
1 parent ff4209f commit 1b19486
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 52 deletions.
10 changes: 5 additions & 5 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function initialize()
$this->fields = new Storage\Field\Manager();
$this->defaultConfig = $this->getDefaults();

$this->cacheFile = $this->app['filesystem.cache']->getFile('config-cache.json');
$this->cacheFile = $this->app['filesystem']->getFile('cache://config-cache.json');

$data = $this->loadCache();
if ($data === null) {
Expand Down Expand Up @@ -122,7 +122,7 @@ private function loadTheme()
}
$this->invalidateCache();

$themeDir = $this->app['filesystem.themes']->getDir($this->get('general/theme'));
$themeDir = $this->app['filesystem']->getDir('themes://' . $this->get('general/theme'));

$this->data['theme'] = $this->parseTheme($themeDir, $this->data['general']);
}
Expand All @@ -137,7 +137,7 @@ private function loadTheme()
*/
protected function parseConfigYaml($filename, DirectoryInterface $directory = null)
{
$directory = $directory ?: $this->app['filesystem.config']->getDir('');
$directory = $directory ?: $this->app['filesystem']->getDir('config://');

try {
$file = $directory->get($filename);
Expand Down Expand Up @@ -1300,7 +1300,7 @@ private function isCacheValid()
$cachedConfigTimestamp = $this->cacheFile->getTimestamp();

/** @var \Bolt\Filesystem\Filesystem $configFs */
$configFs = $this->app['filesystem.config'];
$configFs = $this->app['filesystem']->getFilesystem('config');

$configFiles = [
'config.yml',
Expand Down Expand Up @@ -1336,7 +1336,7 @@ private function isThemeCacheValid()
return false;
}

$themeDir = $this->app['filesystem.themes']->getDir($this->get('general/theme'));
$themeDir = $this->app['filesystem']->getDir('themes://' . $this->get('general/theme'));

// Check the timestamp for the theme's configuration file
$timestampTheme = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DatabaseSchemaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function () use ($app) {

$app['schema.timer'] = $app->share(
function ($app) {
return new Timer($app['filesystem.cache']->getFile(Timer::CHECK_TIMESTAMP_FILE));
return new Timer($app['filesystem']->getFile('cache://dbcheck.ts'));
}
);

Expand Down
65 changes: 25 additions & 40 deletions src/Provider/FilesystemServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,6 @@ class FilesystemServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
// These can be called early
$app['filesystem.config'] = $app->share(function ($app) {
$fs = new Filesystem(new Local($app['path_resolver']->resolve('config')));
$fs->setMountPoint('config');

return $fs;
});

$app['filesystem.cache'] = $app->share(function ($app) {
$fs = new Filesystem(new Local($app['path_resolver']->resolve('cache')));
$fs->setMountPoint('cache');

return $fs;
});

$app['filesystem.themes'] = $app->share(function ($app) {
$fs = new Filesystem(new Local($app['path_resolver']->resolve('themes')));
$fs->setMountPoint('themes');

return $fs;
});

// Calling this before boot … all bets are off … and if Bolt breaks, you get to keep both pieces!
// @TODO :fire: this when the new configuration loading lands
$app['filesystem.theme'] = $app->share(function ($app) {
$fs = new Filesystem(new Local($app['path_resolver']->resolve('%themes%/' . $app['config']->get('general/theme'))));
$fs->setMountPoint('theme');

return $fs;
});

// Don't call this until boot.
$app['filesystem'] = $app->share(
function ($app) {
$manager = new Manager(
Expand All @@ -69,17 +37,15 @@ function ($app) {
// User's synced bolt assets directory
'bolt_assets' => new Filesystem(new Local($app['path_resolver']->resolve('bolt_assets'))),
// User's config directory
'config' => $app['filesystem.config'],
'config' => new Filesystem(new Local($app['path_resolver']->resolve('config'))),
// User's themes directory
'themes' => $app['filesystem.themes'],
// User's currently selected theme directory
'theme' => $app['filesystem.theme'],
'themes' => new Filesystem(new Local($app['path_resolver']->resolve('themes'))),
// User's extension directory
'extensions' => new Filesystem(new Local($app['path_resolver']->resolve('extensions'))),
// User's extension config directory
'extensions_config' => new Filesystem(new Local($app['path_resolver']->resolve('extensions_config'))),
// User's cache directory
'cache' => $app['filesystem.cache'],
'cache' => new Filesystem(new Local($app['path_resolver']->resolve('cache'))),

'app' => new LazyFilesystem(function () use ($app) {
Deprecated::warn('The "app" filesystem', 3.3, 'Use a filesystem at a more specific mount point instead.');
Expand All @@ -101,7 +67,6 @@ function ($app) {
new Plugin\HasUrl(),
new Plugin\Parents(),
new Plugin\ToJs(),
new Plugin\Authorized($app['filepermissions']),
new Plugin\ThumbnailUrl($app['url_generator.lazy']),
]
);
Expand All @@ -110,6 +75,18 @@ function ($app) {
}
);

// Separated to prevent circular dependency.
// config depends on filesystem, so filesystem cannot depend on config
$app['filesystem.theme'] = $app->share(function ($app) {
$fs = new Filesystem(new Local($app['path_resolver']->resolve('%themes%/' . $app['config']->get('general/theme'))));

return $fs;
});

$app['filesystem.plugin.authorized'] = function () use ($app) {
return new Plugin\Authorized($app['filepermissions']);
};

$app['filesystem.plugin.url'] = function () use ($app) {
return new Plugin\AssetUrl($app['asset.packages']);
};
Expand All @@ -123,9 +100,17 @@ function ($app) {

public function boot(Application $app)
{
$filesystem = $app['filesystem'];

// User's currently selected theme directory.
// Add theme filesystem here to prevent circular dependency.
$filesystem->mountFilesystem('theme', $app['filesystem.theme']);

// Add authorized plugin here to prevent circular dependency.
$filesystem->addPlugin($app['filesystem.plugin.authorized']);
// Add url plugin here to prevent circular dependency.
$app['filesystem']->addPlugin($app['filesystem.plugin.url']);
$filesystem->addPlugin($app['filesystem.plugin.url']);
// "bolt" filesystem cannot use the "bolt" asset package.
$app['filesystem']->getFilesystem('bolt')->addPlugin(new Plugin\NoAssetUrl());
$filesystem->getFilesystem('bolt')->addPlugin(new Plugin\NoAssetUrl());
}
}
9 changes: 4 additions & 5 deletions src/Provider/TwigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,9 @@ function () {
function ($app) {
$loader = new FilesystemLoader($app['filesystem']);

$themePath = 'theme://' . $app['config']->get('theme/template_directory');

$loader->addPath($themePath, 'theme');
$loader->addPath('bolt://app/theme_defaults', 'theme');
$loader->addPath('bolt://app/view/twig', 'bolt');

/** @deprecated Deprecated since 3.0, to be removed in 4.0. */
$loader->addPath($themePath);
$loader->addPath('bolt://app/theme_defaults');
$loader->addPath('bolt://app/view/twig');

Expand Down Expand Up @@ -302,6 +297,10 @@ function ($app) {
*/
public function boot(Application $app)
{
// Add path here since "theme" filesystem isn't mounted until boot.
$themePath = 'theme://' . $app['config']->get('theme/template_directory');
$app['twig.loader.bolt_filesystem']->addPath($themePath, 'theme');
$app['twig.loader.bolt_filesystem']->addPath($themePath);
}

protected function registerSandbox(Application $app)
Expand Down
1 change: 0 additions & 1 deletion src/Storage/Database/Schema/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Timer
/** @var boolean */
protected $expired;

const CHECK_TIMESTAMP_FILE = 'dbcheck.ts';
const CHECK_INTERVAL = 1800;

/**
Expand Down

0 comments on commit 1b19486

Please sign in to comment.