From 9ce8269dc9433d7b2af3c3377051f569efba4696 Mon Sep 17 00:00:00 2001 From: junjun Date: Thu, 2 Jun 2016 19:35:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A8=A1=E6=9D=BF=E6=B8=B2?= =?UTF-8?q?=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Collections/AbstractCollection.php | 32 ++++++++++++++++++- src/Collections/Database.php | 2 +- src/Collections/Event.php | 3 +- src/Collections/Route.php | 2 +- src/Controller/PurpleController.php | 4 ++- src/PurpleHook.php | 1 - src/Resources/index.blade.php | 32 +++++++++---------- .../{event.blade.php => events.blade.php} | 0 8 files changed, 53 insertions(+), 23 deletions(-) rename src/Resources/modules/{event.blade.php => events.blade.php} (100%) diff --git a/src/Collections/AbstractCollection.php b/src/Collections/AbstractCollection.php index d2d1587..928d285 100644 --- a/src/Collections/AbstractCollection.php +++ b/src/Collections/AbstractCollection.php @@ -31,7 +31,11 @@ abstract class AbstractCollection implements CollectionInterface * @var Application */ protected $app; - + + /** + * 模板名称 + * @var string + */ protected $template; /** @@ -52,6 +56,13 @@ abstract class AbstractCollection implements CollectionInterface */ protected $global = []; + /** + * icon名称 + * @var string + */ + protected $icon; + + protected $url; /** * 注册收集器 * @param Application $app @@ -125,6 +136,11 @@ public function getTemplate() return $this->template; } + public function getIcon() + { + return $this->icon; + } + /** * 获取收集器收集到的信息数量 * @return int @@ -134,6 +150,20 @@ public function calcBadge() $this->badge = count($this->data[$this->template]); } + public function getMenu() + { + /** + * @var $current \Illuminate\Routing\Route + */ + $current = $this->app['router']->current(); + return [ + 'name' => $this->getName(), + 'icon' => $this->getIcon(), + 'badge' => $this->getBadge(), + 'url' => route('purple.index', ['id' => $current->getParameter('id'), 'key' => $this->getName()]) + ]; + } + public function formatData() { return [ diff --git a/src/Collections/Database.php b/src/Collections/Database.php index acaef85..5e24ba7 100644 --- a/src/Collections/Database.php +++ b/src/Collections/Database.php @@ -18,7 +18,7 @@ class Database extends AbstractCollection protected $name = 'db'; protected $icon = 'database'; - + protected $template = 'query'; public function before(Application $application) diff --git a/src/Collections/Event.php b/src/Collections/Event.php index b78ddc1..4f88896 100644 --- a/src/Collections/Event.php +++ b/src/Collections/Event.php @@ -22,11 +22,10 @@ class Event extends AbstractCollection public function before(Application $application) { - parent::before($application); - /** * @var $event \Illuminate\Events\Dispatcher */ + parent::before($application); $event = $application['events']; $event->listen('*', [$this, 'eventFired']); } diff --git a/src/Collections/Route.php b/src/Collections/Route.php index c262a75..d60f9db 100644 --- a/src/Collections/Route.php +++ b/src/Collections/Route.php @@ -19,7 +19,7 @@ class Route extends AbstractCollection protected $icon = 'road'; protected $template = 'routes'; - + public function after(Application $app, Response $response) { /** diff --git a/src/Controller/PurpleController.php b/src/Controller/PurpleController.php index e98c986..51babeb 100644 --- a/src/Controller/PurpleController.php +++ b/src/Controller/PurpleController.php @@ -59,6 +59,7 @@ protected function buildViewData($result, CollectionInterface $collection) protected function getGlobalData() { $global = []; + $menu = []; /** * @var $hook \Purple\PurpleHook */ @@ -67,9 +68,10 @@ protected function getGlobalData() foreach ($collections as $collection) { $global = array_merge($collection->getGlobal(), $global); + array_push($menu, $collection->getMenu()); } - $global['menu'] = []; + $global['menus'] = $menu; return $global; } diff --git a/src/PurpleHook.php b/src/PurpleHook.php index 6e99926..9109ee4 100644 --- a/src/PurpleHook.php +++ b/src/PurpleHook.php @@ -59,7 +59,6 @@ public function __construct(Application $app) $this->app = $app; foreach ($this->defaultCollections as $collection) { -// array_push($this->collections, $app->make($collection)); $collection = $app->make($collection); $this->collections[$collection->getName()] = $collection; } diff --git a/src/Resources/index.blade.php b/src/Resources/index.blade.php index c81c708..45c32c5 100644 --- a/src/Resources/index.blade.php +++ b/src/Resources/index.blade.php @@ -17,22 +17,22 @@ class="fa fa-reply"> diff --git a/src/Resources/modules/event.blade.php b/src/Resources/modules/events.blade.php similarity index 100% rename from src/Resources/modules/event.blade.php rename to src/Resources/modules/events.blade.php