/** * This method returns an array of nodes matching the specified id. * * @access protected * @param \SimpleXMLElement $root a reference to the root node * @param string $id the object's id * @return array an array of nodes with the specified * id * @throws Throwable\InvalidArgument\Exception indicates that an argument is invalid * * @see http://stackoverflow.com/questions/1257867/regular-expressions-and-xpath-query */ protected function find(\SimpleXMLElement $root, $id) { if (!Spring\Data\XML\Syntax::isId($id)) { throw new Throwable\InvalidArgument\Exception('Invalid argument detected (id: :id).', array(':id' => $id)); } $root->registerXPathNamespace('spring', Spring\Data\XML::NAMESPACE_URI); $nodes = $root->xpath("/spring:objects/spring:object[@id='{$id}' or contains(@name,'{$id}')]"); $nodes = array_filter($nodes, function (\SimpleXMLElement &$node) use($id) { $attributes = $node->attributes(); return isset($attributes['id']) && Spring\Data\XML::valueOf($attributes['id']) == $id || isset($attributes['name']) && in_array($id, preg_split('/(,|;|\\s)+/', Spring\Data\XML::valueOf($attributes['name']))); }); return $nodes; }