Skip to content

Commit

Permalink
Merge branch 'sabre-io:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh authored Sep 6, 2024
2 parents 96674e8 + a6ff593 commit df9f086
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
coverage: [ 'xdebug' ]
streaming: [ false ]
include:
Expand Down
15 changes: 12 additions & 3 deletions lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Sabre\VObject;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\ITip;
use Sabre\VObject\ITip\Broker;
use Sabre\VObject\ITip\Message;
use Sabre\VObject\Reader;

Expand Down Expand Up @@ -389,7 +390,7 @@ public function beforeUnbind($path)
$node->getOwner()
);

$broker = new ITip\Broker();
$broker = $this->createITipBroker();
$messages = $broker->parseEvent(null, $addresses, $node->get());

foreach ($messages as $message) {
Expand Down Expand Up @@ -500,7 +501,7 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage)
$isNewNode = true;
}

$broker = new ITip\Broker();
$broker = $this->createITipBroker();
$newObject = $broker->processMessage($iTipMessage, $currentObject);

$inbox->createFile($newFileName, $iTipMessage->message->serialize());
Expand Down Expand Up @@ -611,7 +612,7 @@ public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilege
*/
protected function processICalendarChange($oldObject, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false)
{
$broker = new ITip\Broker();
$broker = $this->createITipBroker();
$messages = $broker->parseEvent($newObject, $addresses, $oldObject);

if ($messages) {
Expand Down Expand Up @@ -994,4 +995,12 @@ public function getPluginInfo()
'link' => 'http://sabre.io/dav/scheduling/',
];
}

/**
* Returns an instance of the iTip\Broker.
*/
protected function createITipBroker(): Broker
{
return new Broker();
}
}
2 changes: 1 addition & 1 deletion lib/CardDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ protected function negotiateVCard($input, &$mimeType = null)
*
* @return string
*/
protected function convertVCard($data, $target, array $propertiesFilter = null)
protected function convertVCard($data, $target, ?array $propertiesFilter = null)
{
if (is_resource($data)) {
$data = stream_get_contents($data);
Expand Down
2 changes: 1 addition & 1 deletion lib/CardDAV/Xml/Property/SupportedAddressData.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SupportedAddressData implements XmlSerializable
/**
* Creates the property.
*/
public function __construct(array $supportedData = null)
public function __construct(?array $supportedData = null)
{
if (is_null($supportedData)) {
$supportedData = [
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/Auth/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Plugin extends ServerPlugin
*
* @param Backend\BackendInterface $authBackend
*/
public function __construct(Backend\BackendInterface $authBackend = null)
public function __construct(?Backend\BackendInterface $authBackend = null)
{
if (!is_null($authBackend)) {
$this->addBackend($authBackend);
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/Exception/Locked.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Locked extends DAV\Exception
*
* @param DAV\Locks\LockInfo $lock
*/
public function __construct(DAV\Locks\LockInfo $lock = null)
public function __construct(?DAV\Locks\LockInfo $lock = null)
{
parent::__construct();

Expand Down
4 changes: 2 additions & 2 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Server implements LoggerAwareInterface, EmitterInterface
*
* @throws Exception
*/
public function __construct($treeOrNode = null, HTTP\Sapi $sapi = null)
public function __construct($treeOrNode = null, ?HTTP\Sapi $sapi = null)
{
if ($treeOrNode instanceof Tree) {
$this->tree = $treeOrNode;
Expand Down Expand Up @@ -882,7 +882,7 @@ public function getHTTPHeaders($path)
*
* @return \Traversable
*/
private function generatePathNodes(PropFind $propFind, array $yieldFirst = null)
private function generatePathNodes(PropFind $propFind, ?array $yieldFirst = null)
{
if (null !== $yieldFirst) {
yield $yieldFirst;
Expand Down
14 changes: 13 additions & 1 deletion lib/DAV/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,21 @@ public function getNodeForPath($path)
return $this->rootNode;
}

$parts = explode('/', $path);
$node = $this->rootNode;

// look for any cached parent and collect the parts below the parent
$parts = [];
$remainingPath = $path;
do {
list($remainingPath, $baseName) = Uri\split($remainingPath);
array_unshift($parts, $baseName);

if (isset($this->cache[$remainingPath])) {
$node = $this->cache[$remainingPath];
break;
}
} while ('' !== $remainingPath);

while (count($parts)) {
if (!($node instanceof ICollection)) {
throw new Exception\NotFound('Could not find node at path: '.$path);
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/CalDAV/SharedCalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SharedCalendarTest extends \PHPUnit\Framework\TestCase
{
protected $backend;

public function getInstance(array $props = null)
public function getInstance(?array $props = null)
{
if (is_null($props)) {
$props = [
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Mock/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Collection extends DAV\Collection
* @param string $name
* @param Collection $parent
*/
public function __construct($name, array $children = [], Collection $parent = null)
public function __construct($name, array $children = [], ?Collection $parent = null)
{
$this->name = $name;
foreach ($children as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Mock/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class File extends DAV\File
* @param Collection $parent
* @param int $lastModified
*/
public function __construct($name, $contents, Collection $parent = null, $lastModified = -1)
public function __construct($name, $contents, ?Collection $parent = null, $lastModified = -1)
{
$this->name = $name;
$this->put($contents);
Expand Down
17 changes: 17 additions & 0 deletions tests/Sabre/DAV/TreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ public function testGetSubTreeNode()
$this->assertInstanceOf(INode::class, $tree->getNodeForPath('subtree/sub/1'));
$this->assertInstanceOf(INode::class, $tree->getNodeForPath('subtree/2/3'));
}

public function testGetNodeCacheParent()
{
$tree = new TreeMock();

/** @var TreeDirectoryTester $root */
$root = $tree->getNodeForPath('');
$root->createDirectory('new');
$parent = $tree->getNodeForPath('new');
$parent->createDirectory('child');

// make it so we can't create the 'new' folder again
unset($root->newDirectories['new']);

// we should still be able to query child items from the 'new' folder because it is cached in the tree
$this->assertInstanceOf(INode::class, $tree->getNodeForPath('new/child'));
}
}

class TreeMock extends Tree
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAVACL/PrincipalBackend/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Mock extends AbstractBackend
public $groupMembers = [];
public $principals;

public function __construct(array $principals = null)
public function __construct(?array $principals = null)
{
$this->principals = $principals;

Expand Down

0 comments on commit df9f086

Please sign in to comment.