|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPCR\Shell\Console\Command; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Command\Command; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Output\OutputInterface; |
| 8 | +use Symfony\Component\Console\Input\InputArgument; |
| 9 | +use PHPCR\Util\CND\Writer\CndWriter; |
| 10 | +use PHPCR\NodeType\NoSuchNodeTypeException; |
| 11 | +use PHPCR\Util\CND\Parser\CndParser; |
| 12 | +use PHPCR\NamespaceException; |
| 13 | +use Symfony\Component\Console\Input\InputOption; |
| 14 | + |
| 15 | +class NodeMixinAddCommand extends Command |
| 16 | +{ |
| 17 | + protected function configure() |
| 18 | + { |
| 19 | + $this->setName('node:mixin:add'); |
| 20 | + $this->setDescription('Add the named mixin to the current node'); |
| 21 | + $this->addArgument('mixinName', null, InputArgument::REQUIRED, null, 'The name of the mixin node type to be added'); |
| 22 | + $this->setHelp(<<<HERE |
| 23 | +Adds the mixin node type named <info>mixinName</info> to this node. |
| 24 | +
|
| 25 | +If this node is already of type <info>mixinName</info> (either due to a previously |
| 26 | +added mixin or due to its primary type, through inheritance) then this |
| 27 | +method has no effect. Otherwise <info>mixinName</info> is added to this node's |
| 28 | +jcr:mixinTypes property. |
| 29 | +
|
| 30 | +Semantically, the new node type may take effect immediately, on dispatch |
| 31 | +or on persist. The behavior is adopted must be the same as the behavior |
| 32 | +adopted for NodeInterface::setPrimaryType() and the behavior that |
| 33 | +occurs when a node is first created. |
| 34 | +
|
| 35 | +A ConstraintViolationException is thrown either immediately or on save |
| 36 | +if a conflict with another assigned mixin or the primary node type |
| 37 | +occurs or for an implementation-specific reason. Implementations may |
| 38 | +differ on when this validation is done. |
| 39 | +
|
| 40 | +In some implementations it may only be possible to add mixin types |
| 41 | +before a a node is persisted for the first time. In such cases any |
| 42 | +later calls to <info>addMixin</info> will throw a ConstraintViolationException |
| 43 | +either immediately, on dispatch or on persist. |
| 44 | +HERE |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public function execute(InputInterface $input, OutputInterface $output) |
| 49 | + { |
| 50 | + $session = $this->getHelper('phpcr')->getSession(); |
| 51 | + $mixinName = $input->getArgument('mixinName'); |
| 52 | + $currentNode = $session->getCurrentNode(); |
| 53 | + $currentNode->addMixin($mixinName); |
| 54 | + } |
| 55 | +} |
| 56 | + |
0 commit comments