本文整理汇总了PHP中TheSeer\fDOM\fDOMDocument::queryOne方法的典型用法代码示例。如果您正苦于以下问题:PHP fDOMDocument::queryOne方法的具体用法?PHP fDOMDocument::queryOne怎么用?PHP fDOMDocument::queryOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TheSeer\fDOM\fDOMDocument
的用法示例。
在下文中一共展示了fDOMDocument::queryOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isSilentMode
/**
* @return bool
*/
public function isSilentMode()
{
$root = $this->cfg->queryOne('/cfg:phpdox');
if (!$root instanceof \DomNode) {
return false;
}
return $root->getAttribute('silent', 'false') === 'true';
}
示例2: getCacheDom
private function getCacheDom()
{
if ($this->cacheDom === NULL) {
$this->cacheDom = new fDOMDocument();
$cacheFile = $this->config->getLogfilePath();
if (file_exists($cacheFile)) {
$this->cacheDom->load($cacheFile);
$sha1 = $this->cacheDom->documentElement->getAttribute('sha1');
$cwd = getcwd();
chdir($this->config->getSourceDirectory());
exec($this->config->getGitBinary() . ' diff --name-only ' . $sha1, $files, $rc);
foreach ($files as $file) {
$fields = array('path' => dirname($file), 'file' => basename($file));
$query = $this->cacheDom->prepareQuery('//*[@path = :path and @file = :file]', $fields);
$node = $this->cacheDom->queryOne($query);
if (!$node) {
continue;
}
$node->parentNode->removeChild($node);
}
chdir($cwd);
} else {
$this->cacheDom->loadXML('<?xml version="1.0" ?><gitlog xmlns="' . self::GITNS . '" />');
$this->cacheDom->documentElement->setAttribute('sha1', $this->commitSha1);
}
}
return $this->cacheDom;
}
示例3: import
public function import(fDOMDocument $dom) {
$dom->registerNamespace('phpdox', 'http://xml.phpdox.net/src#');
$dir = $dom->queryOne('/phpdox:source/phpdox:dir');
if (!$dir) {
return;
}
$this->importDirNode($dir, '');
}
示例4: getMethod
private function getMethod($name)
{
$ctx = $this->dom->queryOne(sprintf('phpdox:method[@name="%s"]', $name));
if (!$ctx) {
throw new UnitObjectException(sprintf('Method "%s" not found', $name), UnitObjectException::NoSuchMethod);
}
return new MethodObject($this, $ctx);
}
示例5: getProjectConfig
public function getProjectConfig($project)
{
$filter = is_int($project) ? $project : "@name = '{$project}'";
$ctx = $this->cfg->queryOne("//cfg:project[{$filter}]");
if (!$ctx) {
throw new ConfigException("Project '{$project}' not found in configuration xml file", ConfigException::ProjectNotFound);
}
return new ProjectConfig($this->runResolver($ctx));
}
示例6: processFindings
private function processFindings(fDOMDocument $dom, \DOMNodeList $findings)
{
foreach ($findings as $finding) {
/** @var fDOMElement $finding */
$line = $finding->getAttribute('line');
$ref = $dom->queryOne(sprintf('//phpdox:*/*[@line = %d or (@start <= %d and @end >= %d)]', $line, $line, $line));
if (!$ref) {
// One src file may contain multiple classes/traits/interfaces, so the
// finding might not apply to the current object since findings are based on filenames
// but we have individual objects - so we just ignore the finding for this context
continue;
}
$this->processFinding($dom, $ref, $finding);
}
}
示例7: processViolations
private function processViolations(fDOMDocument $dom, \DOMNodeList $violations)
{
foreach ($violations as $violation) {
/** @var fDOMElement $violation */
$line = $violation->getAttribute('beginline');
$ref = $dom->queryOne(sprintf('//phpdox:*/*[@line = %d or (@start <= %d and @end >= %d)]', $line, $line, $line));
if (!$ref) {
// One src file may contain multiple classes/traits/interfaces, so the
// finding might not apply to the current object since violations are based on filenames
// but we have individual objects - so we just ignore the finding for this context
continue;
}
$enrichment = $this->getEnrichtmentContainer($ref, 'pmd');
$enrichViolation = $dom->createElementNS(self::XMLNS, 'violation');
$enrichment->appendChild($enrichViolation);
$enrichViolation->setAttribute('message', trim($violation->nodeValue));
foreach ($violation->attributes as $attr) {
$enrichViolation->setAttributeNode($dom->importNode($attr, true));
}
}
}
示例8: processFindings
private function processFindings(fDOMDocument $dom, \DOMNodeList $findings)
{
foreach ($findings as $finding) {
/** @var fDOMElement $finding */
$line = $finding->getAttribute('line');
$ref = $dom->queryOne(sprintf('//phpdox:*/*[@line = %d or (@start <= %d and @end >= %d)]', $line, $line, $line));
if (!$ref) {
// One src file may contain multiple classes/traits/interfaces, so the
// finding might not apply to the current object since findings are based on filenames
// but we have individual objects - so we just ignore the finding for this context
continue;
}
$enrichment = $this->getEnrichtmentContainer($ref, 'checkstyle');
$enrichFinding = $dom->createElementNS(self::XMLNS, $finding->getAttribute('severity', 'error'));
$enrichment->appendChild($enrichFinding);
foreach ($finding->attributes as $attr) {
if ($attr->localName == 'severity') {
continue;
}
$enrichFinding->setAttributeNode($dom->importNode($attr, true));
}
}
}
示例9: getInterfaceClassName
/**
* @return string
*/
public function getInterfaceClassName()
{
return $this->dom->queryOne('configuration/interface')->getAttribute('name');
}
示例10: loadCoverageInformation
/**
* @param fDOMDocument $dom
*
* @return fDOMDocument
*
* @throws EnricherException
* @throws PHPUnitEnricherException
*/
private function loadCoverageInformation(fDOMDocument $dom)
{
$fileNode = $dom->queryOne('//phpdox:file');
if (!$fileNode) {
throw new PHPUnitEnricherException('No file header in event dom');
}
$fileInfo = new FileInfo($fileNode->getAttribute('path'));
$srcDir = $this->getSourceDirectory();
$paths = explode('/', (string) $fileInfo->getRelative($srcDir));
$file = $fileNode->getAttribute('file');
$paths = array_slice($paths, 1);
$query = sprintf('//pu:project/pu:directory[@name = "%s"]', $srcDir->getRealPath());
foreach ($paths as $path) {
$query .= sprintf('/pu:directory[@name = "%s"]', $path);
}
$query .= sprintf('/pu:file[@name = "%s"]', $file);
$phpunitFileNode = $this->index->queryOne($query);
if (!$phpunitFileNode) {
throw new PHPUnitEnricherException('No coverage information for file');
}
$refDom = $this->loadXML($phpunitFileNode->getAttribute('href'));
return $refDom;
}
示例11: isSilentMode
/**
* @return bool
*/
public function isSilentMode()
{
$root = $this->cfg->queryOne('/cfg:phpdox');
return $root->getAttribute('silent', 'false') === 'true';
}
示例12: createPhpDoxConfig
/**
* @param string[] $units
* @param string[] $visibilities
* @return fDOMDocument
*/
private function createPhpDoxConfig(array $units, array $visibilities)
{
$dom = new fDOMDocument();
$dom->loadXML($this->factory->getConfigSkeleton()->renderStripped());
$dom->registerNamespace('config', ConfigLoader::XMLNS);
// set up silent
$silent = $this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL ? 'true' : 'false';
$dom->queryOne('//config:phpdox')->setAttribute('silent', $silent);
// set up directories
$projectNode = $dom->queryOne('//config:project');
$projectNode->setAttribute('source', $this->sourceDirectory);
$projectNode->setAttribute('workdir', $this->buildDirectory);
// inject flag to avoid unecessary processing according to the visibility filter
if (1 === count($visibilities) && in_array('public', $visibilities)) {
$collectorNode = $dom->queryOne('//config:collector');
$projectNode->setAttribute('publiconly', 'true');
}
// remove current masks
$query = "//config:collector/*[name()='include' or name()='exclude']";
foreach ($dom->query($query) as $mask) {
$mask->parentNode->removeChild($mask);
}
// append files to be parsed
$collector = $dom->queryOne('//config:collector');
foreach ($units as $unitFile) {
$include = $dom->createElement('include');
$include->setAttribute('mask', $unitFile);
$collector->appendChild($include);
}
return $dom;
}
示例13: findAffectedUnits
/**
* @param $fname
*
* @return array
*/
private function findAffectedUnits($fname)
{
$affected = array();
$dom = new fDOMDocument();
$dom->load($this->xmlDir . '/' . $fname);
$dom->registerNamespace('phpdox', 'http://xml.phpdox.net/src#');
$extends = $dom->queryOne('//phpdox:extends');
if ($extends instanceof fDOMElement) {
try {
$affected[$extends->getAttribute('full')] = $this->getUnitByName($extends->getAttribute('full'));
} catch (ProjectException $e) {
}
}
$implements = $dom->query('//phpdox:implements');
foreach ($implements as $implement) {
try {
$affected[$implement->getAttribute('full')] = $this->getUnitByName($implement->getAttribute('full'));
} catch (ProjectException $e) {
}
}
return $affected;
}
示例14: processUnit
private function processUnit(fDOMDocument $unit, fDOMDocument $coverage) {
$enrichment = $this->getEnrichtmentContainer($unit->documentElement, 'phpunit');
$className = $unit->documentElement->getAttribute('name');
$classNamespace = $unit->documentElement->getAttribute('namespace');
$classNode = $coverage->queryOne(
sprintf('//pu:class[@name = "%s" and pu:namespace[@name = "%s"]]', $className, $classNamespace)
);
if (!$classNode) {
// This class seems to be newer than the last phpunit run
return;
}
$coverageTarget = $enrichment->appendElementNS(self::XMLNS, 'coverage');
foreach(array('executable','executed', 'crap') as $attr) {
$coverageTarget->appendChild(
$coverageTarget->ownerDocument->importNode($classNode->getAttributeNode($attr))
);
}
$result = array(
'PASSED' => 0,
'SKIPPED' => 0,
'INCOMPLETE' => 0,
'FAILURE' => 0,
'ERROR' => 0,
'RISKY' => 0
);
$methods = $unit->query('/phpdox:*/phpdox:constructor|/phpdox:*/phpdox:destructor|/phpdox:*/phpdox:method');
$xp = $this->index->getDOMXPath();
foreach($methods as $method) {
$start = $method->getAttribute('start');
$end = $method->getAttribute('end');
$enrichment = $this->getEnrichtmentContainer($method, 'phpunit');
$coverageTarget = $enrichment->appendElementNS(self::XMLNS, 'coverage');
/** @var fDOMElement $coverageMethod */
$coverageMethod = $coverage->queryOne(
sprintf('//pu:method[@start = "%d" and @end = "%d"]', $start, $end)
);
if ($coverageMethod != NULL) {
foreach(array('executable','executed','coverage', 'crap') as $attr) {
$coverageTarget->appendChild(
$coverageTarget->ownerDocument->importNode($coverageMethod->getAttributeNode($attr))
);
}
}
$coveredNodes = $coverage->query(
sprintf('//pu:coverage/pu:line[@nr >= "%d" and @nr <= "%d"]/pu:covered', $start, $end)
);
$seen = array();
foreach($coveredNodes as $coveredNode) {
$by = $coveredNode->getAttribute('by');
if (isset($seen[$by])) {
continue;
}
$seen[$by] = true;
$name = $xp->prepare(':name', array('name' => $by));
$test = $coverageTarget->appendChild(
$unit->importNode(
$this->index->queryOne(
sprintf('//pu:tests/pu:test[@name = %s]', $name)
)
)
);
$result[$test->getAttribute('status')]++;
}
}
if (!isset($this->results[$classNamespace])) {
$this->results[$classNamespace] = array();
$this->coverage[$classNamespace] = array();
}
$this->results[$classNamespace][$className] = $result;
$this->coverage[$classNamespace][$className] = $coverageTarget->cloneNode(false);
}
示例15: testThatTwoNodesAreIdentifiedAsBeingInTheSameDocument
/**
* @covers \TheSeer\fDOM\fDOMDocument::queryOne
*/
public function testThatTwoNodesAreIdentifiedAsBeingInTheSameDocument()
{
$this->dom->loadXML('<?xml version="1.0" ?><root><node /></root>');
$node = $this->dom->queryOne('//node');
$this->assertTrue($this->dom->inSameDocument($node));
}