Validate the signature values
@param VariableSet $variableSet
@param XmlNamespaceManager $nsMgr
@return bool
358472
public function validate( $variableSet, $nsMgr )
	{
		if ( ! $this->name )
		{
			\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name is not defined', array(
				'error' => 'xbrlve:noNameForCustomFunction'
			) );
			return false;
		}

		$qname = $this->getQName();

		if ( $qname->namespaceURI == \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_FUNCTION_INSTANCE ] )
		{
			\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function name has a namespace reserved for functions in the function registry (xfi)', array(
				'signature' => $qname->prefix . ":" . $qname->localName,
				'error' => 'xbrlve:noProhibitedNamespaceForCustomFunction'
			) );
		}

		if ( $this->output )
		{
			$outputQName = qname( $this->output, $nsMgr->getNamespaces() );
			if ( $outputQName && ! \XBRL::startsWith( $this->output, "xs:" ) && $outputQName->namespaceURI != \XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] )
			{
				\XBRL_Log::getInstance()->formula_validation( 'Custom function', 'Custom function outut type is not valid', array(
					'type' => $this->output ? $this->output : "missing",
					'error' => 'xbrlve:invalidDatatypeInCustomFunctionSignature'
				) );
			}
		}

		return true;
	}
955387
private function parseSignature(DOMElement $xml) : void
    {
        /** @var \DOMAttr[] $signatureMethod */
        $signatureMethod = Utils::xpQuery($xml, './ds:Signature/ds:SignedInfo/ds:SignatureMethod/@Algorithm');

        /* Validate the signature element of the message. */
        $sig = Utils::validateElement($xml);
        if ($sig !== false) {
            $this->wasSignedAtConstruction = true;
            $this->setCertificates($sig['Certificates']);
            $this->setSignatureData($sig);
            $this->setSignatureMethod($signatureMethod[0]->value);
        }
    }
891922
public function validate( $variableSet, $nsMgr )
	{
		if ( $this->qnameExpressions )
		{
			foreach ( $this->qnameExpressions as $qnameExpression )
			{
				try
				{
					$xpath2Expression = XPath2Expression::Compile( $qnameExpression, $nsMgr );
					if ( parent::checkForCoverXFIFunctionUse( $qnameExpression, $xpath2Expression ) )
					{
						return false;
					}

					$this->qnameXPath2Expressions[] = $xpath2Expression;
				}
				catch ( XPath2Exception $ex )
				{
					\XBRL_Log::getInstance()->formula_validation( "Concept name filter", "Failed to compile qname expression",
						array(
							'qname expression' => $qnameExpression,
							'error' => $ex instanceof XPath2Exception ? ( $ex->ErrorCode == 'XPST0017' ? "xbrlve:noCustomFunctionSignature" : $ex->ErrorCode ) : get_class( $ex ),
							'reason' => $ex->getMessage()
						)
					);
				}
				catch ( \Exception $ex )
				{
					// BMS 2018-03-27 Test 21201 V-02 requires that this compile failure return xbrlve:noCustomFunctionSignature
					//				  because the custom function my-own:ending-balance does not exist
					\XBRL_Log::getInstance()->formula_validation( "Concept name filter", "Failed to compile qname expression",
						array(
							'qname expression' => $qnameExpression,
							'error' => $ex instanceof XPath2Exception ? ( $ex->ErrorCode == 'XPST0017' ? "err:XPST0017" : $ex->ErrorCode ) : get_class( $ex ),
							'reason' => $ex->getMessage()
						)
					);
				}
			}
		}

		return true;
	}
