From fbd2f3fee8e1f7c90439b8ab1948bab19e592770 Mon Sep 17 00:00:00 2001 From: Reza Lavaryan Date: Wed, 23 Jul 2014 04:59:30 +0430 Subject: [PATCH] Explicit href property for the links. --- src/Lavary/Menu/Item.php | 7 ++++++- src/Lavary/Menu/Link.php | 30 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Lavary/Menu/Item.php b/src/Lavary/Menu/Item.php index d605c24..d1abf74 100644 --- a/src/Lavary/Menu/Item.php +++ b/src/Lavary/Menu/Item.php @@ -56,7 +56,7 @@ class Item { * * @var array */ - protected $attributes = array(); + public $attributes = array(); /** * Creates a new Lavary\Menu\MenuItem instance. @@ -193,6 +193,11 @@ public function attr() */ public function url(){ + if( isset($this->link->href) ) { + + return $this->link->href; + } + return $this->builder->dispatch($this->link->path); } diff --git a/src/Lavary/Menu/Link.php b/src/Lavary/Menu/Link.php index 1c1e2c4..09ebaed 100644 --- a/src/Lavary/Menu/Link.php +++ b/src/Lavary/Menu/Link.php @@ -9,12 +9,19 @@ class Link { */ protected $path = array(); + /** + * Explicit href for the link + * + * @var string + */ + public $href; + /** * Link attributes * * @var array */ - protected $attributes = array(); + public $attributes = array(); /** * Creates a hyper link instance @@ -30,7 +37,7 @@ public function __construct($path = array()) /** * Make the anchor active * - * @return Lavary\Menu\Item + * @return Lavary\Menu\Link */ public function active(){ @@ -38,6 +45,18 @@ public function active(){ return $this; } + /** + * Set Anchor's href property + * + * @return Lavary\Menu\Link + */ + public function href($href){ + + $this->href = $href; + + return $this; + } + /** * Make the url secure * @@ -86,9 +105,12 @@ public function attr() public function __get($prop) { if( property_exists($this, $prop) ) { + return $this->$prop; - } - return false; + } + + return $this->attr($prop); + } } \ No newline at end of file