protected static function pruneMatrix(array &$matrix)
	{
		$usableTags = ['*root*' => 1];

		// Start from the root and keep digging
		$parentTags = $usableTags;
		do
		{
			$nextTags = [];
			foreach (array_keys($parentTags) as $tagName)
			{
				// Accumulate the names of tags that are allowed as children of our parent tags
				$nextTags += array_filter($matrix[$tagName]['allowedChildren']);
			}

			// Keep only the tags that are in the matrix but aren't in the usable array yet, then
			// add them to the array
			$parentTags  = array_diff_key($nextTags, $usableTags);
			$parentTags  = array_intersect_key($parentTags, $matrix);
			$usableTags += $parentTags;
		}
		while (!empty($parentTags));

		// Remove unusable tags from the matrix
		$matrix = array_intersect_key($matrix, $usableTags);
		unset($usableTags['*root*']);

		// Remove unusable tags from the targets
		foreach ($matrix as $tagName => &$tagMatrix)
		{
			$tagMatrix['allowedChildren']
				= array_intersect_key($tagMatrix['allowedChildren'], $usableTags);

			$tagMatrix['allowedDescendants']
				= array_intersect_key($tagMatrix['allowedDescendants'], $usableTags);
		}
		unset($tagMatrix);
	}
protected static function pruneMatrix(array &$matrix)
	{
		$usableTags = ['*root*' => 1];

		// Start from the root and keep digging
		$parentTags = $usableTags;
		do
		{
			$nextTags = [];
			foreach (array_keys($parentTags) as $tagName)
			{
				// Accumulate the names of tags that are allowed as children of our parent tags
				$nextTags += array_filter($matrix[$tagName]['allowedChildren']);
			}

			// Keep only the tags that are in the matrix but aren't in the usable array yet, then
			// add them to the array
			$parentTags  = array_diff_key($nextTags, $usableTags);
			$parentTags  = array_intersect_key($parentTags, $matrix);
			$usableTags += $parentTags;
		}
		while (!empty($parentTags));

		// Remove unusable tags from the matrix
		$matrix = array_intersect_key($matrix, $usableTags);
		unset($usableTags['*root*']);

		// Remove unusable tags from the targets
		foreach ($matrix as $tagName => &$tagMatrix)
		{
			$tagMatrix['allowedChildren']
				= array_intersect_key($tagMatrix['allowedChildren'], $usableTags);

			$tagMatrix['allowedDescendants']
				= array_intersect_key($tagMatrix['allowedDescendants'], $usableTags);
		}
		unset($tagMatrix);
	}
protected static function pruneMatrix ( array & $ matrix ) { $ usableTags = [ '*root*' => 1 ] ; // Start from the root and keep digging $ parentTags = $ usableTags ; do { $ nextTags = [ ] ; foreach ( array_keys ( $ parentTags ) as $ tagName ) { // Accumulate the names of tags that are allowed as children of our parent tags $ nextTags += array_filter ( $ matrix [ $ tagName ] [ 'allowedChildren' ] ) ; } // Keep only the tags that are in the matrix but aren't in the usable array yet, then // add them to the array $ parentTags = array_diff_key ( $ nextTags , $ usableTags ) ; $ parentTags = array_intersect_key ( $ parentTags , $ matrix ) ; $ usableTags += $ parentTags ; } while ( ! empty ( $ parentTags ) ) ; // Remove unusable tags from the matrix $ matrix = array_intersect_key ( $ matrix , $ usableTags ) ; unset ( $ usableTags [ '*root*' ] ) ; // Remove unusable tags from the targets foreach ( $ matrix as $ tagName => & $ tagMatrix ) { $ tagMatrix [ 'allowedChildren' ] = array_intersect_key ( $ tagMatrix [ 'allowedChildren' ] , $ usableTags ) ; $ tagMatrix [ 'allowedDescendants' ] = array_intersect_key ( $ tagMatrix [ 'allowedDescendants' ] , $ usableTags ) ; } unset ( $ tagMatrix ) ; }
Remove unusable tags from the matrix

@param  array &$matrix
@return void
Remove unusable tags from the matrix