1197653
private function validateFilters( $taxonomy, $arcRole, &$variable, $variableSet )
	{
		// Find all filter arcs related to this variable
		$variableFilterArcs = $taxonomy->getGenericArc( $arcRole, $variable->extendedLinkRoleUri, $variable->label, $variable->path, null, $variable->linkbase );

		if ( ! $variableFilterArcs ) return true;

		// Find the filter resources
		$filterResources = array();

		// BMS 2018-06-29 Changed this function so the arc for loop is on the outside so it can take advantage of indexing of the resource collections
		// $result = $taxonomy->getGenericResource( 'filter', null, function( $roleUri, $linkbase, $variableSetName, $index, $resource ) use( &$filterResources, $variableFilterArcs )
		// {
		// 	foreach ( $variableFilterArcs as $arcIndex => $variableFilterArc )
		// 	{
		// 		if ( $roleUri == $variableFilterArc['toRoleUri'] )
		// 		if ( $variableSetName == $variableFilterArc['label'] )
		// 		{
		// 			$resource['linkbase'] = $linkbase;
		// 			if ( $variableFilterArc['attributes'] )
		// 			{
		// 				foreach ( $variableFilterArc['attributes'] as $name => $attribute )
		// 				{
		// 					// BMS 2018-04-09 Test candidates changed.
		// 					$value = $attribute['type'] == "xs:boolean"
		// 						? (bool)$attribute['value']
		// 						: $attribute['value'];
		// 					$resource[ $name ] = $value;
		// 				}
		// 			}
		// 			$filterResources[ $variableSetName ][] = $resource;
		// 		}
		// 	}
		// 	return true;
		// } );

		foreach ( $variableFilterArcs as $arcIndex => $variableFilterArc )
		{
			if ( $variable->path == $variableFilterArc['frompath'] )
			$result = $taxonomy->getGenericResource( 'filter', null, function( $roleUri, $linkbase, $variableSetName, $index, $resource ) use( &$filterResources, $variableFilterArc )
			{
				// Don't believe this is necessary as $variableSetName is $variableFilterArc['label']
				// if ( $variableSetName = $variableFilterArc['label'] )
				if ( $resource['path'] != $variableFilterArc['topath'] /* || $linkbase != $variableFilterArc['linkbase'] */ ) return true;

				$resource['linkbase'] = $linkbase;
				if ( $variableFilterArc['attributes'] )
				{
					foreach ( $variableFilterArc['attributes'] as $name => $attribute )
					{
						// BMS 2018-04-09 Test candidates changed.
						$value = $attribute['type'] == "xs:boolean"
							? (bool)$attribute['value']
							: $attribute['value'];
						$resource[ $name ] = $value;
					}
				}
				$filterResources[ $variableSetName ][] = $resource;

				return true;
			}, $variableFilterArc['toRoleUri'], $variableFilterArc['to'], $variableFilterArc['tolinkbase'] );
		}

		foreach ( $filterResources as $variableFilterLabel => $filterResourceSet )
		{
			foreach ( $filterResourceSet as $filterResource )
			{
				// if ( $variable->path != $filterResource['path'] ) continue;

				// If this is a group filter make sure the arc is not covering
				if ( $arcRole == XBRL_Constants::$arcRoleVariableSetFilter )
				{
					if ( isset( $filterResource['cover'] ) && $filterResource['cover'] )
					{
						$this->log->formula_validation( "Filter", "Group filters MUST not cover",
							array(
								'filter type' => $filterResource['filterType'],
								'label' => $filterResource['label'],
								'error' => 'lyquidity:variableSetFilterCovered',
							)
						);
					}
				}

				// Create the filter instance
				$filterClassName = '\\XBRL\\Formulas\\Resources\\' .
					Formulas::$formulaElements[ $filterResource['filterType'] ]['part'] .
					( isset( Formulas::$formulaElements[ $filterResource['filterType'] ]['className'] )
						? Formulas::$formulaElements[ $filterResource['filterType'] ]['className']
						: ucfirst( $filterResource['filterType'] )
					);

				if ( is_null( $filterClassName ) )
				{
					$this->log->formula_validation( "Filter", "Invalid filter type",
						array(
							'Filter type' => $resource['filterType'],
						)
					);
					return false;
				}

				if ( $variableSet->aspectModel == "non-dimensional" &&
					 in_array( $filterResource['filterType'], array( 'explicitDimension', 'typedDimension' ) )
				)
				{
					$this->log->formula_validation( "Filter", "Dimension filters not allowed when using the non-dimensional aspect model",
						array(
							'aspect model' => $variableSet->aspectModel,
							'filter type' => $filterResource['filterType'],
							'label' => $filterResource['label'],
							'error' => 'xbrlve:filterAspectModelMismatch',
						)
					);
				}
				else if ( $variableSet->aspectModel == "dimensional" &&
					      in_array( $filterResource['filterType'], array( 'scenario', 'segment' ) )
				)
				{
					$this->log->formula_validation( "Filter", "Non-dimensional filters not allowed when using the dimensional aspect model",
						array(
							'aspect model' => $variableSet->aspectModel,
							'filter type' => $filterResource['filterType'],
							'label' => $filterResource['label'],
							'error' => 'xbrlve:filterAspectModelMismatch',
						)
					);
				}

				/** @var \XBRL\Formulas\Resources\Filters\Filter $filter */
				$filter = $filterClassName::fromArray( $filterResource );

				if ( ! $filter->validate( $variableSet, $this->nsMgr ) )
				{
					return false;
				}

				// If this is a group filter then make sure the filter does not reference any
				if ( $arcRole == XBRL_Constants::$arcRoleVariableSetFilter )
				{
					// There should be no variable refs
					$refs = $filter->getVariableRefs();
					if ( $refs )
					{
						foreach ( $refs as $refQName )
						{
							if ( isset( $variableSet->variablesByQName[ $refQName->clarkNotation() ] ) )
							{
								$this->log->formula_validation( "Group Filter", "Variable references are not allowed from group filters",
									array(
										'reference' => $refQName->clarkNotation(),
										'filter' => $filter->label,
										'variable set' => $variableSet->label,
										'error' => 'xbrlve:factVariableReferenceNotAllowed',
									)
								);
							}
						}
					}
				}

				$variable->addFilter( $filter );
			}
		}

		return true;

		// // Return applying any filters
		// return $arcRole == XBRL_Constants::$arcRoleVariableSetFilter
		// 	? true
		// 	: $this->validateAspectCovers( $taxonomy, $variable );
	}
