Skip to content

Commit c9a9b40

Browse files
committed
Factor out hardcoded sprinkles.json filename (partially addresses #813)
1 parent d596e06 commit c9a9b40

7 files changed

Lines changed: 23 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Update Bower dependencies in core Sprinkle
66
- Refactor the `Password` class to use `hash_equals` for legacy passwords (prevent timing-based attacks) and factor out the default cost (#814)
77
- Check if require_email_verification is set in Authenticator and sign-in page (#815)
8+
- Factor out hardcoded `sprinkles.json` filename (partially addresses #813)
89

910
## v4.1.13-alpha
1011
- `ufTable`: Implement `rowTemplate` for customizing how rows are rendered (#787)

app/defines.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace UserFrosting;
44

55
// Some standard defines
6-
define('UserFrosting\VERSION', '4.1.13-alpha');
6+
define('UserFrosting\VERSION', '4.1.14-alpha');
77
define('UserFrosting\DS', '/');
88
define('UserFrosting\PHP_MIN_VERSION', '5.6');
99
define('UserFrosting\DEBUG_CONFIG', false);
@@ -24,15 +24,19 @@
2424
define('UserFrosting\DB_DIR_NAME', 'database');
2525
define('UserFrosting\SESSION_DIR_NAME', 'sessions');
2626
define('UserFrosting\SPRINKLES_DIR_NAME', 'sprinkles');
27+
28+
// Full path to Sprinkles directory
29+
define('UserFrosting\SPRINKLES_DIR', APP_DIR . DS . SPRINKLES_DIR_NAME);
30+
31+
// Sprinkles schema file
32+
define('UserFrosting\SPRINKLES_SCHEMA_FILE', APP_DIR . DS . 'sprinkles.json');
33+
2734
define('UserFrosting\LOG_DIR_NAME', 'logs');
2835
define('UserFrosting\VENDOR_DIR_NAME', 'vendor');
2936

3037
// Full path to Composer's vendor directory
3138
define('UserFrosting\VENDOR_DIR', APP_DIR . DS . VENDOR_DIR_NAME);
3239

33-
// Full path to Sprinkles directory
34-
define('UserFrosting\SPRINKLES_DIR', APP_DIR . DS . SPRINKLES_DIR_NAME);
35-
3640
// Full path to database directory (SQLite only)
3741
define('UserFrosting\DB_DIR', APP_DIR . DS . DB_DIR_NAME);
3842

app/system/Bakery/Bakery.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class Bakery
3333
*/
3434
public function __construct()
3535
{
36-
// Check for `sprinkles.json`
37-
$path = \UserFrosting\APP_DIR . '/sprinkles.json';
38-
$sprinklesFile = @file_get_contents($path);
36+
// Check for Sprinkles schema file
37+
$sprinklesFile = @file_get_contents(\UserFrosting\SPRINKLES_SCHEMA_FILE);
3938
if ($sprinklesFile === false) {
4039
$sprinklesFile = $this->setupBaseSprinkleList();
4140
}
@@ -145,15 +144,15 @@ protected function commandDirectoryPath($sprinkleName)
145144
}
146145

147146
/**
148-
* Write the base `sprinkles.json` file if none exist.
147+
* Write the base Sprinkles schema file if it doesn't exist.
149148
*
150149
* @access protected
151150
* @return void
152151
*/
153152
protected function setupBaseSprinkleList()
154153
{
155154
$model = \UserFrosting\APP_DIR . '/sprinkles.example.json';
156-
$destination = \UserFrosting\APP_DIR . '/sprinkles.json';
155+
$destination = \UserFrosting\SPRINKLES_SCHEMA_FILE;
157156
$sprinklesModelFile = @file_get_contents($model);
158157
if ($sprinklesModelFile === false) {
159158
$this->io->error("File `$sprinklesModelFile` not found. Please create '$destination' manually and try again.");
@@ -164,4 +163,4 @@ protected function setupBaseSprinkleList()
164163

165164
return $sprinklesModelFile;
166165
}
167-
}
166+
}

app/system/Bakery/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class BaseCommand extends Command
3535
protected $projectRoot;
3636

3737
/**
38-
* @var ContainerInterface $ci The global container object, which holds all of UserFristing services.
38+
* @var ContainerInterface $ci The global container object, which holds all of the UserFrosting services.
3939
*/
4040
protected $ci;
4141

@@ -55,4 +55,4 @@ public function setContainer(ContainerInterface $ci)
5555
{
5656
$this->ci = $ci;
5757
}
58-
}
58+
}

app/system/Bakery/Command/Debug.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ protected function checkNpmVersion()
111111
}
112112

113113
/**
114-
* List all sprinkles defined in the `sprinkles.json` file,
114+
* List all sprinkles defined in the Sprinkles schema file,
115115
* making sure this file exist at the same time
116116
*
117117
* @access protected
118118
* @return void
119119
*/
120120
protected function listSprinkles()
121121
{
122-
// Check for `sprinkles.json`
123-
$path = \UserFrosting\APP_DIR . '/sprinkles.json';
122+
// Check for Sprinkles schema file
123+
$path = \UserFrosting\SPRINKLES_SCHEMA_FILE;
124124
$sprinklesFile = @file_get_contents($path);
125125
if ($sprinklesFile === false) {
126126
$this->io->error("The file `$path` not found.");
@@ -182,4 +182,4 @@ protected function showConfig()
182182
"PASSWORD : " . ($config['db.default.password'] ? "*********" : "")
183183
]);
184184
}
185-
}
185+
}

app/system/Sprinkle/SprinkleManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function init($sprinkleNames)
168168
}
169169

170170
/**
171-
* Initialize all base sprinkles in a specified sprinkles.json schema file.
171+
* Initialize all base sprinkles in a specified Sprinkles schema file (e.g. 'sprinkles.json').
172172
*
173173
* @param string $schemaPath
174174
*/
@@ -217,7 +217,7 @@ public function registerServices($name)
217217
}
218218

219219
/**
220-
* Load list of Sprinkles from a JSON schema file (e.g. sprinkles.json).
220+
* Load list of Sprinkles from a JSON schema file (e.g. 'sprinkles.json').
221221
*
222222
* @param string $schemaPath
223223
* @return string[]

app/system/UserFrosting.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ public function setupSprinkles($isWeb = true)
131131
$serviceProvider = new ServicesProvider();
132132
$serviceProvider->register($this->ci);
133133

134-
// Expected path to `sprinkles.json`
135-
$schemaPath = \UserFrosting\APP_DIR . '/sprinkles.json';
136-
137134
// Boot the Sprinkle manager, which creates Sprinkle classes and subscribes them to the event dispatcher
138135
$sprinkleManager = $this->ci->sprinkleManager;
139136

140137
try {
141-
$sprinkleManager->initFromSchema($schemaPath);
138+
$sprinkleManager->initFromSchema(\UserFrosting\SPRINKLES_SCHEMA_FILE);
142139
} catch (FileNotFoundException $e) {
143140
if ($isWeb) {
144141
$this->renderSprinkleErrorPage($e->getMessage());

0 commit comments

Comments
 (0)