Skip to content

Commit

Permalink
Explicit href property for the links.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavary committed Jul 23, 2014
1 parent f584682 commit fbd2f3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Lavary/Menu/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Item {
*
* @var array
*/
protected $attributes = array();
public $attributes = array();

/**
* Creates a new Lavary\Menu\MenuItem instance.
Expand Down Expand Up @@ -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);
}

Expand Down
30 changes: 26 additions & 4 deletions src/Lavary/Menu/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,14 +37,26 @@ public function __construct($path = array())
/**
* Make the anchor active
*
* @return Lavary\Menu\Item
* @return Lavary\Menu\Link
*/
public function active(){

$this->attributes['class'] = Builder::formatGroupClass(array('class' => 'active'), $this->attributes);
return $this;
}

/**
* Set Anchor's href property
*
* @return Lavary\Menu\Link
*/
public function href($href){

$this->href = $href;

return $this;
}

/**
* Make the url secure
*
Expand Down Expand Up @@ -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);

}
}

0 comments on commit fbd2f3f

Please sign in to comment.