1080149
public static function validateClass($name, $namespace = null)
    {
        $name = self::validateNamingConvention($name);

        $prefix = !empty($namespace) ? $namespace . '\\' : '';

        $name = self::validateUnique($name, function ($name) use ($prefix) {
                // Use reflection to get access to private isKeyword method.
                // @todo Remove this when we stop supporting PHP 5.3.
                $isKeywordMethod = new \ReflectionMethod(__CLASS__, 'isKeyword');
                $isKeywordMethod->setAccessible(true);
                $isKeyword = $isKeywordMethod->invoke(null, $name);
             return !$isKeyword &&
                !interface_exists($prefix . $name) &&
                !class_exists($prefix . $name);
        }, self::NAME_SUFFIX);

        return $name;
    }
636201
public function toQuery( $variableSet, $factVariableBinding )
	{
		$test = $this->test ? $this->test : 'true()';
		// $filter = "(if (fn:QName('http://www.xbrl.org/2003/instance','tuple') = xfi:concept-substitutions(fn:node-name(.))) then (false()) else (xfi:period(.)[$test]))";
		$filter = "(xfi:period(.)[$test])";
		return $filter;
	}
783559
public function validate( $variableSet, $nsMgr )
	{
			try
		{
			if ( $this->scheme )
			{
				if ( ! $this->schemaXPath2Expression )
				{
					$this->schemaXPath2Expression = XPath2Expression::Compile( $this->scheme, $nsMgr );
				}
			}
		}
		catch ( \Exception $ex )
		{
			\XBRL_Log::getInstance()->formula_validation( "Specific scheme filter", "Failed to compile scheme expression",
				array(
					'schema expression' => $this->scheme,
					'error' => $ex instanceof XPath2Exception ? $ex->ErrorCode : get_class( $ex ),
					'reason' => $ex->getMessage()
				)
			);
			return false;
		}

		return parent::validate( $variableSet, $nsMgr );
	}
