Skip to content

Commit

Permalink
Merge pull request #174 from jackalope/adjust-console-bootstrap-symfo…
Browse files Browse the repository at this point in the history
…ny-3

adjust console init to symfony 3 and general cleanup
  • Loading branch information
dbu authored Dec 30, 2022
2 parents 58d6917 + c278e49 commit f8013c9
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 95 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
Version 1
=========

2.0.0 (unreleased)
------------------

* Renamed cli-config.php.dist to cli-config.dist.php and cleaned up to be better documented.

1.4.4
-----

Expand Down
56 changes: 56 additions & 0 deletions cli-config.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Jackalope\RepositoryFactoryJackrabbit;
use PHPCR\SimpleCredentials;
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
use PHPCR\Util\Console\Helper\PhpcrHelper;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;

/**
* Bootstrapping the repository implementation for the stand-alone cli application.
*
* Copy this file to cli-config.php and adjust the configuration parts to your need.
*/

/*
* Configuration
*/
$workspace = 'default'; // phpcr workspace to use
$user = 'admin'; // jackrabbit username
$pass = 'admin'; // jackrabbit password

function bootstrapJackrabbit()
{
/*
* Additional jackrabbit configuration
*/
$jackrabbitUrl = 'http://127.0.0.1:8080/server';

// bootstrap jackrabbit
return (new RepositoryFactoryJackrabbit())->getRepository([
"jackalope.jackrabbit_uri" => $jackrabbitUrl,
]);
}

/* Only create a session if this is not about the jackrabbit server startup command */
if (!array_key_exists(1, $argv[1])) {
return;
}
if(!in_array($argv[1], ['jackalope:run:jackrabbit', 'list', 'help'], true)) {
$repository = bootstrapJackrabbit();
$credentials = new SimpleCredentials($user, $pass);
$session = $repository->login($credentials, $workspace);

$helperSet = new HelperSet(array(
'phpcr' => new PhpcrHelper($session),
'phpcr_console_dumper' => new PhpcrConsoleDumperHelper(),
));
if (class_exists(QuestionHelper::class)) {
$helperSet->set(new QuestionHelper(), 'question');
} else {
// legacy support for old Symfony versions
$helperSet->set(new DialogHelper(), 'dialog');
}
}
40 changes: 0 additions & 40 deletions cli-config.php.dist

This file was deleted.

26 changes: 9 additions & 17 deletions src/Jackalope/Transport/Jackrabbit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace Jackalope\Transport\Jackrabbit;

use DOMDocument;
use DOMElement;
use DOMXPath;
use InvalidArgumentException;
use Jackalope\FactoryInterface;
use Jackalope\Lock\Lock;
use Jackalope\Node;
Expand All @@ -19,7 +16,6 @@
use Jackalope\Transport\QueryInterface as QueryTransport;
use Jackalope\Transport\VersioningInterface;
use Jackalope\Transport\WritingInterface;
use LogicException;
use PHPCR\CredentialsInterface;
use PHPCR\ItemExistsException;
use PHPCR\ItemNotFoundException;
Expand Down Expand Up @@ -340,7 +336,7 @@ protected function getCurl()
$this->curl = new curl();
} elseif (false === $this->curl) {
// but do not re-connect, rather report the error if trying to access a closed connection
throw new LogicException('Tried to start a request on a closed transport.');
throw new \LogicException('Tried to start a request on a closed transport.');
}

