-
-
Notifications
You must be signed in to change notification settings - Fork 807
Updating `class_reference.yml`.
Gawain Lynch edited this page Feb 23, 2017
·
6 revisions
To update the class_reference.yml file, do the following:
- Make a checkout of the version you'd like to update the
class_reference.ymlfile for - Make sure it doesn't have any extensions installed.
- Update
pimple.json:- Bolt 3.2 or earlier see the IDE Tools section in the docs
- Bolt 3.3 or later run
php ./app/nut pimple:dump
- Run
dump_classreference.php - Overwrite the
class_reference.ymlfile in the appropriate folder, likevar/versions/3.2/class_reference.yml.
Contents of dump_classreference.php:
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
/**
* Pimple container service class reference generator.
*
* @author Bob den Otter <[email protected]>
* @author Gawain Lynch <[email protected]>
*/
class ClassReferenceGenerator
{
/** @var Filesystem */
private $fs;
/** @var string */
private $boltDir;
/** @var string */
private $composerDir;
/** @var string */
private $pimpleJson;
/** @var ConsoleOutput */
private $output;
/** @var array */
private $volatileValues = [
'asset.salt',
'asset.salt.factory',
'bolt_long_version',
'bolt_name',
'bolt_released',
'bolt_released',
'bolt_version',
'debug',
'debug.class_loader.enabled',
'debug.error_handler.display_errors',
'debug.error_handler.enabled',
'debug.error_handler.reporting_level',
'debug.exception_handler.enabled',
'form.secret',
'guzzle.api_version',
'monolog.logfile',
'token.authentication.name',
'upload.prefix',
'uri_signer.secret',
];
/**
* Constructor.
*/
public function __construct()
{
$this->boltDir = getcwd();
$this->pimpleJson = $this->boltDir . '/pimple.json';
$this->loadBoltAutoloader();
$this->fs = new Filesystem();
$this->initialise();
$this->output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG, true);
}
private function loadBoltAutoloader()
{
if (!file_exists($this->boltDir . '/vendor/autoload.php')) {
die(sprintf(
'%sComposer autoloader not found at %s/vendor/autoload.php. Unable to continue!%s%s',
PHP_EOL,
$this->boltDir,
PHP_EOL,
PHP_EOL
));
}
require_once $this->boltDir . '/vendor/autoload.php';
}
private function initialise()
{
if (Bolt\Version::compare('3.3.0', '<')) {
$homeDir = getenv('HOME');
if (file_exists($homeDir . '/.composer/vendor/autoload.php')) {
$this->composerDir = $homeDir . '/.composer';
require_once $homeDir . '/.composer/vendor/autoload.php';
} elseif (file_exists($homeDir . '/.config/composer/vendor/autoload.php')) {
$this->composerDir = $homeDir . '/.config/composer';
require_once $homeDir . '/.config/composer/vendor/autoload.php';
} else {
$this->output->writeln(sprintf('<error>ABORTING: Unable to find global Composer autoload.php and Bolt prior to 3.2 requires you to first run: %s.</error>'));
$this->output->writeln(sprintf('<info> composer global require sorien/silex-pimple-dumper:^1.0</info>'));
die();
}
}
}
/**
* @param string $item
*
* @return string
*/
private function getClassFilename($item)
{
$basePath = $this->boltDir . '/';
if ($item['type'] === 'class') {
$temp = new ReflectionClass($item['value']);
$file = str_replace($basePath, '', $temp->getFilename());
} else {
$file = '';
}
// Strip paths if they autoload from global
if ($this->composerDir !== null && strpos($file, $this->composerDir) !== false) {
$file = ltrim(str_replace($this->composerDir, '', $file), '/');
}
return $file;
}
public function dumpClassMap()
{
$json = json_decode(implode('', file('./pimple.json')), true);
foreach ($json as $key => $item) {
if (is_array($item['value']) && !empty($item['value'])) {
foreach ($item['value'] as $subkey => $subitem) {
$subitem['name'] = $item['name'] . ' -> ' . $subitem['name'];
$subitem['file'] = $this->getClassFilename($subitem);
if ($subitem['value'] != 'Bolt\Storage\Database\Schema\Table\ContentType') {
$result[] = $subitem;
}
}
$item['value'] = '<em>(array, see children below)</em>';
}
$item['file'] = $this->getClassFilename($item);
if (is_array($item['value'])) {
$item['value'] = '(array)';
}
// Don't store values that change on each system/run
if (in_array($item['name'], $this->volatileValues)) {
$item['value'] = '<em>(unique per-system value)</em>';
}
// Remove base paths from values.
// Note, some might be only the base path, others include a sub-path, hence the ltrim()
if (strpos($item['value'], $this->boltDir) !== false) {
$item['value'] = ltrim(str_replace($this->boltDir, '', $item['value']), '/');
}
$result[] = $item;
}
usort($result, function ($a, $b) { return strcmp(strtolower($a['name']), strtolower($b['name'])); });
$this->fs->dumpFile('class_reference.yml', Yaml::dump($result));
$this->output->writeln('<info>Current class information written out to class_reference.yml</info>');
}
}
$generator = new ClassReferenceGenerator();
$generator->dumpClassMap();- Bolt Wiki Home
- Tuesday Dev meetings
- Curated list of articles and tutorials
- Bolt internationalisation (i18n)
- Bolt Style Guide
- Roadmap
- TODOs
- [Tests] Unit & Functional Split
- [Tests] Code Coverage
- Core Team
- Bug/feature Process
-
Release Process
- Branching
- Packaging release builds