1332183
public function getAspectsCovered( $variableSet, $factVariableBinding )
	{
		if ( $this->dimension )
		{
			// $qname = qname( $this->dimension );
			return array( "{{$this->dimension['namespace']}}{$this->dimension['name']}" );
		}
		else if ( $this->dimensionXPath2Expression )
		{
			/**
			 * @var XPath2Item $result
			 */
			$result = $this->evaluateXPathExpression( $variableSet, $this->dimensionXPath2Expression );
			return array( (string)$result->getValue() );
		}
		else if ( $this->dimensionExpression )
		{
			/**
			 * @var XPath2Item $result
			 */
			$result = $this->evaluateXPath( $variableSet, $this->dimensionExpression );
			return array( (string)$result->getValue() );
		}

		return array( ASPECT_DIMENSIONS );
	}
1169111
public T validateNamespace(String prefix, String namespaceUri) {
        xmlMessageValidationContext.getControlNamespaces().put(prefix, namespaceUri);
        return self;
    }
101398
public function toQuery( $variableSet, $factVariableBinding )
	{
		// return "(true())";

		$clauses = array();

		$dimensionClause = "";
		if ( $this->dimension )
		{
			// $qname = qname( $this->dimension );
			$dimensionClause = "fn:QName('{$this->dimension['namespace']}','{$this->dimension['name']}')";
		}
		else if ( $this->dimensionExpression )
		{
			$dimensionClause = $this->dimensionExpression;
		}
		else
		{
			return "false()";
		}

		if ( $this->test )
		{
			return "( xfi:fact-has-typed-dimension(.,$dimensionClause) and xfi:fact-typed-dimension-value(.,$dimensionClause)[{$this->test}] )";
		}
		else
		{
			return "xfi:fact-has-typed-dimension(.,$dimensionClause)";
		}
	}
400439
public function Filter( $facts, $variableSet )
	{
		// Look for the variable
		$vars = $variableSet->getBindingsAsVars();
		$clark = str_replace( "{}", "", "{{$this->variable['namespace']}}{$this->variable['name']}" );
		if ( ! isset( $vars[ $clark ] ) )
		{
			// Should probably throw some kind of error here
			throw XPath2Exception::withErrorCodeAndParam( "XPST0008", Resources::XPST0008, $clark );
		}

		/**
		 * @var \DOMNode[] $candidates
		 */
		$candidate = null;
		$var = $vars[ $clark ];
		if ( $var instanceof XPath2NodeIterator )
		{
			$node = reset( $var->ToList() );
			if ( is_null( $node ) )
			{
				throw XPath2Exception::withErrorCodeAndParam( "XPST0008", Resources::XPST0008, $clark );
			}

			$candidate = $node->getUnderlyingObject();
		}
		else
		{
			$candidate = $var->getUnderlyingObject();
		}

		$matched = array();
		$notMatched = array();

		$candidateParent = $candidate->parentNode;

		// The fact can be an
		foreach ( $facts as $fact )
		{
			$node = $fact->getUnderlyingObject();
			$factParent = $node->parentNode;

			if ( $candidateParent->isSameNode( $factParent ) )
			{
				$matched[] = $fact->CloneInstance();
			}
			else
			{
				$notMatched[] = $fact->CloneInstance();
			}
		}

		return DocumentOrderNodeIterator::fromItemset( $this->complement ? $notMatched : $matched );

		return $facts;
	}
882409
public function loadAndVerifyWithKeySet(string $token, JWKSet $keyset, ?int &$signature, ?string $payload = null): JWS
    {
        try {
            $jws = $this->serializerManager->unserialize($token);
            $nbSignatures = $jws->countSignatures();
            for ($i = 0; $i < $nbSignatures; ++$i) {
                if ($this->processSignature($jws, $keyset, $i, $payload)) {
                    $signature = $i;

                    return $jws;
                }
            }
        } catch (\Exception $e) {
            // Nothing to do. Exception thrown just after
        }

        throw new \Exception('Unable to load and verify the token.');
    }
