Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show node contents in XML format #56

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
"jackalope/jackalope": "~1.1",
"phpcr/phpcr": "~2.1",
"phpcr/phpcr-utils": "~1.2",
"symfony/finder": "~2.3"
"symfony/finder": "~2.3",
"kukulich/fshl": "dev-symfony-console-formatter"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dantleech/fshl"
}
],
"minimum-stability": "dev",
"require-dev": {
"mockery/mockery": "0.9",
Expand Down
25 changes: 25 additions & 0 deletions features/phpcr_node_show.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Show the current nodes shared set
In order to show the shared set to which the current node belongs
As a user that is logged into the shell
I need to be able to do that

Background:
Given that I am logged in as "testuser"
And the "cms.xml" fixtures are loaded

Scenario: Show the current node
Given the current node is "/foobar"
And I execute the "node:show ." command
Then the command should not fail
And I should see the following:
"""
<?xml version="1.0" encoding="UTF-8"?>
<sv:node xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:ns="http://namespace.com/ns" xmlns:test="http://liip.to/jackalope" xmlns:phpcr="http://www.doctrine-project.org/projects/phpcr_odm" xmlns:dcms="http://dcms.com/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:slinp="asd" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:crx="http://www.day.com/crx/1.0" xmlns:lx="http://flux-cms.org/2.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:dtl="http://www.dantleech.com" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:my_prefix="http://a_new_namespace" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:rep="internal" sv:name="jcr:root">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>rep:root</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">
<sv:value>rep:AccessControllable</sv:value>
</sv:property>
</sv:node>
"""
19 changes: 19 additions & 0 deletions spec/PHPCR/Shell/Console/Helper/ResultFormatterHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,23 @@ function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ResultFormatterHelper');
}

function it_should_indent_a_given_xml_string()
{
$xmlString = <<<EOT
<xml><thisis><foobar></foobar></thisis></xml>
EOT
;

$this->formatXml($xmlString)->shouldReturn(<<<EOT
<?xml version="1.0"?>
<xml>
<thisis>
<foobar/>
</thisis>
</xml>

EOT
);
}
}
15 changes: 15 additions & 0 deletions src/PHPCR/Shell/Console/Application/ShellApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PHPCR\Shell\Transport\TransportRegistry;
use PHPCR\Shell\Config\ProfileLoader;
use PHPCR\Shell\Console\Helper\TableHelper;
use PHPCR\Shell\Console\Helper\SyntaxHighlighterHelper;

/**
* Main application for PHPCRSH
Expand Down Expand Up @@ -132,6 +133,7 @@ private function registerHelpers()
new ResultFormatterHelper(),
new TextHelper(),
new TableHelper(),
new SyntaxHighlighterHelper(),
$phpcrHelper
);

Expand Down Expand Up @@ -173,6 +175,7 @@ private function registerCommands()
$this->add(new CommandPhpcr\WorkspaceListCommand());
$this->add(new CommandPhpcr\NodeCloneCommand());
$this->add(new CommandPhpcr\NodeCopyCommand());
$this->add(new CommandPhpcr\NodeShowCommand());
$this->add(new CommandPhpcr\WorkspaceNamespaceListCommand());
$this->add(new CommandPhpcr\WorkspaceNamespaceRegisterCommand());
$this->add(new CommandPhpcr\WorkspaceNamespaceUnregisterCommand());
Expand Down Expand Up @@ -272,6 +275,18 @@ private function configureFormatter(OutputFormatter $formatter)

$style = new OutputFormatterStyle(null, 'red', array());
$formatter->setStyle('exception', $style);

// syntax highlighting
$colors = array(
'html-tag' => 'magenta',
'html-tagin' => 'yellow',
'html-quote' => null,
);

foreach ($colors as $tag => $color) {
$style = new OutputFormatterStyle($color, null, array());
$formatter->setStyle($tag, $style);
}
}

/**
Expand Down
40 changes: 40 additions & 0 deletions src/PHPCR/Shell/Console/Command/Phpcr/NodeShowCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace PHPCR\Shell\Console\Command\Phpcr;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class NodeShowCommand extends Command
{
protected function configure()
{
$this->setName('node:show');
$this->setDescription('Show a node');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to source node');
$this->setHelp(<<<HERE
HERE
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();
$absPath = $session->getAbsPath($input->getArgument('path'));
$formatter = $this->getHelper('result_formatter');
$highlighter = $this->getHelper('syntax_highlighter');

$skipBinary = true;
$noRecurse = true;

ob_start();
$stream = fopen('php://output', 'w+', false);
$session->exportSystemView($absPath, $stream, $skipBinary, $noRecurse);
$out = ob_get_clean();
fclose($stream);

$output->writeln($highlighter->highlightXml($formatter->formatXml($out)));
}
}
13 changes: 12 additions & 1 deletion src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function getName()
return 'result_formatter';
}


/**
* Return the name of a property from its enumeration (i.e.
* the value of its CONSTANT)
Expand Down Expand Up @@ -171,4 +170,16 @@ public function formatException(\Exception $e)

return sprintf('[%s] %s', get_class($e), $e->getMessage());
}

public function formatXml($xmlString)
{
// format output
$dom = new \DOMDocument('1.0');
$dom->loadXml($xmlString);
$dom->preserveWhitespace = true;
$dom->formatOutput = true;
$out = $dom->saveXml();

return $out;
}
}
20 changes: 20 additions & 0 deletions src/PHPCR/Shell/Console/Helper/SyntaxHighlighterHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PHPCR\Shell\Console\Helper;

use Symfony\Component\Console\Helper\Helper;

class SyntaxHighlighterHelper extends Helper
{
public function getName()
{
return 'syntax_highlighter';
}

public function highlightXml($string)
{
$highlighter = new \FSHL\Highlighter(new \FSHL\Output\SymfonyConsole());
$highlighter->setLexer(new \FSHL\Lexer\Html());
return $highlighter->highlight($string);
}
}