]> git.andy128k.dev Git - ipf.git/commitdiff
introduce admin section interface
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 17 Dec 2016 19:52:06 +0000 (20:52 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 17 Dec 2016 19:52:06 +0000 (20:52 +0100)
ipf/admin/app.php
ipf/admin/section.php [new file with mode: 0644]

index 269caa49fc8bb564160276179abb7a81e969657b..b4e97cd35fa82ce093a9c5740a5ab73a69428c53 100644 (file)
@@ -89,9 +89,12 @@ class IPF_Admin_App extends IPF_Application
             $components = array();
 
             if (is_file($app->getPath().'/admin.php')) {
-                $list = require_once $app->getPath().'/admin.php';
-                foreach ($list as $c) {
-                    $component = is_string($c) ? new $c : $c;
+                $section = require_once $app->getPath().'/admin.php';
+                if (!($section instanceof IPF_Admin_ISection)) {
+                    $section = new IPF_Admin_SimpleSection($section);
+                }
+
+                foreach ($section->components($this->getProject(), $app) as $component) {
                     $component->app = $app;
                     $components[] = $component;
                 }
diff --git a/ipf/admin/section.php b/ipf/admin/section.php
new file mode 100644 (file)
index 0000000..1f2cac7
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+interface IPF_Admin_ISection
+{
+    /**
+     * @param IPF_Project $project
+     * @param IPF_Application $app
+     * @return IPF_Admin_Component[]
+     */
+    public function components(IPF_Project $project, IPF_Application $app);
+}
+
+class IPF_Admin_SimpleSection implements IPF_Admin_ISection
+{
+    /** @var array */
+    private $component_names;
+
+    public function __construct(array $component_names)
+    {
+        $this->component_names = $component_names;
+    }
+
+    /**
+     * @param IPF_Project $project
+     * @param IPF_Application $app
+     * @return IPF_Admin_Component[]
+     */
+    public function components(IPF_Project $project, IPF_Application $app)
+    {
+        $components = array();
+        foreach ($this->component_names as $c) {
+            $component = is_string($c) ? new $c : $c;
+            $components[] = $component;
+        }
+        return $components;
+    }
+}