]> git.andy128k.dev Git - ipf.git/commitdiff
no statics in admin app class
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 17 Dec 2016 19:15:56 +0000 (20:15 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 17 Dec 2016 19:15:56 +0000 (20:15 +0100)
ipf/admin/app.php
ipf/admin/commands/syncperms.php
ipf/admin/controllers/base.php
ipf/admin/controllers/components.php
ipf/auth/admin.php

index 1ebf0dcf0f81ad14ef932abc483af005942732bc..269caa49fc8bb564160276179abb7a81e969657b 100644 (file)
@@ -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),
         );
     }
 }
index 6c724662e21e1864bcf0634735a36e748543ddcd..c2a43197e5fe4ee9a97fed84de03ed6a7737f421 100644 (file)
@@ -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);
index e5212794ffcb3235d24e5dd6b1c7e9da93ffa796..796109b7b9521dd3e72684082e5752ca9d5a55e4 100644 (file)
@@ -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.');
+    }
+}
index 64272173ec29371b5608a836b2d46107c3a3b360..c4a552975b9750d56a2c744f5e04115a7f452433 100644 (file)
@@ -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);
     }
 }
-
index b4679e572f9c7c64acdb6d46383b82422f85cd1f..ccd9d083c5711c58bc8abca0baad36e25cd8362b 100644 (file)
@@ -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);