public function execute(InputInterface $input, OutputInterface $output)
 {
     $session = $this->get('phpcr.session');
     $path = $input->getArgument('path');
     $currentNode = $session->getNodeByPathOrIdentifier($path);
     $workspace = $session->getWorkspace();
     $namespaceRegistry = $workspace->getNamespaceRegistry();
     $nodeType = $currentNode->getDefinition();
     $cndWriter = new CndWriter($namespaceRegistry);
     $out = $cndWriter->writeString(array($nodeType));
     $output->writeln(sprintf('<comment>%s</comment>', $out));
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $session = $this->get('phpcr.session');
     $nodeTypeName = $input->getArgument('nodeTypeName');
     $workspace = $session->getWorkspace();
     $namespaceRegistry = $workspace->getNamespaceRegistry();
     $nodeTypeManager = $workspace->getNodeTypeManager();
     try {
         $nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
     } catch (NoSuchNodeTypeException $e) {
         throw new \Exception(sprintf('The node type "%s" does not exist', $nodeTypeName));
     }
     $cndWriter = new CndWriter($namespaceRegistry);
     $out = $cndWriter->writeString([$nodeType]);
     $output->writeln(sprintf('<comment>%s</comment>', $out));
 }
    /**
     * the "worst case" example from http://jackrabbit.apache.org/node-type-notation.html.
     */
    public function testWorstCaseExample()
    {
        $cnd = <<<EOT
<ns='http://namespace.com/ns'>
<ex='http://namespace.com/example'>
[ns:NodeType] > ns:ParentType1, ns:ParentType2
orderable mixin query
- ex:property (String)
= 'default1', 'default2'
mandatory autocreated protected multiple VERSION
< 'constraint1', 'constraint2'
+ ns:node (ns:reqType1, ns:reqType2)
= ns:defaultType
mandatory autocreated protected VERSION

EOT;
        /** @var $workspace WorkspaceInterface */
        $workspace = $this->session->getWorkspace();
        $ntm = $workspace->getNodeTypeManager();
        $tpl = $ntm->createNodeTypeTemplate();
        $tpl->setName('ns:NodeType');
        $tpl->setMixin(true);
        $tpl->setDeclaredSuperTypeNames(array('ns:ParentType1', 'ns:ParentType2'));
        $tpl->setOrderableChildNodes(true);
        $prop = $ntm->createPropertyDefinitionTemplate();
        $prop->setName('ex:property');
        $prop->setRequiredType(PropertyType::STRING);
        $prop->setDefaultValues(array('default1', 'default2'));
        $prop->setMandatory(true);
        $prop->setAutoCreated(true);
        $prop->setProtected(true);
        $prop->setMultiple(true);
        $prop->setOnParentVersion(OnParentVersionAction::VERSION);
        $prop->setValueConstraints(array('constraint1', 'constraint2'));
        $prop->setFullTextSearchable(true);
        $prop->setQueryOrderable(true);
        $tpl->getPropertyDefinitionTemplates()->append($prop);
        $child = $ntm->createNodeDefinitionTemplate();
        $child->setName('ns:node');
        $child->setRequiredPrimaryTypeNames(array('ns:reqType1', 'ns:reqType2'));
        $child->setDefaultPrimaryTypeName('ns:defaultType');
        $child->setMandatory(true);
        $child->setAutoCreated(true);
        $child->setProtected(true);
        $child->setOnParentVersion(OnParentVersionAction::VERSION);
        $tpl->getNodeDefinitionTemplates()->append($child);
        $ns = $this->getMock('PHPCR\\Tests\\PhpcrUtils\\MockNamespaceRegistry');
        $ns->expects($this->any())->method('getUri')->will($this->returnCallback(function ($prefix) {
            switch ($prefix) {
                case 'ns':
                    return 'http://namespace.com/ns';
                case 'ex':
                    return 'http://namespace.com/example';
                default:
                    throw new \Exception($prefix);
            }
        }));
        $cndWriter = new CndWriter($ns);
        $res = $cndWriter->writeString(array($tpl));
        $this->assertEquals($cnd, $res);
    }
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $session = $this->get('phpcr.session');
        $editor = $this->get('helper.editor');
        $dialog = $this->get('helper.question');
        $nodeTypeName = $input->getArgument('nodeTypeName');
        $workspace = $session->getWorkspace();
        $namespaceRegistry = $workspace->getNamespaceRegistry();
        $nodeTypeManager = $workspace->getNodeTypeManager();
        try {
            $nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
            $cndWriter = new CndWriter($namespaceRegistry);
            $out = $cndWriter->writeString([$nodeType]);
            $message = null;
        } catch (NoSuchNodeTypeException $e) {
            $parts = explode(':', $nodeTypeName);
            if (count($parts) != 2) {
                throw new \InvalidArgumentException('Node type names must be prefixed with a namespace, e.g. ns:foobar');
            }
            list($namespace, $name) = $parts;
            $uri = $session->getNamespaceURI($namespace);
            // so we will create one ..
            $out = <<<EOT
<{$namespace} ='{$uri}'>
[{$namespace}:{$name}] > nt:unstructured

EOT;
            $message = <<<EOT
Creating a new node type: {$nodeTypeName}
EOT;
        }
        $valid = false;
        $prefix = '# ';
        do {
            $res = $editor->fromStringWithMessage($out, $message);
            if (empty($res)) {
                $output->writeln('<info>Editor emptied the CND file, doing nothing. Use node-type:delete to remove node types.</info>');
                return 0;
            }
            try {
                $cndParser = new CndParser($nodeTypeManager);
                $namespacesAndNodeTypes = $cndParser->parseString($res);
                foreach ($namespacesAndNodeTypes['nodeTypes'] as $nodeType) {
                    $nodeTypeManager->registerNodeType($nodeType, true);
                }
                $valid = true;
            } catch (\Exception $e) {
                $output->writeln('<error>' . $e->getMessage() . '</error>');
                $tryAgain = false;
                if (false === $input->getOption('no-interaction')) {
                    $tryAgain = $dialog->ask($input, $output, new ConfirmationQuestion('Do you want to try again? (y/n)'));
                }
                if (false === $tryAgain) {
                    return 1;
                }
                $message = 'The following errors were encountered (all lines starting with ' . $prefix . ' will be ignored):';
                $message .= PHP_EOL;
                $message .= PHP_EOL;
                $message .= $e->getMessage();
                $out = $res;
            }
        } while (false === $valid);
    }
Beispiel #5
0
 /**
  * Register node types with the backend.
  *
  * This is only a proxy to the transport
  *
  * @param array   $types       an array of NodeTypeDefinitions
  * @param boolean $allowUpdate whether to fail if node already exists or to
  *      update it
  *
  * @return bool true on success
  */
 public function registerNodeTypes($types, $allowUpdate)
 {
     if ($this->transport instanceof NodeTypeManagementInterface) {
         return $this->transport->registerNodeTypes($types, $allowUpdate);
     }
     if ($this->transport instanceof NodeTypeCndManagementInterface) {
         $writer = new CndWriter($this->session->getWorkspace()->getNamespaceRegistry());
         return $this->transport->registerNodeTypesCnd($writer->writeString($types), $allowUpdate);
     }
     throw new UnsupportedRepositoryOperationException('Transport does not support registering node types');
 }