From c9a9b401e9269994b0a9b193836e0b993a6782c1 Mon Sep 17 00:00:00 2001 From: alexweissman Date: Tue, 12 Dec 2017 21:25:03 -0500 Subject: [PATCH] Factor out hardcoded `sprinkles.json` filename (partially addresses #813) --- CHANGELOG.md | 1 + app/defines.php | 12 ++++++++---- app/system/Bakery/Bakery.php | 11 +++++------ app/system/Bakery/BaseCommand.php | 4 ++-- app/system/Bakery/Command/Debug.php | 8 ++++---- app/system/Sprinkle/SprinkleManager.php | 4 ++-- app/system/UserFrosting.php | 5 +---- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1049bb67a..2cc08fa5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Update Bower dependencies in core Sprinkle - Refactor the `Password` class to use `hash_equals` for legacy passwords (prevent timing-based attacks) and factor out the default cost (#814) - Check if require_email_verification is set in Authenticator and sign-in page (#815) +- Factor out hardcoded `sprinkles.json` filename (partially addresses #813) ## v4.1.13-alpha - `ufTable`: Implement `rowTemplate` for customizing how rows are rendered (#787) diff --git a/app/defines.php b/app/defines.php index 1db821937..da6078315 100755 --- a/app/defines.php +++ b/app/defines.php @@ -3,7 +3,7 @@ namespace UserFrosting; // Some standard defines -define('UserFrosting\VERSION', '4.1.13-alpha'); +define('UserFrosting\VERSION', '4.1.14-alpha'); define('UserFrosting\DS', '/'); define('UserFrosting\PHP_MIN_VERSION', '5.6'); define('UserFrosting\DEBUG_CONFIG', false); @@ -24,15 +24,19 @@ define('UserFrosting\DB_DIR_NAME', 'database'); define('UserFrosting\SESSION_DIR_NAME', 'sessions'); define('UserFrosting\SPRINKLES_DIR_NAME', 'sprinkles'); + +// Full path to Sprinkles directory +define('UserFrosting\SPRINKLES_DIR', APP_DIR . DS . SPRINKLES_DIR_NAME); + +// Sprinkles schema file +define('UserFrosting\SPRINKLES_SCHEMA_FILE', APP_DIR . DS . 'sprinkles.json'); + define('UserFrosting\LOG_DIR_NAME', 'logs'); define('UserFrosting\VENDOR_DIR_NAME', 'vendor'); // Full path to Composer's vendor directory define('UserFrosting\VENDOR_DIR', APP_DIR . DS . VENDOR_DIR_NAME); -// Full path to Sprinkles directory -define('UserFrosting\SPRINKLES_DIR', APP_DIR . DS . SPRINKLES_DIR_NAME); - // Full path to database directory (SQLite only) define('UserFrosting\DB_DIR', APP_DIR . DS . DB_DIR_NAME); diff --git a/app/system/Bakery/Bakery.php b/app/system/Bakery/Bakery.php index b5adc31d7..8be84809c 100644 --- a/app/system/Bakery/Bakery.php +++ b/app/system/Bakery/Bakery.php @@ -33,9 +33,8 @@ class Bakery */ public function __construct() { - // Check for `sprinkles.json` - $path = \UserFrosting\APP_DIR . '/sprinkles.json'; - $sprinklesFile = @file_get_contents($path); + // Check for Sprinkles schema file + $sprinklesFile = @file_get_contents(\UserFrosting\SPRINKLES_SCHEMA_FILE); if ($sprinklesFile === false) { $sprinklesFile = $this->setupBaseSprinkleList(); } @@ -145,7 +144,7 @@ protected function commandDirectoryPath($sprinkleName) } /** - * Write the base `sprinkles.json` file if none exist. + * Write the base Sprinkles schema file if it doesn't exist. * * @access protected * @return void @@ -153,7 +152,7 @@ protected function commandDirectoryPath($sprinkleName) protected function setupBaseSprinkleList() { $model = \UserFrosting\APP_DIR . '/sprinkles.example.json'; - $destination = \UserFrosting\APP_DIR . '/sprinkles.json'; + $destination = \UserFrosting\SPRINKLES_SCHEMA_FILE; $sprinklesModelFile = @file_get_contents($model); if ($sprinklesModelFile === false) { $this->io->error("File `$sprinklesModelFile` not found. Please create '$destination' manually and try again."); @@ -164,4 +163,4 @@ protected function setupBaseSprinkleList() return $sprinklesModelFile; } -} \ No newline at end of file +} diff --git a/app/system/Bakery/BaseCommand.php b/app/system/Bakery/BaseCommand.php index 59eb2cd8b..1a59141b4 100644 --- a/app/system/Bakery/BaseCommand.php +++ b/app/system/Bakery/BaseCommand.php @@ -35,7 +35,7 @@ abstract class BaseCommand extends Command protected $projectRoot; /** - * @var ContainerInterface $ci The global container object, which holds all of UserFristing services. + * @var ContainerInterface $ci The global container object, which holds all of the UserFrosting services. */ protected $ci; @@ -55,4 +55,4 @@ public function setContainer(ContainerInterface $ci) { $this->ci = $ci; } -} \ No newline at end of file +} diff --git a/app/system/Bakery/Command/Debug.php b/app/system/Bakery/Command/Debug.php index 2b877afbe..4e8a3e45b 100644 --- a/app/system/Bakery/Command/Debug.php +++ b/app/system/Bakery/Command/Debug.php @@ -111,7 +111,7 @@ protected function checkNpmVersion() } /** - * List all sprinkles defined in the `sprinkles.json` file, + * List all sprinkles defined in the Sprinkles schema file, * making sure this file exist at the same time * * @access protected @@ -119,8 +119,8 @@ protected function checkNpmVersion() */ protected function listSprinkles() { - // Check for `sprinkles.json` - $path = \UserFrosting\APP_DIR . '/sprinkles.json'; + // Check for Sprinkles schema file + $path = \UserFrosting\SPRINKLES_SCHEMA_FILE; $sprinklesFile = @file_get_contents($path); if ($sprinklesFile === false) { $this->io->error("The file `$path` not found."); @@ -182,4 +182,4 @@ protected function showConfig() "PASSWORD : " . ($config['db.default.password'] ? "*********" : "") ]); } -} \ No newline at end of file +} diff --git a/app/system/Sprinkle/SprinkleManager.php b/app/system/Sprinkle/SprinkleManager.php index 71ccd6eba..c206cea94 100644 --- a/app/system/Sprinkle/SprinkleManager.php +++ b/app/system/Sprinkle/SprinkleManager.php @@ -168,7 +168,7 @@ public function init($sprinkleNames) } /** - * Initialize all base sprinkles in a specified sprinkles.json schema file. + * Initialize all base sprinkles in a specified Sprinkles schema file (e.g. 'sprinkles.json'). * * @param string $schemaPath */ @@ -217,7 +217,7 @@ public function registerServices($name) } /** - * Load list of Sprinkles from a JSON schema file (e.g. sprinkles.json). + * Load list of Sprinkles from a JSON schema file (e.g. 'sprinkles.json'). * * @param string $schemaPath * @return string[] diff --git a/app/system/UserFrosting.php b/app/system/UserFrosting.php index 53afc554d..4f569ec4b 100644 --- a/app/system/UserFrosting.php +++ b/app/system/UserFrosting.php @@ -131,14 +131,11 @@ public function setupSprinkles($isWeb = true) $serviceProvider = new ServicesProvider(); $serviceProvider->register($this->ci); - // Expected path to `sprinkles.json` - $schemaPath = \UserFrosting\APP_DIR . '/sprinkles.json'; - // Boot the Sprinkle manager, which creates Sprinkle classes and subscribes them to the event dispatcher $sprinkleManager = $this->ci->sprinkleManager; try { - $sprinkleManager->initFromSchema($schemaPath); + $sprinkleManager->initFromSchema(\UserFrosting\SPRINKLES_SCHEMA_FILE); } catch (FileNotFoundException $e) { if ($isWeb) { $this->renderSprinkleErrorPage($e->getMessage());