<commit_before><?php
/**
 * PHP Menu Builder
 * 
 * @author   <NAME> <<EMAIL>>
 * @license  http://opensource.org/licenses/MIT
 * @package  php-menu
 */

namespace anlutro\Menu\Nodes;

use anlutro\Menu\Util\StringUtils;

/**
 * A menu item.
 */
abstract class AbstractNode
{
	/**
	 * The title of the item.
	 *
	 * @var string
	 */
	protected $title;

	/**
	 * The item's attributes.
	 *
	 * @var array
	 */
	protected $attributes = [];

	/**
	 * The icon associated with the item.
	 *
	 * @var \anlutro\Menu\Icons\IconInterface
	 */
	protected $icon;

	/**
	 * Optional HTML prefix for the node.
	 *
	 * @var string
	 */
	protected $prefix = '';

	/**
	 * Optional HTML suffix for the node.
	 *
	 * @var string
	 */
	protected $suffix = '';

	/**
	 * Array of icon resolvers.
	 *
	 * @var array
	 */
	protected static $iconResolvers = [
		'glyph' => 'anlutro\Menu\Icons\Glyphicon',
		'glyphicon' => 'anlutro\Menu\Icons\Glyphicon',
		'fa-icon' => 'anlutro\Menu\Icons\FontAwesomeIcon',
		'fa-stack' => 'anlutro\Menu\Icons\FontAwesomeStack',
	];

	/**
	 * Array keys of attributes that are not HTML attributes.
	 *
	 * @var array
	 */
	protected static $notHtmlAttributes = [
		'icon', 'href', 'suffix', 'prefix', 'glyph',
		'glyphicon', 'fa-icon', 'fa-stack'
	];

	/**
	 * Add an array of icon resolvers.
	 *
	 * @param array $resolvers
	 */
	public static function addIconResolvers(array $resolvers)
	{
		static::$iconResolvers = $resolvers + static::$iconResolvers;
		static::$notHtmlAttributes = array_merge(['icon', 'href', 'suffix', 'prefix'],
			array_keys(static::$iconResolvers));
	}

	/**
	 * @param  array $attributes
	 *
	 * @return array
	 */
	protected function parseAttributes(array $attributes)
	{
		if (isset($attributes['icon']) && $attributes['icon'] instanceof Icons\IconInterface) {
			$this->icon = $attributes['icon'];
		} else {
			/** @var Icons\IconInterface $resolver */
			foreach (static::$iconResolvers as $key => $resolver) {
				if (array_key_exists($key, $attributes)) {
					$this->icon = $resolver::createFromAttribute($attributes[$key]);
					break;
				}
			}
		}

		if (isset($attributes['class'])) {
			if (is_string($attributes['class'])) {<commit_msg>fix incorrect instanceof<commit_after><?php
/**
 * PHP Menu Builder
 * 
 * @author   <NAME> <<EMAIL>>
 * @license  http://opensource.org/licenses/MIT
 * @package  php-menu
 */

namespace anlutro\Menu\Nodes;

use anlutro\Menu\Util\StringUtils;
use anlutro\Menu\Icons\IconInterface;

/**
 * A menu item.
 */
abstract class AbstractNode
{
	/**
	 * The title of the item.
	 *
	 * @var string
	 */
	protected $title;

	/**
	 * The item's attributes.
	 *
	 * @var array
	 */
	protected $attributes = [];

	/**
	 * The icon associated with the item.
	 *
	 * @var IconInterface
	 */
	protected $icon;

	/**
	 * Optional HTML prefix for the node.
	 *
	 * @var string
	 */
	protected $prefix = '';

	/**
	 * Optional HTML suffix for the node.
	 *
	 * @var string
	 */
	protected $suffix = '';

	/**
	 * Array of icon resolvers.
	 *
	 * @var array
	 */
	protected static $iconResolvers = [
		'glyph' => 'anlutro\Menu\Icons\Glyphicon',
		'glyphicon' => 'anlutro\Menu\Icons\Glyphicon',
		'fa-icon' => 'anlutro\Menu\Icons\FontAwesomeIcon',
		'fa-stack' => 'anlutro\Menu\Icons\FontAwesomeStack',
	];

	/**
	 * Array keys of attributes that are not HTML attributes.
	 *
	 * @var array
	 */
	protected static $notHtmlAttributes = [
		'icon', 'href', 'suffix', 'prefix', 'glyph',
		'glyphicon', 'fa-icon', 'fa-stack'
	];

	/**
	 * Add an array of icon resolvers.
	 *
	 * @param array $resolvers
	 */
	public static function addIconResolvers(array $resolvers)
	{
		static::$iconResolvers = $resolvers + static::$iconResolvers;
		static::$notHtmlAttributes = array_merge(['icon', 'href', 'suffix', 'prefix'],
			array_keys(static::$iconResolvers));
	}

	/**
	 * @param  array $attributes
	 *
	 * @return array
	 */
	protected function parseAttributes(array $attributes)
	{
		if (isset($attributes['icon']) && $attributes['icon'] instanceof IconInterface) {
			$this->icon = $attributes['icon'];
		} else {
			/** @var IconInterface $resolver */
			foreach (static::$iconResolvers as $key => $resolver) {
				if (array_key_exists($key, $attributes)) {
					$this->icon = $resolver::createFromAttribute($attributes[$key]);
					break;
				}
			}
		}

		if (isset($attributes['class'])) {
			if (is_string($attributes['class'])) {
{'fraction_non_alphanumeric': 0.1714805549238117, 'fraction_numerical': 0.0, 'mean_word_length': 3.337278106508876, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '1522897', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1454, 'n_words': 332}