Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
kill static methods in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nizsheanez committed Aug 22, 2012
1 parent 9d077bb commit 58b5a38
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 89 deletions.
34 changes: 13 additions & 21 deletions protected/components/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ public static function init()
public static function getModulesData($active = null, $check_allowed_links = false)
{
$modules = array();
foreach (Yii::app()->getModules() as $module_dir => $module_config)
foreach (Yii::app()->getModules() as $module_id => $module_config)
{
$module_class = ucfirst($module_dir) . 'Module';
$module_path = MODULES_PATH . $module_dir . '/' . $module_class . '.php';

if (!file_exists($module_path))
{
continue;
}

require_once $module_path;

$module = Yii::app()->getModule($module_id);
$module_class = get_class($module);
$vars = get_class_vars($module_class);
if (!$vars)
{
Expand All @@ -64,17 +56,17 @@ public static function getModulesData($active = null, $check_allowed_links = fal
}
}

$module = array(
'description' => call_user_func(array($module_class, 'description')),
'version' => call_user_func(array($module_class, 'version')),
'name' => call_user_func(array($module_class, 'name')),
$moduleInfo = array(
'description' => $module->getDescription(),
'version' => $module->getVersion(),
'name' => $module->getName(),
'class' => $module_class,
'dir' => $module_dir
'dir' => $module_id
);

if (method_exists($module_class, 'adminMenu'))
if (method_exists($module, 'adminMenu'))
{
$module['admin_menu'] = call_user_func(array($module_class, 'adminMenu'));
$moduleInfo['admin_menu'] = $module->adminMenu();

// $settins_count = Param::model()->count("module_id = '{$module_dir}'");
// if ($settins_count)
Expand All @@ -84,7 +76,7 @@ public static function getModulesData($active = null, $check_allowed_links = fal

if ($check_allowed_links)
{
foreach ($module['admin_menu'] as $title => $url)
foreach ($moduleInfo['admin_menu'] as $title => $url)
{
$url = explode('/', trim($url, '/'));

Expand All @@ -99,13 +91,13 @@ public static function getModulesData($active = null, $check_allowed_links = fal

if (!RbacModule::isAllow($auth_item))
{
unset($module['admin_menu'][$title]);
unset($moduleInfo['admin_menu'][$title]);
}
}
}
}

$modules[$module_class] = $module;
$modules[$module_class] = $moduleInfo;
}

return $modules;
Expand Down
8 changes: 4 additions & 4 deletions protected/components/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function collectRules()

if (Yii::app()->params['collect_routes_from_modules'])
{
$modules = AppManager::getModulesData(true);
foreach ($modules as $class => $data)
foreach (Yii::app()->getModules() as $id => $config)
{
if (method_exists($class, 'routes'))
$module = Yii::app()->getModule($id);
if (method_exists($module, 'routes'))
{
$routes = array_merge($routes, call_user_func(array($class, 'routes')));
$routes = array_merge($routes, $module->routes());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion protected/components/WebModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function assetsUrl()
}


public static function routes()
public function routes()
{
return array();
}
Expand Down
6 changes: 2 additions & 4 deletions protected/components/interfaces/WebModuleInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
interface WebModuleInterface
{
public static function name();
public function getName();

public static function description();

public static function version();
public function getDescription();
}
8 changes: 4 additions & 4 deletions protected/modules/banners/BannersModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ class BannersModule extends WebModule
public static $active = true;


public static function name()
public function getName()
{
return 'Баннеры';
}


public static function description()
public function getDescription()
{
return 'баннеры';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand Down Expand Up @@ -50,7 +50,7 @@ public function getOperations()
}


public static function adminMenu()
public function adminMenu()
{
return array(
'Баннеры (горизонт.)' => '/banners/bannerAdmin/manage/is_big/1',
Expand Down
8 changes: 4 additions & 4 deletions protected/modules/codegen/CodegenModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ class CodegenModule extends WebModule
public static $active = true;


public static function name()
public function getName()
{
return 'Генератор кода';
}


public static function description()
public function getDescription()
{
return 'Генератор кода';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand All @@ -32,7 +32,7 @@ public function init()
}


public static function adminMenu()
public function adminMenu()
{
return array(
'Создать модуль' => Yii::app()->createUrl('/codegen/moduleAdmin/create'),
Expand Down
10 changes: 5 additions & 5 deletions protected/modules/comments/CommentsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ class CommentsModule extends WebModule
public static $active = true;


public static function name()
public function getName()
{
return 'Комментарии';
}


public static function description()
public function getDescription()
{
return 'Комментарии';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand All @@ -32,14 +32,14 @@ public function init()
}


public static function adminMenu()
public function adminMenu()
{
return array(
);
}


public static function routes()
public function routes()
{
return array(
);
Expand Down
10 changes: 5 additions & 5 deletions protected/modules/content/ContentModule.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?
class ContentModule extends WebModule
{
public static function name()
public function getName()
{
return 'Контент';
}


public static function description()
public function getDescription()
{
return 'Свободно редактируемые страницы, контентные блоки, меню сайта';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand All @@ -29,7 +29,7 @@ public function init()
}


public static function adminMenu()
public function adminMenu()
{
return array(
'Список страниц' => Yii::app()->createUrl('/content/pageAdmin/manage'),
Expand All @@ -42,7 +42,7 @@ public static function adminMenu()
}


public static function routes()
public function routes()
{
$routes = array(
'/' => 'content/page/index',
Expand Down
10 changes: 5 additions & 5 deletions protected/modules/docs/DocsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ class DocsModule extends WebModule
public static $active = true;


public static function name()
public function getName()
{
return 'Документациякода';
}


public static function description()
public function getDescription()
{
return 'Документация';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand All @@ -30,7 +30,7 @@ public function init()
));
}

public static function routes()
public function routes()
{
return array(
'/docs/module/<module:.*>/<view:.*>' => '/docs/docs/module',
Expand All @@ -41,7 +41,7 @@ public static function routes()
}


public static function adminMenu()
public function adminMenu()
{
return array(
);
Expand Down
10 changes: 5 additions & 5 deletions protected/modules/fileManager/FileManagerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ public function init()
));
}

public static function name()
public function getName()
{
return 'Файловый менеджер';
}


public static function description()
public function getDescription()
{
return 'Добавляет возможность использования HTML5 загрузчика. Используется для создания своих модулей.';
}


public static function version()
public function getVersion()
{
return '2.1';
}


public static function adminMenu()
public function adminMenu()
{
return array(
"Все файлы" => "/fileManager/fileManagerAdmin/manage",
);
}

public static function routes()
public function routes()
{
return array(
'/userAlbums/<userId:\d*>' => '/fileManager/fileAlbum/userAlbums',
Expand Down
8 changes: 4 additions & 4 deletions protected/modules/install/InstallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ class InstallModule extends WebModule
{
public static $base_module = true;

public static function description()
public function getDescription()
{
return 'Модуль установки';
}


public static function version()
public function getVversion()
{
return '0.0.1';
}


public static function name()
public function getName()
{
return 'Установочный';
}
Expand All @@ -29,7 +29,7 @@ public function init()
));
}

public static function routes()
public function routes()
{
return array(
'/install' => 'install/install/index',
Expand Down
8 changes: 4 additions & 4 deletions protected/modules/mailer/MailerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class MailerModule extends WebModule
public static $active = true;


public static function name()
public function getName()
{
return 'Рассылка';
}


public static function description()
public function getDescription()
{
return 'Email рассылка';
}


public static function version()
public function getVersion()
{
return '1.0';
}
Expand All @@ -53,7 +53,7 @@ public function beforeControllerAction($controller, $action)
}


public static function adminMenu()
public function adminMenu()
{
return array(
'Исходящие письма' => Yii::app()->createUrl('/mailer/mailerOutboxAdmin/manage'),
Expand Down
Loading

0 comments on commit 58b5a38

Please sign in to comment.