<commit_before><?php

namespace TinyAuth\View\Helper;

use Cake\Core\Exception\Exception;
use Cake\View\Helper;
use Cake\View\View;
use RuntimeException;
use TinyAuth\Auth\AclTrait;
use TinyAuth\Auth\AuthUserTrait;

/**
 * @property \Cake\View\Helper\HtmlHelper $Html
 * @property \Cake\View\Helper\FormHelper $Form
 */
class AuthUserHelper extends Helper {

	use AclTrait, AuthUserTrait;

	/**
	 * @var array
	 */
	public $helpers = ['Html', 'Form'];

	/**
	 * @param \Cake\View\View $View The View this helper is being attached to.
	 * @param array $config Configuration settings for the helper.
	 */
	public function __construct(View $View, array $config = []) {
		$config = $this->_prepareConfig($config);

		parent::__construct($View, $config);
	}

	/**
	 * @param array $url
	 * @return bool
	 * @throws \Cake\Core\Exception\Exception
	 */
	public function hasAccess(array $url) {
		$params = $this->request->getAttribute('params');
		$url += [
			'prefix' => !empty($params['prefix']) ? $params['prefix'] : null,
			'plugin' => !empty($params['plugin']) ? $params['plugin'] : null,
			'controller' => $params['controller'],
			'action' => 'index',
		];

		if (!isset($this->_View->viewVars['_authUser'])) {
			throw new Exception('Variable _authUser containing the user data needs to be passed down. The TinyAuth.Auth component does it automatically, if loaded.');
		}
		if (empty($this->_View->viewVars['_authUser'])) {
			return false;
		}<commit_msg>Add note about hasAccess().<commit_after><?php

namespace TinyAuth\View\Helper;

use Cake\Core\Exception\Exception;
use Cake\View\Helper;
use Cake\View\View;
use RuntimeException;
use TinyAuth\Auth\AclTrait;
use TinyAuth\Auth\AuthUserTrait;

/**
 * @property \Cake\View\Helper\HtmlHelper $Html
 * @property \Cake\View\Helper\FormHelper $Form
 */
class AuthUserHelper extends Helper {

	use AclTrait, AuthUserTrait;

	/**
	 * @var array
	 */
	public $helpers = ['Html', 'Form'];

	/**
	 * @param \Cake\View\View $View The View this helper is being attached to.
	 * @param array $config Configuration settings for the helper.
	 */
	public function __construct(View $View, array $config = []) {
		$config = $this->_prepareConfig($config);

		parent::__construct($View, $config);
	}

	/**
	 * This is only for usage with already logged in persons as this uses the ACL (not allow) data.
	 *
	 * If you need to support also public methods (via Controller or allow INI etc), you could make a fake
	 * "public" role that copies over the public actions into such a dummy role.
	 * This is a workaround for the time being until we can find a cleaner solution.
	 *
	 * @param array $url
	 * @return bool
	 * @throws \Cake\Core\Exception\Exception
	 */
	public function hasAccess(array $url) {
		$params = $this->request->getAttribute('params');
		$url += [
			'prefix' => !empty($params['prefix']) ? $params['prefix'] : null,
			'plugin' => !empty($params['plugin']) ? $params['plugin'] : null,
			'controller' => $params['controller'],
			'action' => 'index',
		];

		if (!isset($this->_View->viewVars['_authUser'])) {
			throw new Exception('Variable _authUser containing the user data needs to be passed down. The TinyAuth.Auth component does it automatically, if loaded.');
		}
		if (empty($this->_View->viewVars['_authUser'])) {
			return false;
		}
{'fraction_non_alphanumeric': 0.15289131092945807, 'fraction_numerical': 0.0, 'mean_word_length': 4.122480620155039, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4720063', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1005, 'n_words': 300}