return $this->curl;
Expand Down Expand Up @@ -699,7 +695,7 @@ public function getBinaryStream($path)
*/
private function decodeBinaryDom($xml)
{
$dom = new DOMDocument();
$dom = new \DOMDocument();
if (!$dom->loadXML($xml)) {
throw new RepositoryException("Failed to load xml data:\n\n$xml");
}
Expand Down Expand Up @@ -969,9 +965,9 @@ public function query(Query $query)

$rawData = $request->execute();

$dom = new DOMDocument();
$dom = new \DOMDocument();
$dom->loadXML($rawData);
$domXpath = new DOMXPath($dom);
$domXpath = new \DOMXPath($dom);

$rows = [];
foreach ($domXpath->query('D:response') as $row) {
Expand Down Expand Up @@ -1028,12 +1024,12 @@ public function getSupportedQueryLanguages()
*
* <dcr:value dcr:type="Boolean">false</dcr:value>
*
* @param DOMElement $node a dcr:value xml element
* @param string $attribute the attribute name
* @param \DOMElement $node a dcr:value xml element
* @param string $attribute the attribute name
*
* @return mixed the node value converted to the specified type
*/
private function getDcrValue(DOMElement $node)
private function getDcrValue(\DOMElement $node)
{
$type = $node->getAttribute('dcr:type');
if (PropertyType::TYPENAME_BOOLEAN == $type && 'false' == $node->nodeValue) {
Expand Down Expand Up @@ -1242,10 +1238,6 @@ public function cloneFrom($srcWorkspace, $srcAbsPath, $destAbsPath, $removeExist
*
* Jackrabbit supports them, but jackalope does not.
*
* @param $srcWorkspace
* @param $srcAbsPath
* @param $destAbsPath
*
* @throws \PHPCR\ItemExistsException
*/
protected function checkForExistingNode($srcWorkspace, $srcAbsPath, $destAbsPath)
Expand Down Expand Up @@ -1711,7 +1703,7 @@ public function fetchEventData($date)
$request->addHeader(sprintf('If-None-Match: "%s"', base_convert($date, 10, 16)));
$curl = $request->execute(true);
// create new DOMDocument and load the response text.
$dom = new DOMDocument();
$dom = new \DOMDocument();
$dom->loadXML($curl->getResponse());

$next = base_convert(trim($curl->getHeader('ETag'), '"'), 16, 10);
Expand Down Expand Up @@ -2068,7 +2060,7 @@ protected function getRequiredDomElementByTagNameNS($dom, $namespace, $element,
* @return int the expire timestamp to be used with Lock::setExpireTime,
* that is when this lock expires in seconds since 1970 or null for inifinite
*
* @throws InvalidArgumentException if the timeout value can not be parsed
* @throws \InvalidArgumentException if the timeout value can not be parsed
*/
protected function parseTimeout($timeoutValue)
{
Expand Down
33 changes: 15 additions & 18 deletions src/Jackalope/Transport/Jackrabbit/EventBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace Jackalope\Transport\Jackrabbit;

use ArrayIterator;
use DOMDocument;
use DOMElement;
use DOMNode;
use Jackalope\FactoryInterface;
use Jackalope\Observation\Event;
use Jackalope\Observation\EventFilter;
Expand Down Expand Up @@ -39,7 +36,7 @@ class EventBuffer implements \Iterator
/**
* Buffered events.
*
* @var ArrayIterator
* @var \ArrayIterator
*/
protected $events;

Expand Down Expand Up @@ -163,7 +160,7 @@ protected function fetchNextPage()
*
* @return Event[]
*/
protected function constructEventJournal(DOMDocument $data)
protected function constructEventJournal(\DOMDocument $data)
{
$events = [];
$entries = $data->getElementsByTagName('entry');
Expand All @@ -174,7 +171,7 @@ protected function constructEventJournal(DOMDocument $data)
$events = array_merge($events, $moreEvents);
}

return new ArrayIterator($events);
return new \ArrayIterator($events);
}

/**
Expand All @@ -185,7 +182,7 @@ protected function constructEventJournal(DOMDocument $data)
*
* @return Event[]
*/
protected function extractEvents(DOMElement $entry, $currentUserId)
protected function extractEvents(\DOMElement $entry, $currentUserId)
{
$events = [];
$domEvents = $entry->getElementsByTagName('event');
Expand Down Expand Up @@ -261,7 +258,7 @@ protected function extractEvents(DOMElement $entry, $currentUserId)
*
* @throws RepositoryException
*/
protected function extractUserId(DOMElement $entry)
protected function extractUserId(\DOMElement $entry)
{
$authors = $entry->getElementsByTagName('author');

Expand All @@ -271,7 +268,7 @@ protected function extractUserId(DOMElement $entry)

$userId = null;
foreach ($authors->item(0)->childNodes as $child) {
if ($child instanceof DOMElement) {
if ($child instanceof \DOMElement) {
return $child->nodeValue;
}
}
Expand All @@ -286,7 +283,7 @@ protected function extractUserId(DOMElement $entry)
*
* @throws RepositoryException
*/
protected function extractEventType(DOMElement $event)
protected function extractEventType(\DOMElement $event)
{
$list = $event->getElementsByTagName('eventtype');

Expand All @@ -297,7 +294,7 @@ protected function extractEventType(DOMElement $event)
// Here we cannot simply take the first child as the <eventtype> tag might contain
// text fragments (i.e. newlines) that will be returned as DOMText elements.
foreach ($list->item(0)->childNodes as $el) {
if ($el instanceof DOMElement) {
if ($el instanceof \DOMElement) {
return $this->getEventTypeFromTagName($el->tagName);
}
}
Expand All @@ -308,16 +305,16 @@ protected function extractEventType(DOMElement $event)
/**
* Extract a given DOMElement from the children of another DOMElement.
*
* @param DOMElement $event The DOMElement containing the searched tag
* @param string $tagName The name of the searched tag
* @param string $errorMessage The error message when the tag was not
* found or null if the tag is not required
* @param \DOMElement $event The DOMElement containing the searched tag
* @param string $tagName The name of the searched tag
* @param string $errorMessage The error message when the tag was not
* found or null if the tag is not required
*
* @return DOMNode
* @return \DOMNode
*
* @throws RepositoryException
*/
protected function getDomElement(DOMElement $event, $tagName, $errorMessage = null)
protected function getDomElement(\DOMElement $event, $tagName, $errorMessage = null)
{
$list = $event->getElementsByTagName($tagName);

Expand Down Expand Up @@ -364,7 +361,7 @@ protected function getEventTypeFromTagName($tagName)
*
* @return string
*/
protected function getEventDom(DOMElement $event)
protected function getEventDom(\DOMElement $event)
{
return $event->ownerDocument->saveXML($event);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Jackalope/Transport/Jackrabbit/HTTPErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Jackalope\Transport\Jackrabbit;

use RuntimeException;

/**
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
* @license http://opensource.org/licenses/MIT MIT License
*/
class HTTPErrorException extends RuntimeException
class HTTPErrorException extends \RuntimeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public function setCheckLoginOnServer($bool);
/**
* Internal method to fetch event data.
*
* @param $date
*
* @return array hashmap with 'data' containing unfiltered DOM of xml atom
* feed of events, 'nextMillis' is the next timestamp if there are
* more events to be found, false otherwise
Expand Down
6 changes: 3 additions & 3 deletions src/Jackalope/Transport/Jackrabbit/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ protected function handleError(curl $curl, $response, $httpCode)

// use XML error response if it's there
if ('<?' === substr($response, 0, 2)) {
$dom = new DOMDocument();
$dom = new \DOMDocument();
$dom->loadXML($response);
$err = $dom->getElementsByTagNameNS(Client::NS_DCR, 'exception');
if ($err->length > 0) {
Expand Down Expand Up @@ -737,14 +737,14 @@ protected function getLongErrorString($curl, $response)
*
* @param bool $forceMultiple whether to force parallel requests or not
*
* @return DOMDocument the loaded XML response text
* @return \DOMDocument the loaded XML response text
*/
public function executeDom($forceMultiple = false)
{
$xml = $this->execute(null, $forceMultiple);

// create new DOMDocument and load the response text.
$dom = new DOMDocument();
$dom = new \DOMDocument();
$dom->loadXML($xml);

return $dom;
Expand Down
Loading

0 comments on commit f8013c9

Please sign in to comment.