<commit_before><?php namespace Fbf\LaravelNavigation;

class NavigationComposer {

	const SHOW_IF_CURRENT_ROUTE_IN_SECTION = 1;
	const SHOW_ALWAYS = 2;
	const SHOW_CHILDREN_ALWAYS = 3;
	const SHOW_CHILDREN_IF_PARENT_OF_CURRENT_ROUTE = 4;

	protected $defaultOptions = array(
		'from_depth' => 1,
		'from_item_id' => null,
		'max_depth' => null,
		'root_element' => 'div',
		'root_element_class' => 'menu',
		'root_element_type_class_prefix' => 'menu--',
		'list_element' => 'ul',
		'root_list_class' => '',
		'current_item_content_element' => 'span',
		'item_content_depth_prefix' => '..',
		'item_element' => 'li',
		'item_class' => '',
		'active_child_class' => 'menu--item__selected-child',
		'active_class' => 'menu--item__selected',
		'first_class' => 'menu--item__first',
		'last_class' => 'menu--item__last',
		'has_children_class' => 'menu--item__has-children',
	);

	protected $options = array();

	protected $type = null;
	protected $subtype = null;

	protected $effectiveRouteNode = null;
	protected $currentRouteNode = null;
	protected $currentRouteAncestorNode = null;

	protected static $done = array();

	public function compose($view)
	{
		$this->currentRouteNode = $this->effectiveRouteNode = $this->getNodeForCurrentRoute();
		if (!$this->currentRouteNode)
		{
			$this->currentRouteAncestorNode = $this->effectiveRouteNode = $this->getAncestorNodeForCurrentRoute();
		}
		$types = \Config::get('laravel-navigation::types');
		foreach ($types as $type => $subtypes)
		{
			if (!is_array(current($subtypes)))
			{
				$subtypes = array($type => $subtypes);
			}
			foreach ($subtypes as $subtype => $options)
			{
				// Skip this subtype if we've done it already. Could have happened if we've attached the composer to
				// more than one view file, e.g. a partial and a view and a layout.
				if (in_array($subtype, self::$done))
				{
					continue;
				}
				$this->options = array_merge($this->defaultOptions, $options);
				$this->type = $type;
				$this->subtype = $subtype;
				if ($this->options['show'] == self::SHOW_ALWAYS || ($this->options['show'] == self::SHOW_IF_CURRENT_ROUTE_IN_SECTION && $this->currentRouteInSection()))
				{
					$navigation = $this->getNavigation();
					self::$done[] = $subtype;
					$view->with($subtype.'Navigation', $navigation);
				}
			}
		}
	}

	protected function getNodeForCurrentRoute()
	{
		$currentUri = \Request::path();
		if ($navItem = NavItem::where('uri','=',$currentUri)->orWhere('uri','=','/'.$currentUri)->first())
		{
			return $navItem;
		}
		return null;
	}

	protected function getAncestorNodeForCurrentRoute()
	{
		$currentRoute = \Route::currentRouteName();
		$currentRoute = preg_replace('/^(get|post|put|delete) /i', '', $currentRoute);
		if ($navItem = NavItem::where('descendants_routes','LIKE','%'.$currentRoute.'%')->first())
		{
			return $navItem;
		}
		return null;
	}
<commit_msg>Fixing bug for Laravel 4.1 where route is a descendant route<commit_after><?php namespace Fbf\LaravelNavigation;

class NavigationComposer {

	const SHOW_IF_CURRENT_ROUTE_IN_SECTION = 1;
	const SHOW_ALWAYS = 2;
	const SHOW_CHILDREN_ALWAYS = 3;
	const SHOW_CHILDREN_IF_PARENT_OF_CURRENT_ROUTE = 4;

	protected $defaultOptions = array(
		'from_depth' => 1,
		'from_item_id' => null,
		'max_depth' => null,
		'root_element' => 'div',
		'root_element_class' => 'menu',
		'root_element_type_class_prefix' => 'menu--',
		'list_element' => 'ul',
		'root_list_class' => '',
		'current_item_content_element' => 'span',
		'item_content_depth_prefix' => '..',
		'item_element' => 'li',
		'item_class' => '',
		'active_child_class' => 'menu--item__selected-child',
		'active_class' => 'menu--item__selected',
		'first_class' => 'menu--item__first',
		'last_class' => 'menu--item__last',
		'has_children_class' => 'menu--item__has-children',
	);

	protected $options = array();

	protected $type = null;
	protected $subtype = null;

	protected $effectiveRouteNode = null;
	protected $currentRouteNode = null;
	protected $currentRouteAncestorNode = null;

	protected static $done = array();

	public function compose($view)
	{
		$this->currentRouteNode = $this->effectiveRouteNode = $this->getNodeForCurrentRoute();
		if (!$this->currentRouteNode)
		{
			$this->currentRouteAncestorNode = $this->effectiveRouteNode = $this->getAncestorNodeForCurrentRoute();
		}
		$types = \Config::get('laravel-navigation::types');
		foreach ($types as $type => $subtypes)
		{
			if (!is_array(current($subtypes)))
			{
				$subtypes = array($type => $subtypes);
			}
			foreach ($subtypes as $subtype => $options)
			{
				// Skip this subtype if we've done it already. Could have happened if we've attached the composer to
				// more than one view file, e.g. a partial and a view and a layout.
				if (in_array($subtype, self::$done))
				{
					continue;
				}
				$this->options = array_merge($this->defaultOptions, $options);
				$this->type = $type;
				$this->subtype = $subtype;
				if ($this->options['show'] == self::SHOW_ALWAYS || ($this->options['show'] == self::SHOW_IF_CURRENT_ROUTE_IN_SECTION && $this->currentRouteInSection()))
				{
					$navigation = $this->getNavigation();
					self::$done[] = $subtype;
					$view->with($subtype.'Navigation', $navigation);
				}
			}
		}
	}

	protected function getNodeForCurrentRoute()
	{
		$currentUri = \Request::path();
		if ($navItem = NavItem::where('uri','=',$currentUri)->orWhere('uri','=','/'.$currentUri)->first())
		{
			return $navItem;
		}
		return null;
	}

	protected function getAncestorNodeForCurrentRoute()
	{
		$currentRoute = \Route::current()->getUri();
		$currentRoute = preg_replace('/^(get|post|put|delete) /i', '', $currentRoute);
		if ($navItem = NavItem::where('descendants_routes','LIKE','%'.$currentRoute.'%')->first())
		{
			return $navItem;
		}
		return null;
	}

{'fraction_non_alphanumeric': 0.17172937521574042, 'fraction_numerical': 0.0020711080428028996, 'mean_word_length': 4.513796384395813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868144', 'n_tokens_mistral': 2230, 'n_tokens_neox': 1986, 'n_words': 376}