Skip to content

Commit

Permalink
Optimized theme autoloader to work with hyphenated classnames #1353
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Mar 15, 2017
1 parent 79d6b8a commit 8741604
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions system/src/Grav/Common/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,14 @@ protected function loadLanguages(Config $config)
*/
protected function autoloadTheme($class)
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];

$prefix = "Grav\\Theme";
if (false !== strpos($class, $prefix)) {
// Remove prefix from class
$class = substr($class, strlen($prefix));

// Replace namespace tokens to directory separators
$path = strtolower(ltrim(preg_replace('#\\\|_(?!.+\\\)#', '/', $class), '/'));
$file = $locator->findResource("themes://{$path}/{$path}.php");
$path = $this->grav['inflector']->hyphenize(ltrim($class,"\\"));
$file = $this->grav['locator']->findResource("themes://{$path}/{$path}.php");

// Load class
if (file_exists($file)) {
Expand Down

0 comments on commit 8741604

Please sign in to comment.