本文整理汇总了PHP中TheSeer\fDOM\fDOMDocument类的典型用法代码示例。如果您正苦于以下问题:PHP fDOMDocument类的具体用法?PHP fDOMDocument怎么用?PHP fDOMDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fDOMDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: generate
public function generate()
{
$document = new fDOMDocument();
// summary
$root = $document->createElement('phpact');
$root->setAttribute('project', $this->summary->getProjectName());
$root->setAttribute('base', $this->summary->getBaseVersion());
$root->setAttribute('challenger', $this->summary->getChallengerVersion());
$root->setAttribute('date', date('c', $this->summary->getTime()));
$root->setAttribute('signature', strip_tags($this->summary->getSignature()));
// difference list
$grouped = $this->groupDifferences($this->differences, Difference::UNIT_NAME);
foreach ($grouped as $unitName => $differences) {
/* @var $differences \RenanBr\PhpAct\Difference\DifferenceCollection */
$family = $differences->current()->getTag(Difference::UNIT_FAMILY);
$unitElement = $root->createElement($family);
$unitElement->setAttribute('name', $unitName);
$this->append($unitElement, 'constant', $differences, Difference::CONSTANT_NAME);
$this->append($unitElement, 'member', $differences, Difference::MEMBER_NAME);
$this->append($unitElement, 'method', $differences, Difference::METHOD_NAME);
$root->appendChild($unitElement);
}
$document->appendChild($root);
$document->preserveWhiteSpace = false;
$document->formatOutput = true;
return $document->saveXML();
}
示例3: getUnitByName
public function getUnitByName($name)
{
$parts = explode('\\', $name);
$local = array_pop($parts);
$namespace = join('\\', $parts);
$indexNode = $this->index->queryOne(sprintf('//phpdox:namespace[@name="%s"]/*[@name="%s"]', $namespace, $local));
if (!$indexNode) {
throw new DependencyException(sprintf("Unit '%s' not found", $name), DependencyException::UnitNotFound);
}
$dom = new fDOMDocument();
$dom->load($this->baseDir . '/' . $indexNode->getAttribute('xml'));
switch ($indexNode->localName) {
case 'interface':
$unit = new InterfaceObject();
$unit->import($dom);
$this->project->addInterface($unit);
break;
case 'trait':
$unit = new TraitObject();
$unit->import($dom);
$this->project->addTrait($unit);
break;
case 'class':
$unit = new ClassObject();
$unit->import($dom);
$this->project->addClass($unit);
break;
default:
throw new DependencyException(sprintf("Invalid unit type '%s'", $indexNode->localName), DependencyException::InvalidUnitType);
}
return $unit;
}
示例4: getUnitByName
public function getUnitByName($name)
{
$parts = explode('\\', $name);
$local = array_pop($parts);
$namespace = join('\\', $parts);
$indexNode = $this->index->queryOne(sprintf('//phpdox:namespace[@name="%s"]/*[@name="%s"]', $namespace, $local));
if (!$indexNode) {
return;
}
$dom = new fDOMDocument();
$dom->load($this->baseDir . '/' . $indexNode->getAttribute('xml'));
switch ($indexNode->localName) {
case 'interface':
$unit = new InterfaceObject();
$unit->import($dom);
$this->project->addInterface($unit);
break;
case 'trait':
$unit = new TraitObject();
$unit->import($dom);
$this->project->addTrait($unit);
break;
case 'class':
$unit = new ClassObject();
$unit->import($dom);
$this->project->addClass($unit);
break;
}
return $unit;
}
示例5: 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, '');
}
示例6: init
private function init($cfgName)
{
$this->version = new Version('0.0');
$this->fileInfo = new FileInfo($this->baseDir . $cfgName . '.xml');
$this->cfgDom = new fDOMDocument();
$this->cfgDom->load($this->fileInfo->getPathname());
$this->cfgDom->registerNamespace('cfg', 'http://xml.phpdox.net/config');
$this->config = new GlobalConfig($this->version, new FileInfo('/tmp'), $this->cfgDom, $this->fileInfo);
}
示例7: renderStripped
/**
* @return string
*/
public function renderStripped()
{
$dom = new fDOMDocument();
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML(preg_replace("/\\s{2,}/u", " ", $this->render()));
foreach ($dom->query('//comment()') as $c) {
$c->parentNode->removeChild($c);
}
$dom->formatOutput = TRUE;
return $dom->saveXML();
}
示例8: loadDocument
protected function loadDocument($dir)
{
$path = $dir . '/' . $this->getNode()->getAttribute('xml');
if (!isset($this->dom[$path])) {
$classDom = new fDOMDocument();
$classDom->load($path);
$classDom->registerNamespace('phpdox', 'http://xml.phpdox.net/src');
$this->dom[$path] = $classDom;
}
return $this->dom[$path];
}
示例9: asDom
public function asDom(\TheSeer\fDOM\fDOMDocument $ctx)
{
$node = $ctx->createElementNS('http://xml.phpdox.net/src', 'invalid');
$node->setAttribute('annotation', $this->name);
foreach ($this->attributes as $attribute => $value) {
$node->setAttribute($attribute, $value);
}
if ($this->body !== null && $this->body !== '') {
$node->appendChild($ctx->createTextnode($this->body));
}
return $node;
}
示例10: loadXML
private function loadXML($fname)
{
try {
if (!file_exists($fname)) {
throw new EnricherException(sprintf('PHPLoc xml file "%s" not found.', $fname), EnricherException::LoadError);
}
$this->dom = new fDOMDocument();
$this->dom->load($fname);
} catch (fDOMException $e) {
throw new EnricherException('Parsing PHPLoc xml file failed: ' . $e->getMessage(), EnricherException::LoadError);
}
}
示例11: processFinding
protected function processFinding(fDOMDocument $dom, $ref, \DOMElement $finding)
{
$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));
}
}
示例12: asDom
public function asDom(\TheSeer\fDOM\fDOMDocument $ctx)
{
$node = $ctx->createElementNS('http://xml.phpdox.net/src#', strtolower($this->name));
foreach ($this->attributes as $attribute => $value) {
$node->setAttribute($attribute, $value);
}
if ($this->body !== null && $this->body !== '') {
$parser = $this->factory->getInstanceFor('InlineProcessor', $ctx);
$node->appendChild($parser->transformToDom($this->body));
}
return $node;
}
示例13: testParse
/**
* @ covers TheSeer\phpDox\DocBlock\Parser::__construct
* @ covers TheSeer\phpDox\DocBlock\Parser::parse
*
* @dataProvider docblockSources
*/
public function testParse($src)
{
$expected = new fDOMDocument();
$dir = __DIR__ . '/../../data/docbock/';
$block = file_get_contents($dir . $src);
$expected->load($dir . $src . '.xml');
$factory = new Factory();
$parser = new Parser($factory);
$result = $parser->parse($block, array());
$this->assertInstanceOf('TheSeer\\phpDox\\DocBlock\\DocBlock', $result);
$dom = new fDOMDocument();
$dom->appendChild($result->asDom($dom));
$this->assertEquals($expected->documentElement, $dom->documentElement);
}
示例14: asDom
/**
* @param \TheSeer\fDOM\fDOMDocument $doc
* @return \TheSeer\fDOM\fDOMElement
*/
public function asDom(\TheSeer\fDOM\fDOMDocument $doc)
{
$node = $doc->createElementNS('http://xml.phpdox.net/src#', 'docblock');
// add lines and such?
foreach ($this->elements as $element) {
if (is_array($element)) {
foreach ($element as $el) {
$node->appendChild($el->asDom($doc));
}
continue;
}
$node->appendChild($element->asDom($doc));
}
return $node;
}
示例15: testQueryReturnsNodeFromClonedDocument
/**
* https://github.com/theseer/fDOMDocument/issues/15
*/
public function testQueryReturnsNodeFromClonedDocument()
{
$this->dom->loadXML('<?xml version="1.0" ?><test />');
$clone = clone $this->dom;
$node = $clone->queryOne('/test');
$this->assertNotSame($this->dom->documentElement, $node);
}