From: Andrey Kutejko Date: Sat, 17 Dec 2016 19:15:56 +0000 (+0100) Subject: no statics in admin app class X-Git-Tag: 0.6~36 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=84dc600dab119137af6e6cdcd12a809f0bf96ef9;p=ipf.git no statics in admin app class --- diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 1ebf0dc..269caa4 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -38,9 +38,9 @@ class IPF_Admin_App extends IPF_Application public function appList($request) { $app_list = array(); - foreach (IPF_Project::getInstance()->appList() as $app) { + foreach ($this->getProject()->appList() as $app) { $components = array(); - foreach (IPF_Admin_App::applicationComponents($app) as $component) { + foreach ($this->applicationComponents($app) as $component) { if ($component->isAccessible(array('view'), $request)) { $component->request = $request; $components[] = $component; @@ -81,11 +81,11 @@ class IPF_Admin_App extends IPF_Application ); } - private static $appComponents = array(); + private $appComponents = array(); - public static function applicationComponents($app) + public function applicationComponents($app) { - if (!array_key_exists($app->slug(), self::$appComponents)) { + if (!array_key_exists($app->slug(), $this->appComponents)) { $components = array(); if (is_file($app->getPath().'/admin.php')) { @@ -97,25 +97,25 @@ class IPF_Admin_App extends IPF_Application } } - self::$appComponents[$app->slug()] = $components; + $this->appComponents[$app->slug()] = $components; } - return self::$appComponents[$app->slug()]; + return $this->appComponents[$app->slug()]; } - public static function getApplicationBySlug($slug) + public function getApplicationBySlug($slug) { - foreach (IPF_Project::getInstance()->appList() as $app) - if ($app->slug() == $slug) + foreach ($this->getProject()->appList() as $app) + if ($app->slug() === $slug) return $app; return null; } - public static function getComponentBySlugs($appSlug, $componentSlug) + public function getComponentBySlugs($appSlug, $componentSlug) { - $app = self::getApplicationBySlug($appSlug); + $app = $this->getProject()->getApplicationBySlug($appSlug); if (!$app) return null; - foreach (self::applicationComponents($app) as $component) { + foreach ($this->applicationComponents($app) as $component) { if ($component->slug() == $componentSlug) return $component; } @@ -125,7 +125,7 @@ class IPF_Admin_App extends IPF_Application public function commands() { return array( - new IPF_Admin_Command_SyncPerms, + new IPF_Admin_Command_SyncPerms($this), ); } } diff --git a/ipf/admin/commands/syncperms.php b/ipf/admin/commands/syncperms.php index 6c72466..c2a4319 100644 --- a/ipf/admin/commands/syncperms.php +++ b/ipf/admin/commands/syncperms.php @@ -5,6 +5,14 @@ class IPF_Admin_Command_SyncPerms public $command = 'syncperms'; public $description = 'Create/Update permissions from admin components'; + /** @var IPF_Admin_App */ + private $admin_app; + + public function __construct(IPF_Admin_App $admin_app) + { + $this->admin_app = $admin_app; + } + public function run($args=null) { print "Create/Update permissions from admin components\n"; @@ -12,7 +20,7 @@ class IPF_Admin_Command_SyncPerms print "COLLECTED PERMISSIONS:\n"; $permissions = array(); foreach (IPF_Project::getInstance()->appList() as $appname => $app) { - foreach (IPF_Admin_App::applicationComponents($app) as $component) { + foreach ($this->admin_app->applicationComponents($app) as $component) { foreach ($component->getPerms(null) as $permName) { $name = $app->slug().'|'.$component->slug().'|'.$permName; $permissions[$name] = array($app, $component, $permName); diff --git a/ipf/admin/controllers/base.php b/ipf/admin/controllers/base.php index e521279..796109b 100644 --- a/ipf/admin/controllers/base.php +++ b/ipf/admin/controllers/base.php @@ -15,5 +15,17 @@ abstract class IPF_Admin_Base_Controller extends IPF_Controller { return IPF_Shortcuts::RenderToResponse($template, $params, $this->request); } -} + /** + * @return IPF_Admin_App + * @throws Exception + */ + protected function adminApplication() + { + foreach ($this->project->appList() as $app) { + if ($app instanceof IPF_Admin_App) + return $app; + } + throw new Exception('Admin application is not registered in project.'); + } +} diff --git a/ipf/admin/controllers/components.php b/ipf/admin/controllers/components.php index 6427217..c4a5529 100644 --- a/ipf/admin/controllers/components.php +++ b/ipf/admin/controllers/components.php @@ -57,7 +57,7 @@ class IPF_Admin_Components_Controller extends IPF_Admin_Base_Controller { $this->ensureUserIsStaff(); - $this->component = IPF_Admin_App::getComponentBySlugs($this->request->params[1], $this->request->params[2]); + $this->component = $this->adminApplication()->getComponentBySlugs($this->request->params[1], $this->request->params[2]); if (!$this->component) throw new IPF_HTTP_Error404; @@ -80,4 +80,3 @@ class IPF_Admin_Components_Controller extends IPF_Admin_Base_Controller return $this->render($template, $context); } } - diff --git a/ipf/auth/admin.php b/ipf/auth/admin.php index b4679e5..ccd9d08 100644 --- a/ipf/auth/admin.php +++ b/ipf/auth/admin.php @@ -8,10 +8,13 @@ use \PFF\HtmlBuilder\Text as Text; function permissionChoices() { + /** @var \IPF_Admin_App $admin_app */ + $admin_app = \IPF_Project::getInstance()->getApplicationBySlug('admin'); + $choices = array(); foreach (Permission::query()->fetchAll() as $p) { list($appSlug, $componentSlug, $permission) = explode('|', $p->name); - $component = \IPF_Admin_App::getComponentBySlugs($appSlug, $componentSlug); + $component = $admin_app->getComponentBySlugs($appSlug, $componentSlug); if ($component) $title = $component->app->getTitle().' | '.$component->verbose_name().' | '.ucfirst($permission);