Skip to content

small cleanup #167

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

Merged
merged 2 commits into from
Jan 20, 2017
Merged
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
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
Expand All @@ -15,7 +13,7 @@ sudo: false

matrix:
include:
- php: 5.3
- php: 5.6
env: PACKAGE_VERSION=low

before_script:
Expand Down
41 changes: 24 additions & 17 deletions bin/phpcr
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use PHPCR\Util\Console\Command;

if (!class_exists('\Symfony\Component\Console\Application')) {
if (is_file(__DIR__.'/../vendor/autoload.php')) {
require __DIR__.'/../vendor/autoload.php';
Expand All @@ -19,7 +23,7 @@ $helperSet = null;
if (file_exists($configFile)) {
if (!is_readable($configFile)) {
trigger_error(
'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR
"Configuration file [$configFile] does not have read permission.", E_USER_ERROR
);
}

Expand All @@ -33,29 +37,32 @@ if (file_exists($configFile)) {
}
} else {
trigger_error(
'Configuration file [' . $configFile . '] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration', E_USER_ERROR
"Configuration file [$configFile] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration", E_USER_ERROR
);
}

$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
$helperSet = $helperSet ?: new HelperSet();

$cli = new Application('PHPCR Command Line Interface', '0.1');

$cli = new \Symfony\Component\Console\Application('PHPCR Command Line Interface', '0.1');
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);

$cli->addCommands(array(
new \PHPCR\Util\Console\Command\NodeDumpCommand(),
new \PHPCR\Util\Console\Command\NodeMoveCommand(),
new \PHPCR\Util\Console\Command\NodeRemoveCommand(),
new \PHPCR\Util\Console\Command\NodeTouchCommand(),
new \PHPCR\Util\Console\Command\NodesUpdateCommand(),
new \PHPCR\Util\Console\Command\NodeTypeListCommand(),
new \PHPCR\Util\Console\Command\NodeTypeRegisterCommand(),
new \PHPCR\Util\Console\Command\WorkspaceCreateCommand(),
new \PHPCR\Util\Console\Command\WorkspaceDeleteCommand(),
new \PHPCR\Util\Console\Command\WorkspaceExportCommand(),
new \PHPCR\Util\Console\Command\WorkspaceImportCommand(),
new \PHPCR\Util\Console\Command\WorkspacePurgeCommand(),
new \PHPCR\Util\Console\Command\WorkspaceQueryCommand(),
new Command\NodeDumpCommand(),
new Command\NodeMoveCommand(),
new Command\NodeRemoveCommand(),
new Command\NodeTouchCommand(),
new Command\NodesUpdateCommand(),
new Command\NodeTypeListCommand(),
new Command\NodeTypeRegisterCommand(),
new Command\WorkspaceCreateCommand(),
new Command\WorkspaceDeleteCommand(),
new Command\WorkspaceExportCommand(),
new Command\WorkspaceImportCommand(),
new Command\WorkspacePurgeCommand(),
new Command\WorkspaceQueryCommand(),
));

$cli->run();

7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
}
],
"require": {
"php": "^5.3.3|7.0.x|7.1.x",
"php": "^5.6|7.0.x|7.1.x",
"phpcr/phpcr": "~2.1.0",
"symfony/console": "~2.3|~3.0"
},
"require-dev": {
"ramsey/uuid": "^3.5"
},
"suggest": {
"ramsey/uuid": "A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."
},
Expand All @@ -45,7 +48,7 @@
"bin": ["bin/phpcr"],
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
"dev-master": "1.3-dev"
}
}
}
17 changes: 10 additions & 7 deletions src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPCR\Util\Console\Command;

use InvalidArgumentException;
use PHPCR\RepositoryException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCR\SessionInterface;
Expand Down Expand Up @@ -62,15 +63,15 @@ protected function configure()

