Skip to content

Commit

Permalink
Factor out hardcoded sprinkles.json filename (partially addresses #813
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alexweissman committed Dec 13, 2017
1 parent d596e06 commit c9a9b40
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions app/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
11 changes: 5 additions & 6 deletions app/system/Bakery/Bakery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -145,15 +144,15 @@ 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
*/
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.");
Expand All @@ -164,4 +163,4 @@ protected function setupBaseSprinkleList()

return $sprinklesModelFile;
}
}
}
4 changes: 2 additions & 2 deletions app/system/Bakery/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -55,4 +55,4 @@ public function setContainer(ContainerInterface $ci)
{
$this->ci = $ci;
}
}
}
8 changes: 4 additions & 4 deletions app/system/Bakery/Command/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ 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
* @return void
*/
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.");
Expand Down Expand Up @@ -182,4 +182,4 @@ protected function showConfig()
"PASSWORD : " . ($config['db.default.password'] ? "*********" : "")
]);
}
}
}
4 changes: 2 additions & 2 deletions app/system/Sprinkle/SprinkleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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[]
Expand Down
5 changes: 1 addition & 4 deletions app/system/UserFrosting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c9a9b40

Please sign in to comment.