1160455
public function Filter( $facts, $variableSet )
	{
		// If the filter is being used in a boolean filter or there is a qname expresssion then return the input facts
		if ( $this->inBoolean || $this->qnameExpressions ) return $facts;

		$matched = array();
		$notMatched = array();

		foreach ( $facts as /** @var XPathNavigator $fact */ $fact )
		{
			if ( $this->testParent( $fact ) )
			{
				$matched[] = $fact->CloneInstance();
			}
			else
			{
				$notMatched[] = $fact->CloneInstance();
			}
		}

		return DocumentOrderNodeIterator::fromItemset( $this->complement ? $notMatched : $matched );
	}
1092594
public static function validateConstructorArgs($name, $globalThreshold, $metric,
                                                 $metricFactor, $componentThreshold,
                                                 $components, $validMetrics)
  {
    if (!self::validateName($name))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $name: please supply a valid non-empty string.');

    if (!self::validateGlobalThreshold($globalThreshold))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $globalThreshold: please supply a positive integer.');

    if (!self::validateMetric($metric, $validMetrics))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $metric. Valid choices are "sec", "min", "hrs".');

    if (!self::validateMetricFactor($metricFactor))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $metricFactor: please supply a positive integer.');

    if (!self::validateComponentThreshold($componentThreshold))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $componentThreshold: please supply a positive integer or null.');

    if (!self::compareThresholds($componentThreshold, $globalThreshold))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $componentThreshold: $componentThreshold must be lower than $globalThreshold.');

    if (!self::validateComponents($components))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $components: $components must be an array.');

    if (!self::validateComponentsName($components))
      throw new \Franzip\Throttler\Exceptions\InvalidArgumentException('Invalid Throttler $components: $components entries must be non empty strings.');
    }
762900
public function validate( $variableSet, $nsMgr )
	{
		try
		{
			if ( isset( $this->select ) && ! empty( $this->select ) )
			{
				$expression = XPath2Expression::Compile( $this->select, $nsMgr );
				$this->selectXPath2expression = $expression;
			}

			return true;
		}
		catch ( \Exception $ex )
		{
			\XBRL_Log::getInstance()->formula_validation( "General variable", "Failed to compile select expression",
				array(
					'select' => $this->select,
					'error' => $ex instanceof XPath2Exception ? $ex->ErrorCode : get_class( $ex ),
					'reason' => $ex->getMessage()
				)
			);
		}
	}
550206
private function checkNamespaceResources(array $namespaceResources): bool
    {
        $isValid = true;
        foreach ($namespaceResources as $namespace => $resources) {
            $isValid = $isValid === true &&
                empty($namespace) === false &&
                is_array($resources) === true && $this->checkResources($resources);
        }

        return $isValid;
    }
1046966
public function toQuery( $variableSet, $factVariableBinding )
	{
		$variable = new QName( $this->variable['originalPrefix'], $this->variable['namespace'], $this->variable['name'] );

		// Look for this variable among the bindings.  If it exists
		// and has a fallback value the the query is just false()
		if ( isset( $variableSet->factVariableBindings[ $variable->clarkNotation() ] ) )
		{
			/**
			 * @var FactVariableBinding $binding
			 */
			$binding = $variableSet->factVariableBindings[ $variable->clarkNotation() ];
			if ( $binding->isFallback )
			{
				return "false()";
			}
		}
		else // BMS 201803-07 What else could it be? if ( isset( $variableSet->generalVariableBindings[ $variable->clarkNotation() ] ) )
		{
			return "false()";
		}

		$this->allowAspectsCovered = true;
		$result = parent::toQuery( $variableSet, $factVariableBinding );
		// Once the filter has been created the class should return the filters applied
		// $this->allowAspectsCovered = false;

		return $result;
	}