/** * Annotate the document with matched attributes against each configuration * element that matches the given context and environment. * * @param AgaviXmlConfigDomDocument The document to act upon. * @param string The environment name. * @param string The context name. * * @author David Zülke <*****@*****.**> * @author Noah Fontes <*****@*****.**> * @since 1.0.0 */ public static function match(AgaviXmlConfigDomDocument $document, $environment, $context) { if ($document->isAgaviConfiguration()) { // it's an agavi config, so we need to set "matched" flags on all <configuration> elements where "context" and "environment" attributes match the values below $testAttributes = array('context' => $context, 'environment' => $environment); foreach ($document->getConfigurationElements() as $configuration) { // assume that the element counts as matched, in case it doesn't have "context" or "environment" attributes $matched = true; foreach ($testAttributes as $attributeName => $attributeValue) { if ($configuration->hasAttribute($attributeName)) { $matched = $matched && self::testPattern($configuration->getAttribute($attributeName), $attributeValue); } } if ($matched) { // if all was fine, we set the attribute. the element will then be kept in the merged result doc later $configuration->setAttributeNS(self::NAMESPACE_AGAVI_ANNOTATIONS_LATEST, 'agavi_annotations_latest:matched', 'true'); } } } }