Skip to content

Commit

Permalink
Произведен рефакторинг
Browse files Browse the repository at this point in the history
Список плагинов переделан с backbone на vue.js
  • Loading branch information
butschster committed May 28, 2016
1 parent 844bf6c commit ca51615
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 197 deletions.
2 changes: 1 addition & 1 deletion src/Console/Commands/PluginsListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function fire()
{
$modules = [];

foreach (PluginLoader::findPlugins() as $module) {
foreach (PluginLoader::getPlugins() as $module) {
$modules[] = [
$module->getName().' ['.get_class($module).']',
'',
Expand Down
8 changes: 3 additions & 5 deletions src/Http/Controllers/API/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace KodiCMS\Plugins\Http\Controllers\API;

use KodiCMS\Plugins\Exceptions\PluginContainerException;
use PluginLoader;
use KodiCMS\API\Exceptions\PermissionException;
use KodiCMS\API\Http\Controllers\System\Controller;
use KodiCMS\Plugins\Exceptions\PluginContainerException;
use PluginLoader;

class PluginController extends Controller
{
Expand All @@ -15,9 +15,7 @@ public function getList()
throw new PermissionException('backend.plugins.list');
}

$this->setContent(
PluginLoader::findPlugins()->toArray()
);
$this->setContent(PluginLoader::getPlugins()->toArray());
}

/**
Expand Down
21 changes: 8 additions & 13 deletions src/Http/Controllers/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace KodiCMS\Plugins\Http\Controllers;

use Meta;
use PluginLoader;
use KodiCMS\Plugins\Loader\BasePluginContainer;
use KodiCMS\CMS\Http\Controllers\System\BackendController;
use KodiCMS\Plugins\Loader\BasePluginContainer;
use PluginLoader;

class PluginController extends BackendController
{
public function getIndex()
{
Meta::loadPackage('backbone');
$this->setContent('list');
}

Expand All @@ -23,11 +21,9 @@ public function getIndex()
public function getSettings($pluginId)
{
$plugin = $this->getPlugin($pluginId);
$this->setTitle(
trans($this->wrapNamespace('core.plugin_settings_page'), [
'title' => $plugin->getTitle(),
])
);
$this->setTitle(trans($this->wrapNamespace('core.plugin_settings_page'), [
'title' => $plugin->getTitle(),
]));

$settingsTemplate = $plugin->getSettingsTemplate();

Expand All @@ -47,10 +43,9 @@ public function postSettings($pluginId)

$plugin->saveSettings($settings);

return $this->smartRedirect([], 'backend.plugins.list')
->with('success', trans($this->wrapNamespace('core.messages.settings_saved'), [
'title' => $plugin->getTitle(),
]));
return $this->smartRedirect([], 'backend.plugins.list')->with('success', trans($this->wrapNamespace('core.messages.settings_saved'), [
'title' => $plugin->getTitle(),
]));
}

/**
Expand Down
22 changes: 18 additions & 4 deletions src/Loader/BasePluginContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use KodiCMS\Support\Traits\Settings;
use KodiCMS\Support\Loader\ModuleContainer;
use KodiCMS\Plugins\Exceptions\PluginContainerException;
use KodiCMS\Support\Facades\PluginLoader as PluginLoaderFacade;

abstract class BasePluginContainer extends ModuleContainer implements SettingsInterface
{
Expand Down Expand Up @@ -60,7 +59,6 @@ public function __construct($moduleName, $modulePath = null, $namespace = null)
}

$this->isInstallable = $this->checkPluginVersion();
$this->isActivated = in_array($this, PluginLoaderFacade::getActivated());

$this->setSettings($this->defaultSettings());
}
Expand All @@ -73,6 +71,21 @@ public function defaultSettings()
return [];
}

/**
* @return string
*/
public function getInfo()
{
return [
'version' => $this->getVersion(),
'description' => $this->getDescription(),
'authors' => [[
'name' => $this->getAuthor()
]]
];
}


/**
* @return string
*/
Expand Down Expand Up @@ -140,6 +153,7 @@ public function hasSettingsPage()
*/
public function isActivated()
{
$this->checkActivation();
return $this->isActivated;
}

Expand Down Expand Up @@ -180,7 +194,7 @@ public function getAssetsPublicPath()
*/
public function checkActivation()
{
return $this->isActivated = in_array($this, PluginLoaderFacade::getActivated());
return $this->isActivated = \PluginLoader::isActivated($this->getName());
}

/**
Expand Down Expand Up @@ -265,7 +279,7 @@ public function saveSettings(array $settings)
*/
protected function checkPluginVersion()
{
return version_compare(CMS::VERSION, $this->getRequiredVersion(), '>=');
return version_compare(CMS::getVersion(), $this->getRequiredVersion(), '>=');
}

/**
Expand Down
40 changes: 25 additions & 15 deletions src/Loader/PluginLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,17 @@ public function init()
/**
* @return Collection|BasePluginContainer[]
*/
public function getActivated()
public function getPlugins()
{
return $this->activated;
return $this->plugins;
}

/**
* @return Collection|BasePluginContainer[]
*/
public function findPlugins()
public function getActivated()
{
foreach ($this->files->directories($this->getPath()) as $directory) {
foreach ($this->files->directories($directory) as $plugin) {
if (is_null($class = $this->initPlugin($plugin))) {
continue;
}

$this->plugins->push($class);
}
}

return $this->plugins;
return $this->activated;
}

/**
Expand Down Expand Up @@ -150,7 +140,9 @@ public function activatePlugin($name)
public function deactivatePlugin($name, $removeTable = false)
{
$status = false;

if ($this->isActivated($name) and ! is_null($plugin = $this->getPluginContainer($name))) {

$status = $plugin->deactivate($removeTable);

if (app()->routesAreCached()) {
Expand All @@ -177,6 +169,7 @@ protected function initPlugin($directory)
$namespace = "Plugins\\{$vendorName}\\{$pluginName}";
$class = "{$namespace}\\PluginContainer";


if (! class_exists($class)) {
return;
}
Expand Down Expand Up @@ -211,7 +204,6 @@ protected function loadActivated()

return $this->activated;
}

/**
* @param string $key
*
Expand All @@ -221,4 +213,22 @@ protected function pluginExists($key)
{
return $this->files->isDirectory($this->path.DIRECTORY_SEPARATOR.$key);
}

/**
* @return Collection|BasePluginContainer[]
*/
protected function findPlugins()
{
foreach ($this->files->directories($this->getPath()) as $directory) {
foreach ($this->files->directories($directory) as $plugin) {
if (is_null($class = $this->initPlugin($plugin))) {
continue;
}

$this->plugins->push($class);
}
}

return $this->plugins;
}
}
12 changes: 4 additions & 8 deletions src/Providers/PluginServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
use KodiCMS\Support\ServiceProvider;
use KodiCMS\Plugins\Loader\PluginLoader;
use KodiCMS\Plugins\Loader\PluginInstaller;
use KodiCMS\Plugins\Console\Commands\PluginsListCommand;
use KodiCMS\Plugins\Console\Commands\PluginActivateCommand;
use KodiCMS\Plugins\Console\Commands\PluginDeactivateCommand;
use KodiCMS\Plugins\Facades\PluginLoader as PluginLoaderFacade;

class PluginServiceProvider extends ServiceProvider
{
Expand All @@ -28,7 +24,7 @@ public function __construct($app)
public function register()
{
$this->registerAliases([
'PluginLoader' => PluginLoaderFacade::class,
'PluginLoader' => \KodiCMS\Plugins\Facades\PluginLoader::class,
]);

$this->app->singleton('plugin.installer', function ($app) {
Expand All @@ -44,9 +40,9 @@ public function register()
}

$this->registerConsoleCommand([
PluginsListCommand::class,
PluginActivateCommand::class,
PluginDeactivateCommand::class,
\KodiCMS\Plugins\Console\Commands\PluginsListCommand::class,
\KodiCMS\Plugins\Console\Commands\PluginActivateCommand::class,
\KodiCMS\Plugins\Console\Commands\PluginDeactivateCommand::class,
]);
}
}
Loading

0 comments on commit ca51615

Please sign in to comment.