Skip to content

Commit

Permalink
Possible fix for #81
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidesu committed Jul 6, 2015
1 parent e84f03e commit f147126
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public function generate(Command $console)

$console->info("Module [{$this->name}] has been created successfully.");

$this->optimize($console);

return true;
}

Expand Down Expand Up @@ -158,6 +160,16 @@ protected function generateFiles()
}
}

/**
* Optimize the framework for better performance.
*
* @return void
*/
protected function optimize(Command $console)
{
$console->call('optimize');
}

/**
* Generate .gitkeep files within generated folders.
*
Expand Down
12 changes: 6 additions & 6 deletions src/Caffeinated/Modules/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ public function register()
{
$modules = $this->repository->enabled();

foreach ($modules as $module) {
$this->registerServiceProvider($module);
}
$modules->each(function($properties, $slug) {
$this->registerServiceProvider($properties);
});
}

/**
* Register the module service provider.
*
* @param string $module
* @param string $properties
* @return string
* @throws \Caffeinated\Modules\Exception\FileMissingException
*/
protected function registerServiceProvider($module)
protected function registerServiceProvider($properties)
{
$module = studly_case($module['slug']);
$module = studly_case($properties['slug']);
$file = $this->repository->getPath()."/{$module}/Providers/{$module}ServiceProvider.php";
$namespace = $this->repository->getNamespace().$module."\\Providers\\{$module}ServiceProvider";

Expand Down
8 changes: 3 additions & 5 deletions src/Caffeinated/Modules/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ModulesServiceProvider extends ServiceProvider
/**
* @var bool $defer Indicates if loading of the provider is deferred.
*/
protected $defer = true;
protected $defer = false;

/**
* Boot the service provider.
Expand All @@ -20,6 +20,8 @@ public function boot()
$this->publishes([
__DIR__.'/../../config/modules.php' => config_path('modules.php'),
]);

$this->app['modules']->register();
}

/**
Expand All @@ -44,10 +46,6 @@ public function register()

return new \Caffeinated\Modules\Modules($app, $repository);
});

$this->app->booting(function ($app) {
$app['modules']->register();
});
}

/**
Expand Down
17 changes: 9 additions & 8 deletions src/Caffeinated/Modules/Repositories/Local/ModuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class ModuleRepository extends Repository
*/
public function all()
{
$modules = $this->getAllBasenames();
$basenames = $this->getAllBasenames();
$modules = collect();

foreach ($modules as $key => $module) {
$modules[$key] = $this->getProperties($module);
}
$basenames->each(function($module, $key) use ($modules) {
$modules->put($module, $this->getProperties($module));
});

return collect($modules)->sortBy('order');
return $modules->sortBy('order');
}

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ public function where($key, $value)
{
$collection = $this->all();

return $collection->where($key, $value)->all();
return $collection->where($key, $value);
}

/**
Expand All @@ -61,7 +62,7 @@ public function sortBy($key)
{
$collection = $this->all();

return $collection->sortBy($key)->all();
return $collection->sortBy($key);
}

/**
Expand All @@ -74,7 +75,7 @@ public function sortByDesc($key)
{
$collection = $this->all();

return $collection->sortByDesc($key)->all();
return $collection->sortByDesc($key);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Caffeinated/Modules/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public function __construct(Config $config, Filesystem $files)
*/
protected function getAllBasenames()
{
$path = $this->getPath();
$path = $this->getPath();
$collection = collect($this->files->directories($path));

if ($this->files->exists($path)) {
return array_map('basename', $this->files->directories($path));
}
$basenames = $collection->map(function($item, $key) {
return basename($item);
});

return array();
return $basenames;
}

/**
Expand Down

0 comments on commit f147126

Please # to comment.