/**
* {@inheritDoc}
*
* @throws InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$definitions = $input->getArgument('cnd-file');

if (count($definitions) == 0) {
throw new \InvalidArgumentException(
'At least one definition (i.e. file or folder) must be specified'
);
throw new InvalidArgumentException('At least one definition (i.e. file or folder) must be specified');
}

$allowUpdate = $input->getOption('allow-update');
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param string $cnd the compact namespace and node type definition in string form
* @param bool $allowUpdate whether to allow updating existing node types.
*
* @throws \PHPCR\RepositoryException on other errors
* @throws RepositoryException on other errors
*/
protected function updateFromCnd(OutputInterface $output, SessionInterface $session, $cnd, $allowUpdate)
{
Expand All @@ -124,6 +125,8 @@ protected function updateFromCnd(OutputInterface $output, SessionInterface $sess
* @param array $definitions List of files of folders
*
* @return array Array of full paths to all the type node definition files.
*
* @throws InvalidArgumentException
*/
protected function getFilePaths($definitions)
{
Expand All @@ -141,7 +144,7 @@ protected function getFilePaths($definitions)
$filePath = sprintf('%s/%s', $definition, $file);

if (!is_readable($filePath)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf("Node type definition file '<info>%s</info>' does not have read permissions.", $file)
);
}
Expand All @@ -150,7 +153,7 @@ protected function getFilePaths($definitions)
}
} else {
if (!file_exists($definition)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf("Node type definition file / folder '<info>%s</info>' does not exist.", $definition)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$session->importXml(
$session->importXML(
$parentPath,
$filename,
ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW
Expand Down
3 changes: 2 additions & 1 deletion src/PHPCR/Util/Console/Helper/PhpcrHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPCR\Util\Console\Helper;

use Exception;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Helper;
use PHPCR\NodeInterface;
Expand Down Expand Up @@ -177,7 +178,7 @@ protected function validateQueryLanguage($language)
}
}

throw new \Exception(sprintf(
throw new Exception(sprintf(
'Query language "%s" not supported, available query languages: %s',
$language, implode(',', $langs)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPCR\Util\Console\Helper\TreeDumper;

use Exception;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCR\ItemInterface;
use PHPCR\NodeInterface;
Expand Down Expand Up @@ -51,14 +52,16 @@ public function setShowFullPath($showFullPath)
* Print information about the visited node.
*
* @param ItemInterface $item the node to visit
*
* @throws Exception
*/
public function visit(ItemInterface $item)
{
if (! $item instanceof NodeInterface) {
throw new \Exception("Internal error: did not expect to visit a non-node object: $item");
throw new Exception("Internal error: did not expect to visit a non-node object: $item");
}

if ($item->getDepth() == 0) {
if ($item->getDepth() === 0) {
$name = 'ROOT';
} elseif ($this->showFullPath) {
$name = $item->getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPCR\Util\Console\Helper\TreeDumper;

use Exception;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCR\ItemInterface;
use PHPCR\PropertyInterface;
Expand Down Expand Up @@ -30,7 +31,7 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor
* Instantiate property visitor
*
* @param OutputInterface $output
* @param int $maxLineLength
* @param array $options
*/
public function __construct(OutputInterface $output, $options = array())
{
Expand All @@ -49,11 +50,13 @@ public function __construct(OutputInterface $output, $options = array())
* Print information about this property
*
* @param ItemInterface $item the property to visit
*
* @throws Exception
*/
public function visit(ItemInterface $item)
{
if (! $item instanceof PropertyInterface) {
throw new \Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item));
throw new Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item));
}

$value = $item->getString();
Expand Down
3 changes: 3 additions & 0 deletions src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPCR\Util\Console\Helper\TreeDumper;

use PHPCR\ItemInterface;
use PHPCR\RepositoryException;
use PHPCR\Util\TreeWalkerFilterInterface;
use PHPCR\Util\NodeHelper;

Expand All @@ -19,6 +20,8 @@ class SystemNodeFilter implements TreeWalkerFilterInterface
* @param ItemInterface $item
*
* @return boolean
*
* @throws RepositoryException
*/
public function mustVisit(ItemInterface $item)
{
Expand Down
32 changes: 27 additions & 5 deletions src/PHPCR/Util/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace PHPCR\Util;

use InvalidArgumentException;
use PHPCR\ItemExistsException;
use PHPCR\ItemInterface;
use PHPCR\Lock\LockException;
use PHPCR\NodeInterface;
use PHPCR\NodeType\ConstraintViolationException;
use PHPCR\PathNotFoundException;
use PHPCR\PropertyInterface;
use PHPCR\SessionInterface;
use PHPCR\RepositoryException;
use PHPCR\ItemNotFoundException;
use PHPCR\NamespaceException;
use PHPCR\Version\VersionException;

/**
* Helper with only static methods to work with PHPCR nodes
Expand All @@ -35,6 +41,14 @@ private function __construct()
* @param string $path full path, like /content/jobs/data
*
* @return NodeInterface the last node of the path, i.e. data
*
* @throws InvalidArgumentException
* @throws RepositoryException
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws LockException
* @throws ConstraintViolationException
* @throws VersionException
*/
public static function createPath(SessionInterface $session, $path)
{
Expand Down Expand Up @@ -65,6 +79,8 @@ public static function createPath(SessionInterface $session, $path)
* @param SessionInterface $session the session to remove all children of
* the root node
*
* @throws RepositoryException
*
* @see isSystemItem
*/
public static function purgeWorkspace(SessionInterface $session)
Expand All @@ -91,6 +107,8 @@ public static function purgeWorkspace(SessionInterface $session)
*
* @param SessionInterface $session
*
* @throws RepositoryException
*
* @deprecated
*/
public static function deleteAllNodes(SessionInterface $session)
Expand All @@ -106,6 +124,8 @@ public static function deleteAllNodes(SessionInterface $session)
* @param ItemInterface $item
*
* @return boolean true if $item is a system item, false otherwise
*
* @throws RepositoryException
*/
public static function isSystemItem(ItemInterface $item)
{
Expand Down Expand Up @@ -133,6 +153,8 @@ public static function isSystemItem(ItemInterface $item)
* @throws NamespaceException if a namespace prefix is provided in the
* $nameHint which does not exist and this implementation performs
* this validation immediately.
*
* @throws RepositoryException
*/
public static function generateAutoNodeName($usedNames, $namespaces, $defaultNamespace, $nameHint = null)
{
Expand All @@ -150,15 +172,15 @@ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNam
* be in the empty namespace and the local part of the name will be
* generated by the repository.
*/
if ('' === $nameHint || ':' == $nameHint || '{}' == $nameHint) {
if ('' === $nameHint || ':' === $nameHint || '{}' === $nameHint) {
return self::generateWithPrefix($usedNames, '');
}

/*
* "<i>somePrefix</i>:" where <i>somePrefix</i> is a syntactically
* valid namespace prefix
*/
if (':' == $nameHint[strlen($nameHint)-1]
if (':' === $nameHint[strlen($nameHint)-1]
&& substr_count($nameHint, ':') === 1
&& preg_match('#^[a-zA-Z][a-zA-Z0-9]*:$#', $nameHint)
) {
Expand All @@ -175,8 +197,8 @@ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNam
* namespace URI
*/
if (strlen($nameHint) > 2
&& '{' == $nameHint[0]
&& '}' == $nameHint[strlen($nameHint)-1]
&& '{' === $nameHint[0]
&& '}' === $nameHint[strlen($nameHint)-1]
&& filter_var(substr($nameHint, 1, -1), FILTER_VALIDATE_URL)
) {
$prefix = array_search(substr($nameHint, 1, -1), $namespaces);
Expand Down Expand Up @@ -328,7 +350,7 @@ public static function calculateOrderBefore(array $old, array $new)
*
* @return array The updated $nodes array with new order
*
* @throws \PHPCR\ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes
* @throws ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes
*/
public static function orderBeforeArray($name, $destination, $list)
{
Expand Down
Loading