From 96ac9ac268d931fed3c3a1769778b624537e4cdb Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 11 Mar 2022 12:20:17 -0100 Subject: [PATCH] support oracle Signed-off-by: Maxence Lange --- composer.json | 3 - composer.lock | 461 +++---- lib/AppInfo/Application.php | 4 - lib/CirclesManager.php | 2 +- .../v2/CollaboratorSearchPlugin.php | 4 +- lib/Command/CirclesCheck.php | 20 +- lib/Command/CirclesDetails.php | 2 +- lib/Command/CirclesList.php | 8 +- lib/Command/CirclesMemberships.php | 24 +- lib/Command/CirclesRemote.php | 22 +- lib/Command/CirclesReport.php | 13 +- lib/Command/CirclesTest.php | 12 +- lib/Command/MembersAdd.php | 16 +- lib/Command/MembersList.php | 30 +- lib/Command/SharesFiles.php | 2 +- lib/Controller/AdminController.php | 8 +- lib/Controller/EventWrapperController.php | 8 +- lib/Controller/LocalController.php | 8 +- lib/Controller/RemoteController.php | 111 +- lib/Cron/ContactsExistingShares.php | 2 +- lib/Cron/Maintenance.php | 2 +- lib/Db/AccountsRequest.php | 2 +- lib/Db/AccountsRequestBuilder.php | 2 +- lib/Db/CircleRequest.php | 13 +- lib/Db/CircleRequestBuilder.php | 5 +- lib/Db/CoreQueryBuilder.php | 60 +- lib/Db/DeprecatedMembersRequest.php | 2 +- lib/Db/EventWrapperRequestBuilder.php | 2 +- lib/Db/GSSharesRequest.php | 2 +- lib/Db/MemberRequest.php | 3 +- lib/Db/MemberRequestBuilder.php | 3 +- lib/Db/MembershipRequestBuilder.php | 2 +- lib/Db/MountRequest.php | 2 +- lib/Db/MountRequestBuilder.php | 2 +- lib/Db/RemoteRequest.php | 29 +- lib/Db/RemoteRequestBuilder.php | 2 +- lib/Db/ShareLockRequestBuilder.php | 2 +- lib/Db/ShareTokenRequestBuilder.php | 5 +- lib/Db/ShareWrapperRequest.php | 17 - lib/Db/ShareWrapperRequestBuilder.php | 3 +- lib/Db/TokensRequestBuilder.php | 2 +- lib/Events/CircleResultGenericEvent.php | 2 +- lib/Events/Files/FileShareCreatedEvent.php | 2 +- lib/Exceptions/JsonNotRequestedException.php | 34 + lib/FederatedItems/CircleConfig.php | 4 +- lib/FederatedItems/CircleCreate.php | 4 +- lib/FederatedItems/CircleDestroy.php | 4 +- lib/FederatedItems/CircleEdit.php | 4 +- lib/FederatedItems/CircleJoin.php | 10 +- lib/FederatedItems/CircleLeave.php | 8 +- lib/FederatedItems/CircleSettings.php | 4 +- lib/FederatedItems/Files/FileShare.php | 10 +- lib/FederatedItems/Files/FileUnshare.php | 12 +- lib/FederatedItems/ItemLock.php | 2 +- lib/FederatedItems/LoopbackTest.php | 2 +- lib/FederatedItems/MassiveMemberAdd.php | 6 +- lib/FederatedItems/MemberDisplayName.php | 7 +- lib/FederatedItems/MemberLevel.php | 4 +- lib/FederatedItems/SharedItemsSync.php | 2 +- lib/FederatedItems/SingleMemberAdd.php | 10 +- lib/GlobalScale/FileShare.php | 4 +- lib/GlobalScale/GSMount/Mount.php | 2 +- lib/GlobalScale/GSMount/MountProvider.php | 2 +- lib/GlobalScale/MemberAdd.php | 2 +- lib/GlobalScale/Test.php | 2 +- lib/Handlers/WebfingerHandler.php | 4 +- lib/IFederatedSync.php | 2 +- .../Examples/ExampleAddingCircleMember.php | 4 +- .../Examples/ExampleMembershipsCreated.php | 6 +- .../Examples/ExampleMembershipsRemoved.php | 6 +- .../ExampleRequestingCircleMember.php | 4 +- lib/Listeners/Files/AddingMemberSendMail.php | 6 +- lib/Listeners/Files/CreatingShareSendMail.php | 6 +- lib/Listeners/Files/DestroyingCircle.php | 6 +- lib/Listeners/Files/MemberAddedSendMail.php | 8 +- lib/Listeners/Files/MembershipsRemoved.php | 2 +- .../Files/PreparingMemberSendMail.php | 6 +- .../Files/PreparingShareSendMail.php | 6 +- lib/Listeners/Files/RemovingMember.php | 6 +- lib/Listeners/Files/ShareCreatedSendMail.php | 6 +- .../Notifications/RequestingMember.php | 4 +- lib/Migration/Migration.php | 4 +- lib/Model/Circle.php | 48 +- lib/Model/DavCard.php | 2 +- lib/Model/DeprecatedCircle.php | 2 +- lib/Model/Federated/EventWrapper.php | 14 +- lib/Model/Federated/FederatedEvent.php | 6 +- lib/Model/Federated/FederatedShare.php | 14 +- lib/Model/Federated/RemoteInstance.php | 14 +- lib/Model/FederatedUser.php | 18 +- lib/Model/FileCacheWrapper.php | 14 +- lib/Model/GlobalScale/GSEvent.php | 4 +- lib/Model/GlobalScale/GSShare.php | 2 +- lib/Model/GlobalScale/GSShareMountpoint.php | 2 +- lib/Model/GlobalScale/GSWrapper.php | 2 +- lib/Model/Helpers/MemberHelper.php | 2 +- lib/Model/Member.php | 18 +- lib/Model/Membership.php | 14 +- lib/Model/ModelManager.php | 8 +- lib/Model/Mount.php | 10 +- lib/Model/Mountpoint.php | 2 +- lib/Model/Report.php | 4 +- lib/Model/ShareToken.php | 14 +- lib/Model/ShareWrapper.php | 18 +- lib/Model/SharesToken.php | 2 +- lib/MountManager/CircleMount.php | 2 +- lib/MountManager/CircleMountProvider.php | 2 +- lib/Notification/Notifier.php | 4 +- lib/Search/GlobalScaleUsers.php | 16 +- lib/Search/LocalUsers.php | 2 +- lib/Service/CircleService.php | 10 +- lib/Service/CirclesService.php | 2 +- lib/Service/ConfigService.php | 18 +- lib/Service/ContactService.php | 8 +- lib/Service/EventService.php | 6 +- lib/Service/EventWrapperService.php | 10 +- lib/Service/FederatedEventService.php | 18 +- lib/Service/FederatedShareService.php | 12 +- lib/Service/FederatedUserService.php | 14 +- lib/Service/GSUpstreamService.php | 28 +- lib/Service/GlobalScaleService.php | 14 +- lib/Service/InterfaceService.php | 8 +- lib/Service/MaintenanceService.php | 4 +- lib/Service/MemberService.php | 16 +- lib/Service/MembersService.php | 16 +- lib/Service/MembershipService.php | 6 +- lib/Service/MigrationService.php | 8 +- lib/Service/MiscService.php | 2 +- lib/Service/NotificationService.php | 4 +- lib/Service/OutputService.php | 6 +- lib/Service/RemoteDownstreamService.php | 12 +- lib/Service/RemoteService.php | 14 +- lib/Service/RemoteStreamService.php | 56 +- lib/Service/RemoteUpstreamService.php | 8 +- lib/Service/ShareTokenService.php | 2 +- lib/Service/ShareWrapperService.php | 2 +- lib/Service/SyncService.php | 6 +- lib/ShareByCircleProvider.php | 8 +- lib/ShareByCircleProviderDeprecated.php | 2 +- lib/Tools/ActivityPub/NCSignature.php | 413 ++++++ lib/Tools/Db/ExtendedQueryBuilder.php | 1135 +++++++++++++++++ lib/Tools/Db/IQueryRow.php | 49 + .../Exceptions/ArrayNotFoundException.php | 42 + lib/Tools/Exceptions/DateTimeException.php | 42 + lib/Tools/Exceptions/InvalidItemException.php | 42 + .../Exceptions/InvalidOriginException.php | 42 + .../Exceptions/ItemNotFoundException.php | 42 + .../Exceptions/MalformedArrayException.php | 42 + .../Exceptions/RequestContentException.php | 42 + .../Exceptions/RequestNetworkException.php | 42 + .../RequestResultNotJsonException.php | 42 + .../Exceptions/RequestResultSizeException.php | 42 + .../Exceptions/RequestServerException.php | 42 + lib/Tools/Exceptions/RowNotFoundException.php | 42 + lib/Tools/Exceptions/SignatoryException.php | 42 + lib/Tools/Exceptions/SignatureException.php | 42 + lib/Tools/Exceptions/UnknownTypeException.php | 42 + .../WellKnownLinkNotFoundException.php | 42 + lib/Tools/IDeserializable.php | 42 + lib/Tools/Model/NCRequest.php | 174 +++ lib/Tools/Model/NCRequestResult.php | 321 +++++ lib/Tools/Model/NCSignatory.php | 293 +++++ lib/Tools/Model/NCSignedRequest.php | 348 +++++ lib/Tools/Model/NCWebfinger.php | 197 +++ lib/Tools/Model/NCWellKnownLink.php | 222 ++++ lib/Tools/Model/Request.php | 832 ++++++++++++ lib/Tools/Model/SimpleDataStore.php | 488 +++++++ lib/Tools/Model/TreeNode.php | 232 ++++ lib/Tools/Traits/TArrayTools.php | 432 +++++++ lib/Tools/Traits/TAsync.php | 75 ++ lib/Tools/Traits/TConsoleTree.php | 142 +++ lib/Tools/Traits/TDeserialize.php | 109 ++ lib/Tools/Traits/TNCLocalSignatory.php | 111 ++ lib/Tools/Traits/TNCLogger.php | 201 +++ lib/Tools/Traits/TNCRequest.php | 178 +++ lib/Tools/Traits/TNCSetup.php | 107 ++ lib/Tools/Traits/TNCSignatory.php | 207 +++ lib/Tools/Traits/TNCWellKnown.php | 128 ++ lib/Tools/Traits/TStringTools.php | 258 ++++ lib/UnifiedSearch/UnifiedSearchProvider.php | 4 +- .../lib/Controller/AdminControllerTest.php | 4 +- .../lib/Controller/LocalControllerTest.php | 12 +- 182 files changed, 8256 insertions(+), 861 deletions(-) create mode 100644 lib/Exceptions/JsonNotRequestedException.php create mode 100644 lib/Tools/ActivityPub/NCSignature.php create mode 100644 lib/Tools/Db/ExtendedQueryBuilder.php create mode 100644 lib/Tools/Db/IQueryRow.php create mode 100644 lib/Tools/Exceptions/ArrayNotFoundException.php create mode 100644 lib/Tools/Exceptions/DateTimeException.php create mode 100644 lib/Tools/Exceptions/InvalidItemException.php create mode 100644 lib/Tools/Exceptions/InvalidOriginException.php create mode 100644 lib/Tools/Exceptions/ItemNotFoundException.php create mode 100644 lib/Tools/Exceptions/MalformedArrayException.php create mode 100644 lib/Tools/Exceptions/RequestContentException.php create mode 100644 lib/Tools/Exceptions/RequestNetworkException.php create mode 100644 lib/Tools/Exceptions/RequestResultNotJsonException.php create mode 100644 lib/Tools/Exceptions/RequestResultSizeException.php create mode 100644 lib/Tools/Exceptions/RequestServerException.php create mode 100644 lib/Tools/Exceptions/RowNotFoundException.php create mode 100644 lib/Tools/Exceptions/SignatoryException.php create mode 100644 lib/Tools/Exceptions/SignatureException.php create mode 100644 lib/Tools/Exceptions/UnknownTypeException.php create mode 100644 lib/Tools/Exceptions/WellKnownLinkNotFoundException.php create mode 100644 lib/Tools/IDeserializable.php create mode 100644 lib/Tools/Model/NCRequest.php create mode 100644 lib/Tools/Model/NCRequestResult.php create mode 100644 lib/Tools/Model/NCSignatory.php create mode 100644 lib/Tools/Model/NCSignedRequest.php create mode 100644 lib/Tools/Model/NCWebfinger.php create mode 100644 lib/Tools/Model/NCWellKnownLink.php create mode 100644 lib/Tools/Model/Request.php create mode 100644 lib/Tools/Model/SimpleDataStore.php create mode 100644 lib/Tools/Model/TreeNode.php create mode 100644 lib/Tools/Traits/TArrayTools.php create mode 100644 lib/Tools/Traits/TAsync.php create mode 100644 lib/Tools/Traits/TConsoleTree.php create mode 100644 lib/Tools/Traits/TDeserialize.php create mode 100644 lib/Tools/Traits/TNCLocalSignatory.php create mode 100644 lib/Tools/Traits/TNCLogger.php create mode 100644 lib/Tools/Traits/TNCRequest.php create mode 100644 lib/Tools/Traits/TNCSetup.php create mode 100644 lib/Tools/Traits/TNCSignatory.php create mode 100644 lib/Tools/Traits/TNCWellKnown.php create mode 100644 lib/Tools/Traits/TStringTools.php diff --git a/composer.json b/composer.json index bdd4cae06..55ab2a59e 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,6 @@ "OCA\\Circles\\": "lib/" } }, - "require": { - "artificial-owl/my-small-php-tools": "~22" - }, "scripts": { "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", diff --git a/composer.lock b/composer.lock index 2a770d99e..f339b87c4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,69 +4,28 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "66a5f1b7417abb934f926dee132f4cca", - "packages": [ - { - "name": "artificial-owl/my-small-php-tools", - "version": "v22.1.7", - "source": { - "type": "git", - "url": "https://github.com/ArtificialOwl/my-small-php-tools.git", - "reference": "104c3fe1a2c6aa8030e7fcb8ea46566c3efce3c9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ArtificialOwl/my-small-php-tools/zipball/104c3fe1a2c6aa8030e7fcb8ea46566c3efce3c9", - "reference": "104c3fe1a2c6aa8030e7fcb8ea46566c3efce3c9", - "shasum": "" - }, - "require": { - "php": ">=7.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "ArtificialOwl\\MySmallPhpTools\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "AGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Maxence Lange", - "email": "maxence@artificial-owl.com" - } - ], - "description": "My small PHP Tools", - "support": { - "issues": "https://github.com/ArtificialOwl/my-small-php-tools/issues", - "source": "https://github.com/ArtificialOwl/my-small-php-tools/tree/v22.1.7" - }, - "time": "2021-07-26T12:32:23+00:00" - } - ], + "content-hash": "a28ca34070a501e76cf20cdb002dd841", + "packages": [], "packages-dev": [ { "name": "composer/pcre", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "3d322d715c43a1ac36c7fe215fa59336265500f2" + "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/3d322d715c43a1ac36c7fe215fa59336265500f2", - "reference": "3d322d715c43a1ac36c7fe215fa59336265500f2", + "url": "https://api.github.com/repos/composer/pcre/zipball/67a32d7d6f9f560b726ab25a061b38ff3a80c560", + "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^1", + "phpstan/phpstan": "^1.3", "phpstan/phpstan-strict-rules": "^1.1", "symfony/phpunit-bridge": "^4.2 || ^5" }, @@ -101,7 +60,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/1.0.0" + "source": "https://github.com/composer/pcre/tree/1.0.1" }, "funding": [ { @@ -117,27 +76,27 @@ "type": "tidelift" } ], - "time": "2021-12-06T15:17:27+00:00" + "time": "2022-01-21T20:24:37+00:00" }, { "name": "composer/semver", - "version": "3.2.6", + "version": "3.2.9", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "83e511e247de329283478496f7a1e114c9517506" + "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506", - "reference": "83e511e247de329283478496f7a1e114c9517506", + "url": "https://api.github.com/repos/composer/semver/zipball/a951f614bd64dcd26137bc9b7b2637ddcfc57649", + "reference": "a951f614bd64dcd26137bc9b7b2637ddcfc57649", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^0.12.54", + "phpstan/phpstan": "^1.4", "symfony/phpunit-bridge": "^4.2 || ^5" }, "type": "library", @@ -182,7 +141,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.2.6" + "source": "https://github.com/composer/semver/tree/3.2.9" }, "funding": [ { @@ -198,20 +157,20 @@ "type": "tidelift" } ], - "time": "2021-10-25T11:34:17+00:00" + "time": "2022-02-04T13:58:43+00:00" }, { "name": "composer/xdebug-handler", - "version": "2.0.3", + "version": "2.0.5", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "6555461e76962fd0379c444c46fd558a0fcfb65e" + "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6555461e76962fd0379c444c46fd558a0fcfb65e", - "reference": "6555461e76962fd0379c444c46fd558a0fcfb65e", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/9e36aeed4616366d2b690bdce11f71e9178c579a", + "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a", "shasum": "" }, "require": { @@ -248,7 +207,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/2.0.3" + "source": "https://github.com/composer/xdebug-handler/tree/2.0.5" }, "funding": [ { @@ -264,7 +223,7 @@ "type": "tidelift" } ], - "time": "2021-12-08T13:07:32+00:00" + "time": "2022-02-24T20:20:32+00:00" }, { "name": "doctrine/annotations", @@ -340,29 +299,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^8.0", + "doctrine/coding-standard": "^9", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.22" }, "type": "library", "autoload": { @@ -389,7 +349,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + "source": "https://github.com/doctrine/instantiator/tree/1.4.1" }, "funding": [ { @@ -405,36 +365,32 @@ "type": "tidelift" } ], - "time": "2020-11-10T18:47:58+00:00" + "time": "2022-03-03T08:28:38+00:00" }, { "name": "doctrine/lexer", - "version": "1.2.1", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229", + "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpstan/phpstan": "^0.11.8", - "phpunit/phpunit": "^8.2" + "doctrine/coding-standard": "^9.0", + "phpstan/phpstan": "^1.3", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.11" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" @@ -469,7 +425,7 @@ ], "support": { "issues": "https://github.com/doctrine/lexer/issues", - "source": "https://github.com/doctrine/lexer/tree/1.2.1" + "source": "https://github.com/doctrine/lexer/tree/1.2.3" }, "funding": [ { @@ -485,7 +441,7 @@ "type": "tidelift" } ], - "time": "2020-05-25T17:44:05+00:00" + "time": "2022-02-28T11:07:21+00:00" }, { "name": "friendsofphp/php-cs-fixer", @@ -598,37 +554,38 @@ }, { "name": "myclabs/deep-copy", - "version": "1.10.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, - "replace": { - "myclabs/deep-copy": "self.version" + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" }, "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, "files": [ "src/DeepCopy/deep_copy.php" - ] + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -644,7 +601,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" }, "funding": [ { @@ -652,7 +609,7 @@ "type": "tidelift" } ], - "time": "2020-11-13T09:40:50+00:00" + "time": "2022-03-03T13:19:32+00:00" }, { "name": "nextcloud/coding-standard", @@ -813,16 +770,16 @@ }, { "name": "phar-io/version", - "version": "3.1.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "bae7c545bef187884426f042434e561ab1ddb182" + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", - "reference": "bae7c545bef187884426f042434e561ab1ddb182", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { @@ -858,9 +815,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.1.0" + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "time": "2021-02-23T14:00:09+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { "name": "php-cs-fixer/diff", @@ -1029,16 +986,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.5.1", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae" + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae", - "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706", + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706", "shasum": "" }, "require": { @@ -1073,9 +1030,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0" }, - "time": "2021-10-02T14:08:47+00:00" + "time": "2022-01-04T19:58:01+00:00" }, { "name": "phpspec/prophecy", @@ -1146,16 +1103,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.10", + "version": "9.2.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687" + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687", - "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f", "shasum": "" }, "require": { @@ -1211,7 +1168,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15" }, "funding": [ { @@ -1219,7 +1176,7 @@ "type": "github" } ], - "time": "2021-12-05T09:12:13+00:00" + "time": "2022-03-07T09:28:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1464,16 +1421,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.10", + "version": "9.5.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a" + "reference": "1b5856028273bfd855e60a887278857d872ec67a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a", + "reference": "1b5856028273bfd855e60a887278857d872ec67a", "shasum": "" }, "require": { @@ -1489,7 +1446,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.7", + "phpunit/php-code-coverage": "^9.2.13", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1524,11 +1481,11 @@ } }, "autoload": { - "classmap": [ - "src/" - ], "files": [ "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1551,11 +1508,11 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18" }, "funding": [ { - "url": "https://phpunit.de/donate.html", + "url": "https://phpunit.de/sponsors.html", "type": "custom" }, { @@ -1563,7 +1520,7 @@ "type": "github" } ], - "time": "2021-09-25T07:38:51+00:00" + "time": "2022-03-08T06:52:28+00:00" }, { "name": "psr/cache", @@ -2268,16 +2225,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.3", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "shasum": "" }, "require": { @@ -2320,7 +2277,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" }, "funding": [ { @@ -2328,7 +2285,7 @@ "type": "github" } ], - "time": "2021-06-11T13:31:12+00:00" + "time": "2022-02-14T08:28:10+00:00" }, { "name": "sebastian/lines-of-code", @@ -2728,16 +2685,16 @@ }, { "name": "symfony/console", - "version": "v5.4.1", + "version": "v5.4.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4" + "reference": "d8111acc99876953f52fe16d4c50eb60940d49ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4", - "reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4", + "url": "https://api.github.com/repos/symfony/console/zipball/d8111acc99876953f52fe16d4c50eb60940d49ad", + "reference": "d8111acc99876953f52fe16d4c50eb60940d49ad", "shasum": "" }, "require": { @@ -2807,7 +2764,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.1" + "source": "https://github.com/symfony/console/tree/v5.4.5" }, "funding": [ { @@ -2823,7 +2780,7 @@ "type": "tidelift" } ], - "time": "2021-12-09T11:22:43+00:00" + "time": "2022-02-24T12:45:35+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2894,16 +2851,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v5.4.0", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb" + "reference": "dec8a9f58d20df252b9cd89f1c6c1530f747685d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/27d39ae126352b9fa3be5e196ccf4617897be3eb", - "reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/dec8a9f58d20df252b9cd89f1c6c1530f747685d", + "reference": "dec8a9f58d20df252b9cd89f1c6c1530f747685d", "shasum": "" }, "require": { @@ -2959,7 +2916,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.0" + "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.3" }, "funding": [ { @@ -2975,7 +2932,7 @@ "type": "tidelift" } ], - "time": "2021-11-23T10:19:22+00:00" + "time": "2022-01-02T09:53:40+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -3058,16 +3015,16 @@ }, { "name": "symfony/filesystem", - "version": "v5.4.0", + "version": "v5.4.6", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "731f917dc31edcffec2c6a777f3698c33bea8f01" + "reference": "d53a45039974952af7f7ebc461ccdd4295e29440" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/731f917dc31edcffec2c6a777f3698c33bea8f01", - "reference": "731f917dc31edcffec2c6a777f3698c33bea8f01", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/d53a45039974952af7f7ebc461ccdd4295e29440", + "reference": "d53a45039974952af7f7ebc461ccdd4295e29440", "shasum": "" }, "require": { @@ -3102,7 +3059,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.0" + "source": "https://github.com/symfony/filesystem/tree/v5.4.6" }, "funding": [ { @@ -3118,20 +3075,20 @@ "type": "tidelift" } ], - "time": "2021-10-28T13:39:27+00:00" + "time": "2022-03-02T12:42:23+00:00" }, { "name": "symfony/finder", - "version": "v5.4.0", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "d2f29dac98e96a98be467627bd49c2efb1bc2590" + "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/d2f29dac98e96a98be467627bd49c2efb1bc2590", - "reference": "d2f29dac98e96a98be467627bd49c2efb1bc2590", + "url": "https://api.github.com/repos/symfony/finder/zipball/231313534dded84c7ecaa79d14bc5da4ccb69b7d", + "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d", "shasum": "" }, "require": { @@ -3165,7 +3122,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.0" + "source": "https://github.com/symfony/finder/tree/v5.4.3" }, "funding": [ { @@ -3181,20 +3138,20 @@ "type": "tidelift" } ], - "time": "2021-11-28T15:25:38+00:00" + "time": "2022-01-26T16:34:36+00:00" }, { "name": "symfony/options-resolver", - "version": "v5.4.0", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "b0fb78576487af19c500aaddb269fd36701d4847" + "reference": "cc1147cb11af1b43f503ac18f31aa3bec213aba8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/b0fb78576487af19c500aaddb269fd36701d4847", - "reference": "b0fb78576487af19c500aaddb269fd36701d4847", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/cc1147cb11af1b43f503ac18f31aa3bec213aba8", + "reference": "cc1147cb11af1b43f503ac18f31aa3bec213aba8", "shasum": "" }, "require": { @@ -3234,7 +3191,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v5.4.0" + "source": "https://github.com/symfony/options-resolver/tree/v5.4.3" }, "funding": [ { @@ -3250,25 +3207,28 @@ "type": "tidelift" } ], - "time": "2021-11-23T10:19:22+00:00" + "time": "2022-01-02T09:53:40+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.23.0", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + "reference": "30885182c981ab175d4d034db0f6f469898070ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", + "reference": "30885182c981ab175d4d034db0f6f469898070ab", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-ctype": "*" + }, "suggest": { "ext-ctype": "For best performance" }, @@ -3283,12 +3243,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3313,7 +3273,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.25.0" }, "funding": [ { @@ -3329,20 +3289,20 @@ "type": "tidelift" } ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-10-20T20:35:02+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.23.1", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "16880ba9c5ebe3642d1995ab866db29270b36535" + "reference": "81b86b50cf841a64252b439e738e97f4a34e2783" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/16880ba9c5ebe3642d1995ab866db29270b36535", - "reference": "16880ba9c5ebe3642d1995ab866db29270b36535", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/81b86b50cf841a64252b439e738e97f4a34e2783", + "reference": "81b86b50cf841a64252b439e738e97f4a34e2783", "shasum": "" }, "require": { @@ -3362,12 +3322,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Grapheme\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3394,7 +3354,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.1" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.25.0" }, "funding": [ { @@ -3410,11 +3370,11 @@ "type": "tidelift" } ], - "time": "2021-05-27T12:26:48+00:00" + "time": "2021-11-23T21:10:46+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.23.0", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -3443,12 +3403,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, "files": [ "bootstrap.php" ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, "classmap": [ "Resources/stubs" ] @@ -3478,7 +3438,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.25.0" }, "funding": [ { @@ -3498,21 +3458,24 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.23.1", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-mbstring": "*" + }, "suggest": { "ext-mbstring": "For best performance" }, @@ -3527,12 +3490,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3558,7 +3521,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.25.0" }, "funding": [ { @@ -3574,7 +3537,7 @@ "type": "tidelift" } ], - "time": "2021-05-27T12:26:48+00:00" + "time": "2021-11-30T18:21:41+00:00" }, { "name": "symfony/polyfill-php70", @@ -3646,7 +3609,7 @@ }, { "name": "symfony/polyfill-php72", - "version": "v1.23.0", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", @@ -3672,12 +3635,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3702,7 +3665,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-php72/tree/v1.25.0" }, "funding": [ { @@ -3722,16 +3685,16 @@ }, { "name": "symfony/polyfill-php73", - "version": "v1.23.0", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010" + "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fba8933c384d6476ab14fb7b8526e5287ca7e010", - "reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", + "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5", "shasum": "" }, "require": { @@ -3748,12 +3711,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, "files": [ "bootstrap.php" ], + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, "classmap": [ "Resources/stubs" ] @@ -3781,7 +3744,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.25.0" }, "funding": [ { @@ -3797,20 +3760,20 @@ "type": "tidelift" } ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-06-05T21:20:04+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.23.1", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" + "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4407588e0d3f1f52efb65fbe92babe41f37fe50c", + "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c", "shasum": "" }, "require": { @@ -3827,12 +3790,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, "files": [ "bootstrap.php" ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, "classmap": [ "Resources/stubs" ] @@ -3864,7 +3827,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.25.0" }, "funding": [ { @@ -3880,20 +3843,20 @@ "type": "tidelift" } ], - "time": "2021-07-28T13:41:28+00:00" + "time": "2022-03-04T08:16:47+00:00" }, { "name": "symfony/process", - "version": "v5.4.0", + "version": "v5.4.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5be20b3830f726e019162b26223110c8f47cf274" + "reference": "95440409896f90a5f85db07a32b517ecec17fa4c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5be20b3830f726e019162b26223110c8f47cf274", - "reference": "5be20b3830f726e019162b26223110c8f47cf274", + "url": "https://api.github.com/repos/symfony/process/zipball/95440409896f90a5f85db07a32b517ecec17fa4c", + "reference": "95440409896f90a5f85db07a32b517ecec17fa4c", "shasum": "" }, "require": { @@ -3926,7 +3889,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.0" + "source": "https://github.com/symfony/process/tree/v5.4.5" }, "funding": [ { @@ -3942,7 +3905,7 @@ "type": "tidelift" } ], - "time": "2021-11-28T15:25:38+00:00" + "time": "2022-01-30T18:16:22+00:00" }, { "name": "symfony/service-contracts", @@ -4029,16 +3992,16 @@ }, { "name": "symfony/stopwatch", - "version": "v5.4.0", + "version": "v5.4.5", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "208ef96122bfed82a8f3a61458a07113a08bdcfe" + "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/208ef96122bfed82a8f3a61458a07113a08bdcfe", - "reference": "208ef96122bfed82a8f3a61458a07113a08bdcfe", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", + "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", "shasum": "" }, "require": { @@ -4071,7 +4034,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.4.0" + "source": "https://github.com/symfony/stopwatch/tree/v5.4.5" }, "funding": [ { @@ -4087,20 +4050,20 @@ "type": "tidelift" } ], - "time": "2021-11-23T10:19:22+00:00" + "time": "2022-02-18T16:06:09+00:00" }, { "name": "symfony/string", - "version": "v5.4.0", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "9ffaaba53c61ba75a3c7a3a779051d1e9ec4fd2d" + "reference": "92043b7d8383e48104e411bc9434b260dbeb5a10" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/9ffaaba53c61ba75a3c7a3a779051d1e9ec4fd2d", - "reference": "9ffaaba53c61ba75a3c7a3a779051d1e9ec4fd2d", + "url": "https://api.github.com/repos/symfony/string/zipball/92043b7d8383e48104e411bc9434b260dbeb5a10", + "reference": "92043b7d8383e48104e411bc9434b260dbeb5a10", "shasum": "" }, "require": { @@ -4122,12 +4085,12 @@ }, "type": "library", "autoload": { - "psr-4": { - "Symfony\\Component\\String\\": "" - }, "files": [ "Resources/functions.php" ], + "psr-4": { + "Symfony\\Component\\String\\": "" + }, "exclude-from-classmap": [ "/Tests/" ] @@ -4157,7 +4120,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.0" + "source": "https://github.com/symfony/string/tree/v5.4.3" }, "funding": [ { @@ -4173,7 +4136,7 @@ "type": "tidelift" } ], - "time": "2021-11-24T10:02:00+00:00" + "time": "2022-01-02T09:53:40+00:00" }, { "name": "theseer/tokenizer", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0e1c81bc4..2b2a4aead 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -92,10 +92,6 @@ //use OCA\Files\App as FilesApp; - -require_once __DIR__ . '/../../vendor/autoload.php'; - - /** * Class Application * diff --git a/lib/CirclesManager.php b/lib/CirclesManager.php index 863bc7ae0..71837b72d 100644 --- a/lib/CirclesManager.php +++ b/lib/CirclesManager.php @@ -31,7 +31,7 @@ namespace OCA\Circles; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; use OCA\Circles\Exceptions\ContactFormatException; diff --git a/lib/Collaboration/v2/CollaboratorSearchPlugin.php b/lib/Collaboration/v2/CollaboratorSearchPlugin.php index 345b408ff..6cc49e0e8 100644 --- a/lib/Collaboration/v2/CollaboratorSearchPlugin.php +++ b/lib/Collaboration/v2/CollaboratorSearchPlugin.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Collaboration\v2; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OC\Share20\Share; use OCA\Circles\AppInfo\Application; @@ -51,7 +51,7 @@ * @package OCA\Circles\Collaboration\v2 */ class CollaboratorSearchPlugin implements ISearchPlugin { - use TNC22Logger; + use TNCLogger; /** @var IRequest */ diff --git a/lib/Command/CirclesCheck.php b/lib/Command/CirclesCheck.php index ce6098403..b5dcdb8a6 100644 --- a/lib/Command/CirclesCheck.php +++ b/lib/Command/CirclesCheck.php @@ -31,14 +31,6 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use Exception; use OC; use OC\AppConfig; @@ -63,6 +55,14 @@ use OCA\Circles\Service\RemoteService; use OCA\Circles\Service\RemoteStreamService; use OCA\Circles\Service\RemoteUpstreamService; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TStringTools; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -77,7 +77,7 @@ class CirclesCheck extends Base { use TStringTools; use TArrayTools; - use TNC22Request; + use TNCRequest; public static $checks = [ @@ -791,7 +791,7 @@ private function testRequest( string $route, array $args = [] ): bool { - $request = new NC22Request('', Request::type($type)); + $request = new NCRequest('', Request::type($type)); $this->configService->configureLoopbackRequest($request, $route, $args); $request->setFollowLocation(false); diff --git a/lib/Command/CirclesDetails.php b/lib/Command/CirclesDetails.php index 106233fa1..98442e3e3 100644 --- a/lib/Command/CirclesDetails.php +++ b/lib/Command/CirclesDetails.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\InvalidItemException; use OC\Core\Command\Base; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\FederatedItemException; diff --git a/lib/Command/CirclesList.php b/lib/Command/CirclesList.php index c8b8a95aa..967cc1a27 100644 --- a/lib/Command/CirclesList.php +++ b/lib/Command/CirclesList.php @@ -31,10 +31,10 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use OC\Core\Command\Base; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\FederatedItemException; diff --git a/lib/Command/CirclesMemberships.php b/lib/Command/CirclesMemberships.php index 2af52c465..19f0e7a5e 100644 --- a/lib/Command/CirclesMemberships.php +++ b/lib/Command/CirclesMemberships.php @@ -31,13 +31,6 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22TreeNode; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22ConsoleTree; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use Exception; use OC\Core\Command\Base; use OCA\Circles\Db\CircleRequest; @@ -66,6 +59,13 @@ use OCA\Circles\Service\ConfigService; use OCA\Circles\Service\FederatedUserService; use OCA\Circles\Service\MembershipService; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\TreeNode; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TConsoleTree; use OCP\IUserManager; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -81,7 +81,7 @@ */ class CirclesMemberships extends Base { use TArrayTools; - use TNC22ConsoleTree; + use TConsoleTree; /** @var IUserManager */ @@ -237,7 +237,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(''); - $tree = new NC22TreeNode(null, new SimpleDataStore(['federatedUser' => $federatedUser])); + $tree = new TreeNode(null, new SimpleDataStore(['federatedUser' => $federatedUser])); $this->generateTree($federatedUser->getSingleId(), $tree); $this->drawTree( @@ -255,10 +255,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * @param string $id - * @param NC22TreeNode $tree + * @param TreeNode $tree * @param array $knownIds */ - private function generateTree(string $id, NC22TreeNode $tree, array $knownIds = []) { + private function generateTree(string $id, TreeNode $tree, array $knownIds = []) { if (in_array($id, $knownIds)) { return; } @@ -271,7 +271,7 @@ private function generateTree(string $id, NC22TreeNode $tree, array $knownIds = continue; } - $item = new NC22TreeNode( + $item = new TreeNode( $tree, new SimpleDataStore( [ 'member' => $member, diff --git a/lib/Command/CirclesRemote.php b/lib/Command/CirclesRemote.php index 05572c2c1..b893b1abe 100644 --- a/lib/Command/CirclesRemote.php +++ b/lib/Command/CirclesRemote.php @@ -31,13 +31,13 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatureException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22SignedRequest; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22WellKnown; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\SignatureException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\NCSignedRequest; +use OCA\Circles\Tools\Traits\TNCWellKnown; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OC\Core\Command\Base; use OCA\Circles\AppInfo\Application; @@ -63,7 +63,7 @@ * @package OCA\Circles\Command */ class CirclesRemote extends Base { - use TNC22WellKnown; + use TNCWellKnown; use TStringTools; @@ -395,12 +395,12 @@ private function updateRemote(RemoteInstance $remoteSignatory): void { * @param string $remote * @param array $payload * - * @return NC22SignedRequest + * @return NCSignedRequest * @throws RequestNetworkException * @throws SignatoryException */ - private function outgoingTest(string $remote, array $payload): NC22SignedRequest { - $request = new NC22Request(); + private function outgoingTest(string $remote, array $payload): NCSignedRequest { + $request = new NCRequest(); $request->basedOnUrl($remote); $request->setFollowLocation(true); $request->setLocalAddressAllowed(true); diff --git a/lib/Command/CirclesReport.php b/lib/Command/CirclesReport.php index 787e54c0c..6e063b712 100644 --- a/lib/Command/CirclesReport.php +++ b/lib/Command/CirclesReport.php @@ -31,12 +31,9 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Console\Nextcloud\nc22\NC22InteractiveShell; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IInteractiveShellClient; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22InteractiveShellSession; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TArrayTools; use OC\Core\Command\Base; use OCA\Circles\Exceptions\InitiatorNotFoundException; use OCA\Circles\Exceptions\UnknownInterfaceException; @@ -63,7 +60,7 @@ * @package OCA\Circles\Command */ class CirclesReport extends Base implements IInteractiveShellClient { - use TNC22Deserialize; + use TDeserialize; use TArrayTools; @@ -136,6 +133,8 @@ protected function configure() { * @throws InitiatorNotFoundException */ protected function execute(InputInterface $input, OutputInterface $output): int { + throw new \Exception('not available'); + $filename = $input->getOption('read'); $local = $input->getOption('local'); $this->output = $output; diff --git a/lib/Command/CirclesTest.php b/lib/Command/CirclesTest.php index 03624a8b0..610d99041 100644 --- a/lib/Command/CirclesTest.php +++ b/lib/Command/CirclesTest.php @@ -31,11 +31,11 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OC\Core\Command\Base; use OCA\Circles\AppInfo\Application; @@ -63,7 +63,7 @@ class CirclesTest extends Base { use TArrayTools; use TStringTools; - use TNC22Deserialize; + use TDeserialize; public static $INSTANCES = [ diff --git a/lib/Command/MembersAdd.php b/lib/Command/MembersAdd.php index b1e0faae3..7496c0362 100644 --- a/lib/Command/MembersAdd.php +++ b/lib/Command/MembersAdd.php @@ -31,13 +31,13 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestContentException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultNotJsonException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultSizeException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestServerException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; +use OCA\Circles\Tools\Exceptions\RequestContentException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\RequestResultNotJsonException; +use OCA\Circles\Tools\Exceptions\RequestResultSizeException; +use OCA\Circles\Tools\Exceptions\RequestServerException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; use Exception; use OC\Core\Command\Base; use OCA\Circles\Exceptions\FederatedItemException; @@ -162,7 +162,7 @@ private function findUserFromLookup(string $search, string &$instance = ''): str return ''; } - $request = new NC22Request(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); + $request = new NCRequest(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); $this->configService->configureRequest($request); $request->basedOnUrl($lookup); $request->addParam('search', $search); diff --git a/lib/Command/MembersList.php b/lib/Command/MembersList.php index 0a53415da..a7aa75d5e 100644 --- a/lib/Command/MembersList.php +++ b/lib/Command/MembersList.php @@ -31,15 +31,6 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22TreeNode; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22ConsoleTree; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use Exception; use OC\Core\Command\Base; use OCA\Circles\Db\MemberRequest; @@ -65,6 +56,15 @@ use OCA\Circles\Service\FederatedUserService; use OCA\Circles\Service\MemberService; use OCA\Circles\Service\RemoteService; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\TreeNode; +use OCA\Circles\Tools\Traits\TConsoleTree; +use OCA\Circles\Tools\Traits\TStringTools; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -78,7 +78,7 @@ * @package OCA\Circles\Command */ class MembersList extends Base { - use TNC22ConsoleTree; + use TConsoleTree; use TStringTools; @@ -194,7 +194,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Config: ' . $type); $output->writeln(' '); - $tree = new NC22TreeNode(null, new SimpleDataStore(['circle' => $circle])); + $tree = new TreeNode(null, new SimpleDataStore(['circle' => $circle])); $inherited = false; } @@ -276,7 +276,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * @param string $instance * @param string $initiator * @param int $initiatorType - * @param NC22TreeNode|null $tree + * @param TreeNode|null $tree * @param array $knownIds * * @return array @@ -304,7 +304,7 @@ private function getMembers( string $instance, string $initiator, int $initiatorType, - ?NC22TreeNode $tree, + ?TreeNode $tree, array $knownIds = [] ): array { if (in_array($circleId, $knownIds)) { @@ -359,7 +359,7 @@ private function getMembers( ); $circle = $this->circleService->getCircle($member->getSingleId()); } - $node = new NC22TreeNode( + $node = new TreeNode( $tree, new SimpleDataStore( [ 'circle' => $circle, @@ -379,7 +379,7 @@ private function getMembers( ); } else { if ($this->treeType !== 'circles-only') { - new NC22TreeNode( + new TreeNode( $tree, new SimpleDataStore( [ 'member' => $member, diff --git a/lib/Command/SharesFiles.php b/lib/Command/SharesFiles.php index d51ab0bc4..e0b3a0d34 100644 --- a/lib/Command/SharesFiles.php +++ b/lib/Command/SharesFiles.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Command; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use OC\Core\Command\Base; use OCA\Circles\Exceptions\FederatedUserException; use OCA\Circles\Exceptions\FederatedUserNotFoundException; diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index ed0aefaa6..37d7d31a4 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; use OCA\Circles\Exceptions\ContactFormatException; @@ -64,8 +64,8 @@ * @package OCA\Circles\Controller */ class AdminController extends OcsController { - use TNC22Deserialize; - use TNC22Logger; + use TDeserialize; + use TNCLogger; /** @var IUserSession */ diff --git a/lib/Controller/EventWrapperController.php b/lib/Controller/EventWrapperController.php index ca3466bfa..0e09afe45 100644 --- a/lib/Controller/EventWrapperController.php +++ b/lib/Controller/EventWrapperController.php @@ -31,15 +31,14 @@ namespace OCA\Circles\Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Async; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Controller; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Service\ConfigService; use OCA\Circles\Service\EventWrapperService; use OCA\Circles\Service\FederatedEventService; use OCA\Circles\Service\RemoteDownstreamService; use OCA\Circles\Service\RemoteUpstreamService; +use OCA\Circles\Tools\Traits\TAsync; +use OCA\Circles\Tools\Traits\TStringTools; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -52,8 +51,7 @@ */ class EventWrapperController extends Controller { use TStringTools; - use TNC22Async; - use TNC22Controller; + use TAsync; /** @var EventWrapperService */ diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 4a6ec8225..efa78363b 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OCA\Circles\Exceptions\FederatedUserException; use OCA\Circles\Exceptions\FederatedUserNotFoundException; @@ -62,8 +62,8 @@ * @package OCA\Circles\Controller */ class LocalController extends OcsController { - use TNC22Deserialize; - use TNC22Logger; + use TDeserialize; + use TNCLogger; /** @var IUserSession */ diff --git a/lib/Controller/RemoteController.php b/lib/Controller/RemoteController.php index f04159cc4..990bb3476 100644 --- a/lib/Controller/RemoteController.php +++ b/lib/Controller/RemoteController.php @@ -31,25 +31,13 @@ namespace OCA\Circles\Controller; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidOriginException; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Exceptions\JsonNotRequestedException; -use ArtificialOwl\MySmallPhpTools\Exceptions\MalformedArrayException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatureException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22SignedRequest; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22LocalSignatory; use Exception; use OC\AppFramework\Middleware\Security\Exceptions\NotLoggedInException; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Exceptions\FederatedItemException; use OCA\Circles\Exceptions\FederatedUserException; use OCA\Circles\Exceptions\FederatedUserNotFoundException; +use OCA\Circles\Exceptions\JsonNotRequestedException; use OCA\Circles\Exceptions\UnknownInterfaceException; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Federated\FederatedEvent; @@ -66,10 +54,22 @@ use OCA\Circles\Service\MembershipService; use OCA\Circles\Service\RemoteDownstreamService; use OCA\Circles\Service\RemoteStreamService; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\InvalidOriginException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\MalformedArrayException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\SignatureException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\Model\NCSignedRequest; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLocalSignatory; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +use OCP\IUserSession; /** * Class RemoteController @@ -77,9 +77,8 @@ * @package OCA\Circles\Controller */ class RemoteController extends Controller { - use TNC22Controller; - use TNC22LocalSignatory; - use TNC22Deserialize; + use TNCLocalSignatory; + use TDeserialize; /** @var CircleRequest */ @@ -109,6 +108,8 @@ class RemoteController extends Controller { /** @var ConfigService */ private $configService; + /** @var IUserSession */ + private $userSession; /** * RemoteController constructor. @@ -136,7 +137,8 @@ public function __construct( MemberService $memberService, MembershipService $membershipService, InterfaceService $interfaceService, - ConfigService $configService + ConfigService $configService, + IUserSession $userSession ) { parent::__construct($appName, $request); $this->circleRequest = $circleRequest; @@ -148,6 +150,7 @@ public function __construct( $this->membershipService = $membershipService; $this->interfaceService = $interfaceService; $this->configService = $configService; + $this->userSession = $userSession; $this->setup('app', 'circles'); $this->setupArray('enforceSignatureHeaders', ['digest', 'content-length']); @@ -486,12 +489,12 @@ private function extractDataFromFromRequest(): SimpleDataStore { /** - * @param NC22SignedRequest $signedRequest + * @param NCSignedRequest $signedRequest * * @return RemoteInstance * @throws SignatoryException */ - private function confirmRemoteInstance(NC22SignedRequest $signedRequest): RemoteInstance { + private function confirmRemoteInstance(NCSignedRequest $signedRequest): RemoteInstance { /** @var RemoteInstance $signatory */ $signatory = $signedRequest->getSignatory(); @@ -534,4 +537,74 @@ public function exceptionResponse( ($e->getCode() > 0) ? $e->getCode() : $httpErrorCode ); } + + + /** + * use this one if a method from a Controller is only PublicPage when remote client asking for Json + * + * try { + * $this->publicPageJsonLimited(); + * return new DataResponse(['test' => 42]); + * } catch (JsonNotRequestedException $e) {} + * + * + * @throws NotLoggedInException + * @throws JsonNotRequestedException + */ + private function publicPageJsonLimited(): void { + if (!$this->jsonRequested()) { + if (!$this->userSession->isLoggedIn()) { + throw new NotLoggedInException(); + } + + throw new JsonNotRequestedException(); + } + } + + + /** + * @return bool + */ + private function jsonRequested(): bool { + return ($this->areWithinAcceptHeader( + [ + 'application/json', + 'application/ld+json', + 'application/activity+json' + ] + )); + } + + + /** + * @param array $needles + * + * @return bool + */ + private function areWithinAcceptHeader(array $needles): bool { + $accepts = array_map([$this, 'trimHeader'], explode(',', $this->request->getHeader('Accept'))); + + foreach ($accepts as $accept) { + if (in_array($accept, $needles)) { + return true; + } + } + + return false; + } + + /** + * @param string $header + * + * @return string + */ + private function trimHeader(string $header): string { + $header = trim($header); + $pos = strpos($header, ';'); + if ($pos === false) { + return $header; + } + + return substr($header, 0, $pos); + } } diff --git a/lib/Cron/ContactsExistingShares.php b/lib/Cron/ContactsExistingShares.php index 7362cf171..a71e7bd1c 100644 --- a/lib/Cron/ContactsExistingShares.php +++ b/lib/Cron/ContactsExistingShares.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Cron; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use OC\BackgroundJob\TimedJob; use OC\Share20\Share; use OCA\Circles\AppInfo\Application; diff --git a/lib/Cron/Maintenance.php b/lib/Cron/Maintenance.php index 98588df40..43ba53b53 100644 --- a/lib/Cron/Maintenance.php +++ b/lib/Cron/Maintenance.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Cron; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OC\BackgroundJob\TimedJob; use OCA\Circles\Exceptions\MaintenanceException; use OCA\Circles\Service\ConfigService; diff --git a/lib/Db/AccountsRequest.php b/lib/Db/AccountsRequest.php index 8044af5f5..20557d98c 100644 --- a/lib/Db/AccountsRequest.php +++ b/lib/Db/AccountsRequest.php @@ -27,7 +27,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Exceptions\MemberDoesNotExistException; class AccountsRequest extends AccountsRequestBuilder { diff --git a/lib/Db/AccountsRequestBuilder.php b/lib/Db/AccountsRequestBuilder.php index e6b5d386c..792960e9c 100644 --- a/lib/Db/AccountsRequestBuilder.php +++ b/lib/Db/AccountsRequestBuilder.php @@ -28,7 +28,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use OCP\DB\QueryBuilder\IQueryBuilder; /** diff --git a/lib/Db/CircleRequest.php b/lib/Db/CircleRequest.php index b1e810d3b..1303f480d 100644 --- a/lib/Db/CircleRequest.php +++ b/lib/Db/CircleRequest.php @@ -41,7 +41,6 @@ use OCA\Circles\Model\Circle; use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; -use OCA\Circles\Model\Probes\BasicProbe; use OCA\Circles\Model\Probes\CircleProbe; /** @@ -197,10 +196,6 @@ public function getCircles(?IFederatedUser $initiator, CircleProbe $probe): arra $qb->limitToRemoteInstance(CoreQueryBuilder::CIRCLE, $probe->getFilterRemoteInstance(), false); } - if ($probe->showDetail(BasicProbe::DETAILS_POPULATION)) { - $qb->countMembers(CoreQueryBuilder::CIRCLE); - } - $qb->chunk($probe->getItemsOffset(), $probe->getItemsLimit()); return $this->getItemsFromRequest($qb); @@ -246,7 +241,7 @@ public function getCircle( ->emulateVisitor(); } - $qb = $this->getCircleSelectSql(); + $qb = $this->getCircleSelectSql(CoreQueryBuilder::CIRCLE, true); $qb->setOptions( [CoreQueryBuilder::CIRCLE], array_merge( @@ -275,10 +270,6 @@ public function getCircle( $qb->limitToRemoteInstance(CoreQueryBuilder::CIRCLE, $probe->getFilterRemoteInstance(), false); } - if ($probe->showDetail(BasicProbe::DETAILS_POPULATION)) { - $qb->countMembers(CoreQueryBuilder::CIRCLE); - } - return $this->getItemFromRequest($qb); } @@ -292,7 +283,7 @@ public function getCircle( * @throws FederatedUserNotFoundException */ public function getFederatedUserBySingleId(string $singleId): FederatedUser { - $qb = $this->getCircleSelectSql(); + $qb = $this->getCircleSelectSql(CoreQueryBuilder::CIRCLE, true); $qb->limitToUniqueId($singleId); $qb->leftJoinOwner(CoreQueryBuilder::CIRCLE); diff --git a/lib/Db/CircleRequestBuilder.php b/lib/Db/CircleRequestBuilder.php index 1f707a21a..ea0fbd987 100644 --- a/lib/Db/CircleRequestBuilder.php +++ b/lib/Db/CircleRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Model\Circle; @@ -77,8 +77,7 @@ protected function getCircleSelectSql( bool $single = false ): CoreQueryBuilder { $qb = $this->getQueryBuilder(); - $qb->generateSelect(self::TABLE_CIRCLE, self::$tables[self::TABLE_CIRCLE], $alias, !$single) - ->generateGroupBy(self::$tables[self::TABLE_CIRCLE], $alias); + $qb->generateSelect(self::TABLE_CIRCLE, self::$tables[self::TABLE_CIRCLE], $alias); if (!$single) { $qb->orderBy($alias . '.creation', 'asc'); diff --git a/lib/Db/CoreQueryBuilder.php b/lib/Db/CoreQueryBuilder.php index d9b94b2b1..72dc43590 100644 --- a/lib/Db/CoreQueryBuilder.php +++ b/lib/Db/CoreQueryBuilder.php @@ -31,8 +31,6 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\NC22ExtendedQueryBuilder; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use Doctrine\DBAL\Query\QueryBuilder; use OC; use OCA\Circles\Exceptions\RequestBuilderException; @@ -44,6 +42,8 @@ use OCA\Circles\Model\Member; use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Service\ConfigService; +use OCA\Circles\Tools\Db\ExtendedQueryBuilder; +use OCA\Circles\Tools\Traits\TArrayTools; use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -52,7 +52,7 @@ * * @package OCA\Circles\Db */ -class CoreQueryBuilder extends NC22ExtendedQueryBuilder { +class CoreQueryBuilder extends ExtendedQueryBuilder { use TArrayTools; @@ -267,7 +267,7 @@ public function getInstance(IFederatedModel $federatedModel): string { * @param string $id */ public function limitToCircleId(string $id): void { - $this->limitToDBField('circle_id', $id, true); + $this->limit('circle_id', $id, '', true); } /** @@ -295,14 +295,14 @@ public function limitToSanitizedName(string $name): void { * @param int $config */ public function limitToConfig(int $config): void { - $this->limitToDBFieldInt('config', $config); + $this->limitInt('config', $config); } /** * @param int $source */ public function limitToSource(int $source): void { - $this->limitToDBFieldInt('source', $source); + $this->limitInt('source', $source); } /** @@ -318,7 +318,7 @@ public function limitToConfigFlag(int $config, string $alias = ''): void { * @param string $singleId */ public function limitToSingleId(string $singleId): void { - $this->limitToDBField('single_id', $singleId, true); + $this->limit('single_id', $singleId, '', true); } @@ -326,7 +326,7 @@ public function limitToSingleId(string $singleId): void { * @param string $itemId */ public function limitToItemId(string $itemId): void { - $this->limitToDBField('item_id', $itemId, true); + $this->limit('item_id', $itemId, '', true); } @@ -334,7 +334,7 @@ public function limitToItemId(string $itemId): void { * @param string $host */ public function limitToInstance(string $host): void { - $this->limitToDBField('instance', $host, false); + $this->limit('instance', $host, '', false); } @@ -342,7 +342,7 @@ public function limitToInstance(string $host): void { * @param int $userType */ public function limitToUserType(int $userType): void { - $this->limitToDBFieldInt('user_type', $userType); + $this->limitInt('user_type', $userType); } @@ -350,7 +350,7 @@ public function limitToUserType(int $userType): void { * @param int $shareType */ public function limitToShareType(int $shareType): void { - $this->limitToDBFieldInt('share_type', $shareType); + $this->limitInt('share_type', $shareType); } @@ -358,7 +358,7 @@ public function limitToShareType(int $shareType): void { * @param string $shareWith */ public function limitToShareWith(string $shareWith): void { - $this->limitToDBField('share_with', $shareWith); + $this->limit('share_with', $shareWith, '', true); } @@ -366,14 +366,14 @@ public function limitToShareWith(string $shareWith): void { * @param int $nodeId */ public function limitToFileSource(int $nodeId): void { - $this->limitToDBFieldInt('file_source', $nodeId); + $this->limitInt('file_source', $nodeId); } /** * @param array $files */ public function limitToFileSourceArray(array $files): void { - $this->limitToDBFieldInArray('file_source', $files); + $this->limitArray('file_source', $files); } @@ -381,7 +381,7 @@ public function limitToFileSourceArray(array $files): void { * @param int $shareId */ public function limitToShareParent(int $shareId): void { - $this->limitToDBFieldInt('parent', $shareId); + $this->limitInt('parent', $shareId); } @@ -678,9 +678,7 @@ public function filterDirectMembership(string $aliasMember, Member $member): voi ); } - $andX->add( - $expr->eq($aliasMember . '.instance', $this->createNamedParameter($this->getInstance($member))) - ); + $this->limitToInstance($this->getInstance($member)); if ($member->getLevel() > 0) { $andX->add( @@ -695,32 +693,6 @@ public function filterDirectMembership(string $aliasMember, Member $member): voi } - /** - * @param string $alias - */ - public function countMembers(string $alias): void { - if ($this->getType() !== QueryBuilder::SELECT) { - return; - } - - try { - $aliasMemberCount = $this->generateAlias($alias, self::MEMBER_COUNT, $options); - } catch (RequestBuilderException $e) { - return; - } - - $expr = $this->expr(); - $this->selectAlias( - $this->createFunction('COUNT(`' . $aliasMemberCount . '`.`member_id`)'), - (($alias !== $this->getDefaultSelectAlias()) ? $alias . '_' : '') . 'population' - ); - $this->leftJoin( - $alias, CoreRequestBuilder::TABLE_MEMBER, $aliasMemberCount, - $expr->eq($alias . '.unique_id', $aliasMemberCount . '.circle_id') - ); - } - - /** * @param string $alias * @param IFederatedUser|null $initiator diff --git a/lib/Db/DeprecatedMembersRequest.php b/lib/Db/DeprecatedMembersRequest.php index c452bf46b..8a0be9cb6 100644 --- a/lib/Db/DeprecatedMembersRequest.php +++ b/lib/Db/DeprecatedMembersRequest.php @@ -27,7 +27,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Exception; use OCA\Circles\Exceptions\GSStatusException; diff --git a/lib/Db/EventWrapperRequestBuilder.php b/lib/Db/EventWrapperRequestBuilder.php index 3f5c5cc98..2e060e9ef 100644 --- a/lib/Db/EventWrapperRequestBuilder.php +++ b/lib/Db/EventWrapperRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\EventWrapperNotFoundException; use OCA\Circles\Model\Federated\EventWrapper; diff --git a/lib/Db/GSSharesRequest.php b/lib/Db/GSSharesRequest.php index c0054e673..9fa9944f7 100644 --- a/lib/Db/GSSharesRequest.php +++ b/lib/Db/GSSharesRequest.php @@ -27,7 +27,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Model\GlobalScale\GSShare; use OCA\Circles\Model\GlobalScale\GSShareMountpoint; use OCA\Circles\Model\DeprecatedMember; diff --git a/lib/Db/MemberRequest.php b/lib/Db/MemberRequest.php index 1d5489076..98ededbc7 100644 --- a/lib/Db/MemberRequest.php +++ b/lib/Db/MemberRequest.php @@ -279,8 +279,7 @@ public function getInheritedMembers(string $singleId, bool $getData = false, int $qb->limitToMembersByInheritance(CoreQueryBuilder::MEMBER, $singleId, $level); $aliasMembership = $qb->generateAlias(CoreQueryBuilder::MEMBER, CoreQueryBuilder::MEMBERSHIPS); - $qb->orderBy($aliasMembership . '.inheritance_depth', 'asc') - ->addGroupBy($aliasMembership . '.inheritance_depth'); + $qb->orderBy($aliasMembership . '.inheritance_depth', 'asc'); return $this->getItemsFromRequest($qb); } diff --git a/lib/Db/MemberRequestBuilder.php b/lib/Db/MemberRequestBuilder.php index f61d610c9..6e87c0bb6 100644 --- a/lib/Db/MemberRequestBuilder.php +++ b/lib/Db/MemberRequestBuilder.php @@ -31,12 +31,12 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\MemberNotFoundException; use OCA\Circles\Exceptions\RequestBuilderException; use OCA\Circles\IFederatedUser; use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; /** * Class MemberRequestBuilder @@ -86,7 +86,6 @@ protected function getMemberSelectSql( self::$tables[self::TABLE_MEMBER], CoreQueryBuilder::MEMBER ) - ->generateGroupBy(self::$tables[self::TABLE_MEMBER], CoreQueryBuilder::MEMBER) ->orderBy(CoreQueryBuilder::MEMBER . '.joined'); if ($getBasedOn) { diff --git a/lib/Db/MembershipRequestBuilder.php b/lib/Db/MembershipRequestBuilder.php index 1363d692e..a6a2ed320 100644 --- a/lib/Db/MembershipRequestBuilder.php +++ b/lib/Db/MembershipRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\MembershipNotFoundException; use OCA\Circles\Model\Membership; diff --git a/lib/Db/MountRequest.php b/lib/Db/MountRequest.php index 7aaebe5f6..af1ee0cc9 100644 --- a/lib/Db/MountRequest.php +++ b/lib/Db/MountRequest.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Exceptions\RequestBuilderException; use OCA\Circles\IFederatedUser; use OCA\Circles\Model\Mount; diff --git a/lib/Db/MountRequestBuilder.php b/lib/Db/MountRequestBuilder.php index 0625dbb78..ecdc677da 100644 --- a/lib/Db/MountRequestBuilder.php +++ b/lib/Db/MountRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\MountNotFoundException; use OCA\Circles\Model\Mount; diff --git a/lib/Db/RemoteRequest.php b/lib/Db/RemoteRequest.php index a6d3fd19e..92b005cc1 100644 --- a/lib/Db/RemoteRequest.php +++ b/lib/Db/RemoteRequest.php @@ -95,7 +95,7 @@ public function updateItem(RemoteInstance $remote) { $qb = $this->getRemoteUpdateSql(); $qb->set('item', $qb->createNamedParameter(json_encode($remote->getOrigData()))); - $qb->limitToDBField('uid', $remote->getUid(true), false); + $qb->limit('uid', $remote->getUid(true), '', false); $qb->execute(); } @@ -111,7 +111,7 @@ public function updateInstance(RemoteInstance $remote) { $qb = $this->getRemoteUpdateSql(); $qb->set('instance', $qb->createNamedParameter($remote->getInstance())); - $qb->limitToDBField('uid', $remote->getUid(true), false); + $qb->limit('uid', $remote->getUid(true), '', false); $qb->execute(); } @@ -127,7 +127,7 @@ public function updateType(RemoteInstance $remote) { $qb = $this->getRemoteUpdateSql(); $qb->set('type', $qb->createNamedParameter($remote->getType())); - $qb->limitToDBField('uid', $remote->getUid(true), false); + $qb->limit('uid', $remote->getUid(true), '', false); $qb->execute(); } @@ -143,7 +143,7 @@ public function updateHref(RemoteInstance $remote) { $qb = $this->getRemoteUpdateSql(); $qb->set('href', $qb->createNamedParameter($remote->getId())); - $qb->limitToDBField('uid', $remote->getUid(true), false); + $qb->limit('uid', $remote->getUid(true), '', false); $qb->execute(); } @@ -163,7 +163,7 @@ public function getAllInstances(): array { */ public function getKnownInstances(): array { $qb = $this->getRemoteSelectSql(); - $qb->filterDBField('type', RemoteInstance::TYPE_UNKNOWN, false); + $qb->filter('type', RemoteInstance::TYPE_UNKNOWN, '', false); return $this->getItemsFromRequest($qb); } @@ -186,12 +186,12 @@ public function getOutgoingRecipient(Circle $circle, bool $broadcastAsFederated $expr = $qb->expr(); $orX = $expr->orX(); - $orX->add($qb->exprLimitToDBField('type', RemoteInstance::TYPE_GLOBALSCALE, true, false)); + $orX->add($qb->exprLimit('type', RemoteInstance::TYPE_GLOBALSCALE, '', false)); if ($circle->isConfig(Circle::CFG_FEDERATED) || $broadcastAsFederated) { // get all TRUSTED - $orX->add($qb->exprLimitToDBField('type', RemoteInstance::TYPE_TRUSTED, true, false)); + $orX->add($qb->exprLimit('type', RemoteInstance::TYPE_TRUSTED, '', false)); // get EXTERNAL with Members $aliasMember = $qb->generateAlias(CoreQueryBuilder::REMOTE, CoreQueryBuilder::MEMBER); @@ -208,13 +208,12 @@ public function getOutgoingRecipient(Circle $circle, bool $broadcastAsFederated ); $external = $expr->andX(); - $external->add($qb->exprLimitToDBField('type', RemoteInstance::TYPE_EXTERNAL, true, false)); + $external->add($qb->exprLimit('type', RemoteInstance::TYPE_EXTERNAL, '', false)); $external->add($expr->isNotNull($aliasMember . '.instance')); $orX->add($external); } - $qb->andWhere($orX) - ->generateGroupBy(self::$tables[self::TABLE_REMOTE], CoreQueryBuilder::REMOTE); + $qb->andWhere($orX); return $this->getItemsFromRequest($qb); } @@ -242,7 +241,7 @@ public function getFromInstance(string $host): RemoteInstance { */ public function getFromHref(string $href): RemoteInstance { $qb = $this->getRemoteSelectSql(); - $qb->limitToDBField('href', $href, false); + $qb->limit('href', $href, '', false); return $this->getItemFromRequest($qb); } @@ -267,12 +266,12 @@ public function getFromType(string $status): array { * @return RemoteInstance * @throws RemoteNotFoundException */ - public function searchDuplicate(RemoteInstance $remoteInstance) { + public function searchDuplicate(RemoteInstance $remoteInstance): RemoteInstance { $qb = $this->getRemoteSelectSql(); $orX = $qb->expr()->orX(); - $orX->add($qb->exprLimitToDBField('href', $remoteInstance->getId(), true, false)); - $orX->add($qb->exprLimitToDBField('uid', $remoteInstance->getUid(true), true)); - $orX->add($qb->exprLimitToDBField('instance', $remoteInstance->getInstance(), true, false)); + $orX->add($qb->exprLimit('href', $remoteInstance->getId(), '', false)); + $orX->add($qb->exprLimit('uid', $remoteInstance->getUid(true), '', false)); + $orX->add($qb->exprLimit('instance', $remoteInstance->getInstance(), '', false)); $qb->andWhere($orX); return $this->getItemFromRequest($qb); diff --git a/lib/Db/RemoteRequestBuilder.php b/lib/Db/RemoteRequestBuilder.php index d178ffcf0..847461097 100644 --- a/lib/Db/RemoteRequestBuilder.php +++ b/lib/Db/RemoteRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\RemoteNotFoundException; use OCA\Circles\Model\Federated\RemoteInstance; diff --git a/lib/Db/ShareLockRequestBuilder.php b/lib/Db/ShareLockRequestBuilder.php index 10d8ecb8e..ae9a90c75 100644 --- a/lib/Db/ShareLockRequestBuilder.php +++ b/lib/Db/ShareLockRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\FederatedShareNotFoundException; use OCA\Circles\Model\Federated\FederatedShare; diff --git a/lib/Db/ShareTokenRequestBuilder.php b/lib/Db/ShareTokenRequestBuilder.php index 076b2e399..ea3519f45 100644 --- a/lib/Db/ShareTokenRequestBuilder.php +++ b/lib/Db/ShareTokenRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OCA\Circles\Exceptions\ShareTokenNotFoundException; use OCA\Circles\Model\ShareToken; @@ -72,8 +72,7 @@ protected function getTokenUpdateSql(): CoreQueryBuilder { */ protected function getTokenSelectSql(string $alias = CoreQueryBuilder::TOKEN): CoreQueryBuilder { $qb = $this->getQueryBuilder(); - $qb->generateSelect(self::TABLE_TOKEN, self::$tables[self::TABLE_TOKEN], $alias) - ->generateGroupBy(self::$tables[self::TABLE_TOKEN], $alias); + $qb->generateSelect(self::TABLE_TOKEN, self::$tables[self::TABLE_TOKEN], $alias); return $qb; } diff --git a/lib/Db/ShareWrapperRequest.php b/lib/Db/ShareWrapperRequest.php index 7625bee07..e86623deb 100644 --- a/lib/Db/ShareWrapperRequest.php +++ b/lib/Db/ShareWrapperRequest.php @@ -187,12 +187,6 @@ public function getSharesToCircle( $aliasMembership = $qb->generateAlias($aliasUpstreamMembership, CoreQueryBuilder::MEMBERSHIPS); $qb->leftJoinFileCache(CoreQueryBuilder::SHARE); $qb->leftJoinShareChild(CoreQueryBuilder::SHARE, $aliasMembership); - - $qb->generateGroupBy( - self::$tables[self::TABLE_MEMBERSHIP], - $aliasMembership, - true - ); } return $this->getItemsFromRequest($qb); @@ -283,12 +277,6 @@ public function getSharesByFileId(int $fileId, bool $getData = false): array { $aliasMembership = $qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::MEMBERSHIPS); $qb->leftJoinInheritedMembers(CoreQueryBuilder::SHARE, 'share_with'); $qb->leftJoinShareChild(CoreQueryBuilder::SHARE); - - $qb->generateGroupBy( - self::$tables[self::TABLE_MEMBERSHIP], - $aliasMembership, - true - ); } return $this->getItemsFromRequest($qb); @@ -377,11 +365,6 @@ public function getSharesBy( $qb->leftJoinInheritedMembers(CoreQueryBuilder::SHARE, 'share_with'); $qb->leftJoinFileCache(CoreQueryBuilder::SHARE); $qb->leftJoinShareChild(CoreQueryBuilder::SHARE, $aliasMembership); - $qb->generateGroupBy( - self::$tables[self::TABLE_MEMBERSHIP], - $aliasMembership, - true - ); } $qb->chunk($offset, $limit); diff --git a/lib/Db/ShareWrapperRequestBuilder.php b/lib/Db/ShareWrapperRequestBuilder.php index ce0a4e84a..877621432 100644 --- a/lib/Db/ShareWrapperRequestBuilder.php +++ b/lib/Db/ShareWrapperRequestBuilder.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; use OC\Share20\Share; use OCA\Circles\Exceptions\ShareWrapperNotFoundException; use OCA\Circles\Model\ShareWrapper; @@ -74,7 +74,6 @@ protected function getShareUpdateSql(): CoreQueryBuilder { protected function getShareSelectSql(string $alias = CoreQueryBuilder::SHARE): CoreQueryBuilder { $qb = $this->getQueryBuilder(); $qb->generateSelect(self::TABLE_SHARE, self::$outsideTables[self::TABLE_SHARE], $alias) - ->generateGroupBy(self::$outsideTables[self::TABLE_SHARE], $alias) ->limitToShareType(Share::TYPE_CIRCLE); return $qb; diff --git a/lib/Db/TokensRequestBuilder.php b/lib/Db/TokensRequestBuilder.php index 2c08f2d6b..e87c6e1cc 100644 --- a/lib/Db/TokensRequestBuilder.php +++ b/lib/Db/TokensRequestBuilder.php @@ -28,8 +28,8 @@ namespace OCA\Circles\Db; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use OCA\Circles\Model\SharesToken; +use OCA\Circles\Tools\Traits\TArrayTools; use OCP\DB\QueryBuilder\IQueryBuilder; /** diff --git a/lib/Events/CircleResultGenericEvent.php b/lib/Events/CircleResultGenericEvent.php index 59ff21ae7..26a93b150 100644 --- a/lib/Events/CircleResultGenericEvent.php +++ b/lib/Events/CircleResultGenericEvent.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Events; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Federated\FederatedEvent; use OCA\Circles\Model\Member; diff --git a/lib/Events/Files/FileShareCreatedEvent.php b/lib/Events/Files/FileShareCreatedEvent.php index df056c7d9..b0d1ff202 100644 --- a/lib/Events/Files/FileShareCreatedEvent.php +++ b/lib/Events/Files/FileShareCreatedEvent.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Events\Files; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OCA\Circles\Events\CircleResultGenericEvent; use OCA\Circles\Model\Federated\FederatedEvent; diff --git a/lib/Exceptions/JsonNotRequestedException.php b/lib/Exceptions/JsonNotRequestedException.php new file mode 100644 index 000000000..718bd8ec4 --- /dev/null +++ b/lib/Exceptions/JsonNotRequestedException.php @@ -0,0 +1,34 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Circles\Exceptions; + +class JsonNotRequestedException extends FederatedItemNotFoundException { +} diff --git a/lib/FederatedItems/CircleConfig.php b/lib/FederatedItems/CircleConfig.php index 8287bd206..fceefd03b 100644 --- a/lib/FederatedItems/CircleConfig.php +++ b/lib/FederatedItems/CircleConfig.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Exceptions\FederatedItemBadRequestException; use OCA\Circles\Exceptions\FederatedItemException; @@ -50,7 +50,7 @@ class CircleConfig implements IFederatedItem, IFederatedItemAsyncProcess { - use TNC22Deserialize; + use TDeserialize; /** @var CircleRequest */ diff --git a/lib/FederatedItems/CircleCreate.php b/lib/FederatedItems/CircleCreate.php index eab1d4bc2..5f2803016 100644 --- a/lib/FederatedItems/CircleCreate.php +++ b/lib/FederatedItems/CircleCreate.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\CircleNotFoundException; @@ -58,7 +58,7 @@ class CircleCreate implements IFederatedItemHighSeverity, IFederatedItemCircleCheckNotRequired, IFederatedItemMustBeInitializedLocally { - use TNC22Deserialize; + use TDeserialize; /** @var CircleRequest */ diff --git a/lib/FederatedItems/CircleDestroy.php b/lib/FederatedItems/CircleDestroy.php index 1672d27d8..c074f1734 100644 --- a/lib/FederatedItems/CircleDestroy.php +++ b/lib/FederatedItems/CircleDestroy.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\RequestBuilderException; @@ -54,7 +54,7 @@ class CircleDestroy implements IFederatedItemHighSeverity, IFederatedItemAsyncProcess, IFederatedItemMemberEmpty { - use TNC22Deserialize; + use TDeserialize; /** @var CircleRequest */ diff --git a/lib/FederatedItems/CircleEdit.php b/lib/FederatedItems/CircleEdit.php index 2a73b37bf..d41b59e8a 100644 --- a/lib/FederatedItems/CircleEdit.php +++ b/lib/FederatedItems/CircleEdit.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Exceptions\CircleNameTooShortException; use OCA\Circles\Exceptions\RequestBuilderException; @@ -47,7 +47,7 @@ * @package OCA\Circles\FederatedItems */ class CircleEdit implements IFederatedItem { - use TNC22Deserialize; + use TDeserialize; /** @var CircleRequest */ diff --git a/lib/FederatedItems/CircleJoin.php b/lib/FederatedItems/CircleJoin.php index d98d2a9ac..3fbcedbb0 100644 --- a/lib/FederatedItems/CircleJoin.php +++ b/lib/FederatedItems/CircleJoin.php @@ -31,9 +31,9 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\FederatedItemBadRequestException; @@ -77,8 +77,8 @@ class CircleJoin implements IFederatedItemMemberCheckNotRequired, IFederatedItemMemberOptional { use TStringTools; - use TNC22Logger; - use TNC22Deserialize; + use TNCLogger; + use TDeserialize; /** @var IUserManager */ diff --git a/lib/FederatedItems/CircleLeave.php b/lib/FederatedItems/CircleLeave.php index c01734764..1fb749677 100644 --- a/lib/FederatedItems/CircleLeave.php +++ b/lib/FederatedItems/CircleLeave.php @@ -31,8 +31,8 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; @@ -67,8 +67,8 @@ class CircleLeave implements IFederatedItemAsyncProcess, IFederatedItemInitiatorMembershipNotRequired, IFederatedItemMemberOptional { - use TNC22Deserialize; - use TNC22Logger; + use TDeserialize; + use TNCLogger; /** @var MemberRequest */ diff --git a/lib/FederatedItems/CircleSettings.php b/lib/FederatedItems/CircleSettings.php index 4f58f588a..0521c23f5 100644 --- a/lib/FederatedItems/CircleSettings.php +++ b/lib/FederatedItems/CircleSettings.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\CircleRequest; use OCA\Circles\IFederatedItem; use OCA\Circles\Model\Federated\FederatedEvent; @@ -42,7 +42,7 @@ * @package OCA\Circles\FederatedItems */ class CircleSettings implements IFederatedItem { - use TNC22Deserialize; + use TDeserialize; /** @var CircleRequest */ diff --git a/lib/FederatedItems/Files/FileShare.php b/lib/FederatedItems/Files/FileShare.php index b531ada57..58bbd49e2 100644 --- a/lib/FederatedItems/Files/FileShare.php +++ b/lib/FederatedItems/Files/FileShare.php @@ -31,10 +31,10 @@ namespace OCA\Circles\FederatedItems\Files; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\MountRequest; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\IFederatedItem; @@ -58,7 +58,7 @@ class FileShare implements IFederatedItemAsyncProcess, IFederatedItemMemberEmpty { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var MountRequest */ diff --git a/lib/FederatedItems/Files/FileUnshare.php b/lib/FederatedItems/Files/FileUnshare.php index d9520651c..b98a6dc1e 100644 --- a/lib/FederatedItems/Files/FileUnshare.php +++ b/lib/FederatedItems/Files/FileUnshare.php @@ -31,11 +31,11 @@ namespace OCA\Circles\FederatedItems\Files; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\MountRequest; use OCA\Circles\IFederatedItem; use OCA\Circles\IFederatedItemAsyncProcess; @@ -57,7 +57,7 @@ class FileUnshare implements IFederatedItemAsyncProcess, IFederatedItemMemberEmpty { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var MountRequest */ diff --git a/lib/FederatedItems/ItemLock.php b/lib/FederatedItems/ItemLock.php index 0babe32bc..f3254a66d 100644 --- a/lib/FederatedItems/ItemLock.php +++ b/lib/FederatedItems/ItemLock.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\ShareLockRequest; use OCA\Circles\Exceptions\FederatedShareNotFoundException; use OCA\Circles\Exceptions\InvalidIdException; diff --git a/lib/FederatedItems/LoopbackTest.php b/lib/FederatedItems/LoopbackTest.php index fce737a5b..8b1a692fa 100644 --- a/lib/FederatedItems/LoopbackTest.php +++ b/lib/FederatedItems/LoopbackTest.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OCA\Circles\IFederatedItem; use OCA\Circles\IFederatedItemAsyncProcess; use OCA\Circles\IFederatedItemLoopbackTest; diff --git a/lib/FederatedItems/MassiveMemberAdd.php b/lib/FederatedItems/MassiveMemberAdd.php index 31af12989..fe1f27b4b 100644 --- a/lib/FederatedItems/MassiveMemberAdd.php +++ b/lib/FederatedItems/MassiveMemberAdd.php @@ -31,8 +31,8 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\IFederatedItem; use OCA\Circles\IFederatedItemAsyncProcess; @@ -54,7 +54,7 @@ class MassiveMemberAdd extends SingleMemberAdd implements IFederatedItemHighSeverity, IFederatedItemMemberEmpty { use TStringTools; - use TNC22Logger; + use TNCLogger; /** diff --git a/lib/FederatedItems/MemberDisplayName.php b/lib/FederatedItems/MemberDisplayName.php index 228077958..2f5941f3a 100644 --- a/lib/FederatedItems/MemberDisplayName.php +++ b/lib/FederatedItems/MemberDisplayName.php @@ -31,7 +31,6 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\FederatedItemBadRequestException; use OCA\Circles\Exceptions\FederatedItemException; @@ -44,6 +43,7 @@ use OCA\Circles\Service\EventService; use OCA\Circles\Service\MembershipService; use OCA\Circles\StatusCode; +use OCA\Circles\Tools\Traits\TDeserialize; /** * Class MemberDisplayName @@ -54,7 +54,7 @@ class MemberDisplayName implements IFederatedItem, IFederatedItemHighSeverity, IFederatedItemMemberEmpty { - use TNC22Deserialize; + use TDeserialize; /** @var MemberRequest */ @@ -99,7 +99,8 @@ public function __construct( * @throws MemberLevelException */ public function verify(FederatedEvent $event): void { - $member = $event->getCircle()->getInitiator(); + $member = $event->getCircle() + ->getInitiator(); $displayName = $event->getParams()->g('displayName'); diff --git a/lib/FederatedItems/MemberLevel.php b/lib/FederatedItems/MemberLevel.php index af3b1f281..c1a368176 100644 --- a/lib/FederatedItems/MemberLevel.php +++ b/lib/FederatedItems/MemberLevel.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; +use OCA\Circles\Tools\Traits\TDeserialize; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\FederatedItemBadRequestException; use OCA\Circles\Exceptions\FederatedItemException; @@ -57,7 +57,7 @@ class MemberLevel implements IFederatedItem, IFederatedItemHighSeverity, IFederatedItemMemberRequired { - use TNC22Deserialize; + use TDeserialize; /** @var MemberRequest */ diff --git a/lib/FederatedItems/SharedItemsSync.php b/lib/FederatedItems/SharedItemsSync.php index c69323a5e..ff7edcc58 100644 --- a/lib/FederatedItems/SharedItemsSync.php +++ b/lib/FederatedItems/SharedItemsSync.php @@ -31,7 +31,7 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OCA\Circles\IFederatedItem; use OCA\Circles\IFederatedItemLimitedToInstanceWithMembership; use OCA\Circles\Model\Federated\FederatedEvent; diff --git a/lib/FederatedItems/SingleMemberAdd.php b/lib/FederatedItems/SingleMemberAdd.php index 239f7baed..bc9399a41 100644 --- a/lib/FederatedItems/SingleMemberAdd.php +++ b/lib/FederatedItems/SingleMemberAdd.php @@ -31,9 +31,9 @@ namespace OCA\Circles\FederatedItems; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\FederatedItemBadRequestException; @@ -86,11 +86,11 @@ class SingleMemberAdd implements IFederatedItemHighSeverity, IFederatedItemMemberRequired, IFederatedItemMemberCheckNotRequired { - use TNC22Deserialize; + use TDeserialize; use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IUserManager */ diff --git a/lib/GlobalScale/FileShare.php b/lib/GlobalScale/FileShare.php index 2a2da0a37..4a1a089c2 100644 --- a/lib/GlobalScale/FileShare.php +++ b/lib/GlobalScale/FileShare.php @@ -31,8 +31,8 @@ namespace OCA\Circles\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC; use OC\Share20\Share; diff --git a/lib/GlobalScale/GSMount/Mount.php b/lib/GlobalScale/GSMount/Mount.php index 002d19bde..21eae9738 100644 --- a/lib/GlobalScale/GSMount/Mount.php +++ b/lib/GlobalScale/GSMount/Mount.php @@ -31,7 +31,7 @@ namespace OCA\Circles\GlobalScale\GSMount; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC\Files\Mount\MountPoint; use OC\Files\Mount\MoveableMount; diff --git a/lib/GlobalScale/GSMount/MountProvider.php b/lib/GlobalScale/GSMount/MountProvider.php index 3f18ca554..947737292 100644 --- a/lib/GlobalScale/GSMount/MountProvider.php +++ b/lib/GlobalScale/GSMount/MountProvider.php @@ -31,7 +31,7 @@ namespace OCA\Circles\GlobalScale\GSMount; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC; use OCA\Circles\Db\GSSharesRequest; diff --git a/lib/GlobalScale/MemberAdd.php b/lib/GlobalScale/MemberAdd.php index 288f02f56..26b4e8bbc 100644 --- a/lib/GlobalScale/MemberAdd.php +++ b/lib/GlobalScale/MemberAdd.php @@ -31,7 +31,7 @@ namespace OCA\Circles\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use Exception; use OC\User\NoUserException; use OCA\Circles\Exceptions\CircleDoesNotExistException; diff --git a/lib/GlobalScale/Test.php b/lib/GlobalScale/Test.php index c0f2f96d5..4d4191108 100644 --- a/lib/GlobalScale/Test.php +++ b/lib/GlobalScale/Test.php @@ -31,7 +31,7 @@ namespace OCA\Circles\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use OCA\Circles\Model\GlobalScale\GSEvent; /** diff --git a/lib/Handlers/WebfingerHandler.php b/lib/Handlers/WebfingerHandler.php index d3449db6d..f3dbd56c6 100644 --- a/lib/Handlers/WebfingerHandler.php +++ b/lib/Handlers/WebfingerHandler.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Handlers; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Traits\TArrayTools; use OC\URLGenerator; use OCA\Circles\AppInfo\Application; use OCA\Circles\Exceptions\UnknownInterfaceException; diff --git a/lib/IFederatedSync.php b/lib/IFederatedSync.php index 38fe24385..25683e685 100644 --- a/lib/IFederatedSync.php +++ b/lib/IFederatedSync.php @@ -31,7 +31,7 @@ namespace OCA\Circles; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; /** * Interface IFederatedSync diff --git a/lib/Listeners/Examples/ExampleAddingCircleMember.php b/lib/Listeners/Examples/ExampleAddingCircleMember.php index 3e8f51954..e023f068f 100644 --- a/lib/Listeners/Examples/ExampleAddingCircleMember.php +++ b/lib/Listeners/Examples/ExampleAddingCircleMember.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Listeners\Examples; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\AddingCircleMemberEvent; use OCA\Circles\Events\CircleGenericEvent; @@ -47,7 +47,7 @@ * @package OCA\Circles\Listeners\Files */ class ExampleAddingCircleMember implements IEventListener { - use TNC22Logger; + use TNCLogger; /** @var ConfigService */ diff --git a/lib/Listeners/Examples/ExampleMembershipsCreated.php b/lib/Listeners/Examples/ExampleMembershipsCreated.php index 441e68aa3..6218ddaf6 100644 --- a/lib/Listeners/Examples/ExampleMembershipsCreated.php +++ b/lib/Listeners/Examples/ExampleMembershipsCreated.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Examples; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\CirclesManager; @@ -50,7 +50,7 @@ */ class ExampleMembershipsCreated implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var CirclesManager */ diff --git a/lib/Listeners/Examples/ExampleMembershipsRemoved.php b/lib/Listeners/Examples/ExampleMembershipsRemoved.php index a46901ad2..7458ece14 100644 --- a/lib/Listeners/Examples/ExampleMembershipsRemoved.php +++ b/lib/Listeners/Examples/ExampleMembershipsRemoved.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Examples; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\CirclesManager; @@ -50,7 +50,7 @@ */ class ExampleMembershipsRemoved implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var CirclesManager */ diff --git a/lib/Listeners/Examples/ExampleRequestingCircleMember.php b/lib/Listeners/Examples/ExampleRequestingCircleMember.php index da1053dd7..aebe9260f 100644 --- a/lib/Listeners/Examples/ExampleRequestingCircleMember.php +++ b/lib/Listeners/Examples/ExampleRequestingCircleMember.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Listeners\Examples; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\CircleGenericEvent; use OCA\Circles\Events\RequestingCircleMemberEvent; @@ -46,7 +46,7 @@ * @package OCA\Circles\Listeners\Examples */ class ExampleRequestingCircleMember implements IEventListener { - use TNC22Logger; + use TNCLogger; /** @var ConfigService */ diff --git a/lib/Listeners/Files/AddingMemberSendMail.php b/lib/Listeners/Files/AddingMemberSendMail.php index 15992d954..a1dcbb07d 100644 --- a/lib/Listeners/Files/AddingMemberSendMail.php +++ b/lib/Listeners/Files/AddingMemberSendMail.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\AddingCircleMemberEvent; @@ -52,7 +52,7 @@ */ class AddingMemberSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Files/CreatingShareSendMail.php b/lib/Listeners/Files/CreatingShareSendMail.php index 532eac91e..6e72b9f3c 100644 --- a/lib/Listeners/Files/CreatingShareSendMail.php +++ b/lib/Listeners/Files/CreatingShareSendMail.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\Files\CreatingFileShareEvent; @@ -59,7 +59,7 @@ */ class CreatingShareSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Files/DestroyingCircle.php b/lib/Listeners/Files/DestroyingCircle.php index 81181e65e..9d19f10ed 100644 --- a/lib/Listeners/Files/DestroyingCircle.php +++ b/lib/Listeners/Files/DestroyingCircle.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\DestroyingCircleEvent; use OCA\Circles\Exceptions\RequestBuilderException; @@ -47,7 +47,7 @@ */ class DestroyingCircle implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Files/MemberAddedSendMail.php b/lib/Listeners/Files/MemberAddedSendMail.php index 833fa5151..738e9e3fb 100644 --- a/lib/Listeners/Files/MemberAddedSendMail.php +++ b/lib/Listeners/Files/MemberAddedSendMail.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\CircleMemberAddedEvent; use OCA\Circles\Model\Member; @@ -50,7 +50,7 @@ */ class MemberAddedSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Files/MembershipsRemoved.php b/lib/Listeners/Files/MembershipsRemoved.php index 0f1331438..78fd23a7d 100644 --- a/lib/Listeners/Files/MembershipsRemoved.php +++ b/lib/Listeners/Files/MembershipsRemoved.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\CirclesManager; use OCA\Circles\Db\ShareWrapperRequest; use OCA\Circles\Events\MembershipsRemovedEvent; diff --git a/lib/Listeners/Files/PreparingMemberSendMail.php b/lib/Listeners/Files/PreparingMemberSendMail.php index b473984fd..5b557d375 100644 --- a/lib/Listeners/Files/PreparingMemberSendMail.php +++ b/lib/Listeners/Files/PreparingMemberSendMail.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\PreparingCircleMemberEvent; use OCA\Circles\Exceptions\FederatedItemException; @@ -57,7 +57,7 @@ */ class PreparingMemberSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Files/PreparingShareSendMail.php b/lib/Listeners/Files/PreparingShareSendMail.php index 233349a60..9ae0ded73 100644 --- a/lib/Listeners/Files/PreparingShareSendMail.php +++ b/lib/Listeners/Files/PreparingShareSendMail.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\Files\PreparingFileShareEvent; use OCA\Circles\Exceptions\FederatedItemException; @@ -58,7 +58,7 @@ */ class PreparingShareSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IHasher */ diff --git a/lib/Listeners/Files/RemovingMember.php b/lib/Listeners/Files/RemovingMember.php index 7de96a4b3..e6e3ff371 100644 --- a/lib/Listeners/Files/RemovingMember.php +++ b/lib/Listeners/Files/RemovingMember.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\RemovingCircleMemberEvent; use OCA\Circles\Exceptions\MembershipNotFoundException; @@ -50,7 +50,7 @@ */ class RemovingMember implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var MemberService */ diff --git a/lib/Listeners/Files/ShareCreatedSendMail.php b/lib/Listeners/Files/ShareCreatedSendMail.php index 605766a98..0b776f0de 100644 --- a/lib/Listeners/Files/ShareCreatedSendMail.php +++ b/lib/Listeners/Files/ShareCreatedSendMail.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Listeners\Files; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\Files\FileShareCreatedEvent; @@ -60,7 +60,7 @@ */ class ShareCreatedSendMail implements IEventListener { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var ShareWrapperService */ diff --git a/lib/Listeners/Notifications/RequestingMember.php b/lib/Listeners/Notifications/RequestingMember.php index b2f780360..50a91c0cd 100644 --- a/lib/Listeners/Notifications/RequestingMember.php +++ b/lib/Listeners/Notifications/RequestingMember.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Listeners\Notifications; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\CircleGenericEvent; use OCA\Circles\Events\RequestingCircleMemberEvent; @@ -46,7 +46,7 @@ * @package OCA\Circles\Listeners\Notifications */ class RequestingMember implements IEventListener { - use TNC22Logger; + use TNCLogger; /** @var NotificationService */ diff --git a/lib/Migration/Migration.php b/lib/Migration/Migration.php index 7ef0bd2c6..75ad6adb6 100644 --- a/lib/Migration/Migration.php +++ b/lib/Migration/Migration.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Migration; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OCA\Circles\Service\ConfigService; use OCA\Circles\Service\MigrationService; @@ -45,7 +45,7 @@ * @package OCA\Circles\Migration */ class Migration implements IRepairStep { - use TNC22Logger; + use TNCLogger; /** @var MigrationService */ diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php index 9f968434d..8adaf46f7 100644 --- a/lib/Model/Circle.php +++ b/lib/Model/Circle.php @@ -31,11 +31,6 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use DateTime; use JsonSerializable; use OCA\Circles\Db\CircleRequest; @@ -51,6 +46,11 @@ use OCA\Circles\Exceptions\UnknownRemoteException; use OCA\Circles\IMemberships; use OCA\Circles\Model\Helpers\MemberHelper; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TDeserialize; use OCP\Security\IHasher; /** @@ -81,9 +81,13 @@ * * @package OCA\Circles\Model */ -class Circle extends ManagedModel implements IMemberships, IDeserializable, INC22QueryRow, JsonSerializable { +class Circle extends ManagedModel implements + IMemberships, + IDeserializable, + IQueryRow, + JsonSerializable { use TArrayTools; - use TNC22Deserialize; + use TDeserialize; public const FLAGS_SHORT = 1; @@ -217,6 +221,9 @@ class Circle extends ManagedModel implements IMemberships, IDeserializable, INC2 /** @var int */ private $population = 0; + /** @var int */ + private $populationInherited = 0; + // /** @var bool */ // private $hidden = false; @@ -639,6 +646,25 @@ public function getPopulation(): int { } + /** + * @param int $population + * + * @return Circle + */ + public function setPopulationInherited(int $population): self { + $this->populationInherited = $population; + + return $this; + } + + /** + * @return int + */ + public function getPopulationInherited(): int { + return $this->populationInherited; + } + + /** * @param array $settings * @@ -842,10 +868,10 @@ public function jsonSerialize(): array { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws CircleNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->get($prefix . 'unique_id', $data) === '') { throw new CircleNotFoundException(); } @@ -857,7 +883,6 @@ public function importFromDatabase(array $data, string $prefix = ''): INC22Query ->setConfig($this->getInt($prefix . 'config', $data)) ->setSource($this->getInt($prefix . 'source', $data)) ->setInstance($this->get($prefix . 'instance', $data)) - ->setPopulation($this->getInt($prefix . 'population', $data)) ->setSettings($this->getArray($prefix . 'settings', $data)) ->setContactAddressBook($this->getInt($prefix . 'contact_addressbook', $data)) ->setContactGroupName($this->get($prefix . 'contact_groupname', $data)) @@ -866,6 +891,9 @@ public function importFromDatabase(array $data, string $prefix = ''): INC22Query $creation = $this->get($prefix . 'creation', $data); $this->setCreation(DateTime::createFromFormat('Y-m-d H:i:s', $creation)->getTimestamp()); + $this->setPopulation($this->getInt('population', $this->getSettings())); + $this->setPopulationInherited($this->getInt('populationInherited', $this->getSettings())); + $this->getManager()->manageImportFromDatabase($this, $data, $prefix); diff --git a/lib/Model/DavCard.php b/lib/Model/DavCard.php index 112968e51..bcad4192a 100644 --- a/lib/Model/DavCard.php +++ b/lib/Model/DavCard.php @@ -29,7 +29,7 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** diff --git a/lib/Model/DeprecatedCircle.php b/lib/Model/DeprecatedCircle.php index 56b530fa2..9471e9e1b 100644 --- a/lib/Model/DeprecatedCircle.php +++ b/lib/Model/DeprecatedCircle.php @@ -26,7 +26,7 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\CircleTypeNotValidException; use OCA\Circles\Exceptions\FederatedCircleNotAllowedException; diff --git a/lib/Model/Federated/EventWrapper.php b/lib/Model/Federated/EventWrapper.php index 798ceb755..7338941df 100644 --- a/lib/Model/Federated/EventWrapper.php +++ b/lib/Model/Federated/EventWrapper.php @@ -31,10 +31,10 @@ namespace OCA\Circles\Model\Federated; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** @@ -42,7 +42,7 @@ * * @package OCA\Circles\Model\Remote */ -class EventWrapper implements INC22QueryRow, JsonSerializable { +class EventWrapper implements IQueryRow, JsonSerializable { use TArrayTools; @@ -306,10 +306,10 @@ public function jsonSerialize(): array { /** * @param array $data * - * @return INC22QueryRow + * @return IQueryRow * @throws InvalidItemException */ - public function importFromDatabase(array $data): INC22QueryRow { + public function importFromDatabase(array $data): IQueryRow { $this->setToken($this->get('token', $data)); $this->setInstance($this->get('instance', $data)); $this->setInterface($this->getInt('interface', $data)); diff --git a/lib/Model/Federated/FederatedEvent.php b/lib/Model/Federated/FederatedEvent.php index c172b3ece..8443f67c9 100644 --- a/lib/Model/Federated/FederatedEvent.php +++ b/lib/Model/Federated/FederatedEvent.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Model\Federated; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; diff --git a/lib/Model/Federated/FederatedShare.php b/lib/Model/Federated/FederatedShare.php index 44b52caa7..8b049441c 100644 --- a/lib/Model/Federated/FederatedShare.php +++ b/lib/Model/Federated/FederatedShare.php @@ -31,10 +31,10 @@ namespace OCA\Circles\Model\Federated; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\IFederatedModel; use OCA\Circles\Model\ManagedModel; @@ -44,7 +44,7 @@ * * @package OCA\Circles\Model\Federated */ -class FederatedShare extends ManagedModel implements IFederatedModel, JsonSerializable, INC22QueryRow, IDeserializable { +class FederatedShare extends ManagedModel implements IFederatedModel, JsonSerializable, IQueryRow, IDeserializable { use TArrayTools; @@ -195,9 +195,9 @@ public function import(array $data): IDeserializable { /** * @param array $data * - * @return INC22QueryRow + * @return IQueryRow */ - public function importFromDatabase(array $data): INC22QueryRow { + public function importFromDatabase(array $data): IQueryRow { $this->setId($this->getInt('id', $data)); $this->setItemId($this->get('item_id', $data)); $this->setCircleId($this->get('circle_id', $data)); diff --git a/lib/Model/Federated/RemoteInstance.php b/lib/Model/Federated/RemoteInstance.php index fe7b0c43b..a4c824b08 100644 --- a/lib/Model/Federated/RemoteInstance.php +++ b/lib/Model/Federated/RemoteInstance.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Model\Federated; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Signatory; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Model\NCSignatory; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\RemoteNotFoundException; use OCA\Circles\Exceptions\RemoteUidException; @@ -43,7 +43,7 @@ * * @package OCA\Circles\Model */ -class RemoteInstance extends NC22Signatory implements INC22QueryRow, JsonSerializable { +class RemoteInstance extends NCSignatory implements IQueryRow, JsonSerializable { use TArrayTools; public const TYPE_UNKNOWN = 'Unknown'; // not trusted @@ -473,9 +473,9 @@ public function mustBeIdentityAuthed(): void { /** * @param array $data * - * @return NC22Signatory + * @return NCSignatory */ - public function import(array $data): NC22Signatory { + public function import(array $data): NCSignatory { parent::import($data); $this->setTest($this->get('test', $data)) @@ -541,7 +541,7 @@ public function jsonSerialize(): array { * @return self * @throws RemoteNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->getInt($prefix . 'id', $data) === 0) { throw new RemoteNotFoundException(); } diff --git a/lib/Model/FederatedUser.php b/lib/Model/FederatedUser.php index a0e774755..acb042518 100644 --- a/lib/Model/FederatedUser.php +++ b/lib/Model/FederatedUser.php @@ -31,11 +31,11 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\FederatedUserNotFoundException; use OCA\Circles\Exceptions\OwnerNotFoundException; @@ -52,10 +52,10 @@ class FederatedUser extends ManagedModel implements IFederatedUser, IMemberships, IDeserializable, - INC22QueryRow, + IQueryRow, JsonSerializable { use TArrayTools; - use TNC22Deserialize; + use TDeserialize; /** @var string */ @@ -398,10 +398,10 @@ public function importFromCircle(Circle $circle): self { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws FederatedUserNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->get($prefix . 'single_id', $data) === '') { throw new FederatedUserNotFoundException(); } diff --git a/lib/Model/FileCacheWrapper.php b/lib/Model/FileCacheWrapper.php index 535d83eec..fa659f8ed 100644 --- a/lib/Model/FileCacheWrapper.php +++ b/lib/Model/FileCacheWrapper.php @@ -31,10 +31,10 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Db\CoreQueryBuilder; use OCA\Circles\Exceptions\FileCacheNotFoundException; @@ -44,7 +44,7 @@ * * @package OCA\Circles\Model */ -class FileCacheWrapper extends ManagedModel implements INC22QueryRow, IDeserializable, JsonSerializable { +class FileCacheWrapper extends ManagedModel implements IQueryRow, IDeserializable, JsonSerializable { use TArrayTools; @@ -497,10 +497,10 @@ public function import(array $data): IDeserializable { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws FileCacheNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->getInt($prefix . 'fileid', $data) === 0) { throw new FileCacheNotFoundException(); } diff --git a/lib/Model/GlobalScale/GSEvent.php b/lib/Model/GlobalScale/GSEvent.php index 39a0fce09..93e57e074 100644 --- a/lib/Model/GlobalScale/GSEvent.php +++ b/lib/Model/GlobalScale/GSEvent.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Model\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\JsonException; use OCA\Circles\Exceptions\ModelException; diff --git a/lib/Model/GlobalScale/GSShare.php b/lib/Model/GlobalScale/GSShare.php index 8c2b3da27..5a0c3cd0a 100644 --- a/lib/Model/GlobalScale/GSShare.php +++ b/lib/Model/GlobalScale/GSShare.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** diff --git a/lib/Model/GlobalScale/GSShareMountpoint.php b/lib/Model/GlobalScale/GSShareMountpoint.php index 2cb146e80..d4e8326d4 100644 --- a/lib/Model/GlobalScale/GSShareMountpoint.php +++ b/lib/Model/GlobalScale/GSShareMountpoint.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** diff --git a/lib/Model/GlobalScale/GSWrapper.php b/lib/Model/GlobalScale/GSWrapper.php index 235b4aa92..c9bbbb7f5 100644 --- a/lib/Model/GlobalScale/GSWrapper.php +++ b/lib/Model/GlobalScale/GSWrapper.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model\GlobalScale; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\JsonException; use OCA\Circles\Exceptions\ModelException; diff --git a/lib/Model/Helpers/MemberHelper.php b/lib/Model/Helpers/MemberHelper.php index 0ae5fb7b4..5e81e0e58 100644 --- a/lib/Model/Helpers/MemberHelper.php +++ b/lib/Model/Helpers/MemberHelper.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model\Helpers; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use OCA\Circles\Exceptions\MemberHelperException; use OCA\Circles\Exceptions\MemberLevelException; use OCA\Circles\Exceptions\ParseMemberLevelException; diff --git a/lib/Model/Member.php b/lib/Model/Member.php index 4abccfb85..063dfe515 100644 --- a/lib/Model/Member.php +++ b/lib/Model/Member.php @@ -31,11 +31,6 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use DateTime; use JsonSerializable; use OCA\Circles\AppInfo\Capabilities; @@ -47,6 +42,11 @@ use OCA\Circles\IFederatedUser; use OCA\Circles\IMemberships; use OCA\Circles\Model\Federated\RemoteInstance; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TDeserialize; /** * Class Member @@ -57,10 +57,10 @@ class Member extends ManagedModel implements IMemberships, IFederatedUser, IDeserializable, - INC22QueryRow, + IQueryRow, JsonSerializable { use TArrayTools; - use TNC22Deserialize; + use TDeserialize; public const LEVEL_NONE = 0; @@ -831,10 +831,10 @@ public function import(array $data): IDeserializable { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws MemberNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->get($prefix . 'single_id', $data) === '') { throw new MemberNotFoundException(); } diff --git a/lib/Model/Membership.php b/lib/Model/Membership.php index 6aacd4df8..bba5145ce 100644 --- a/lib/Model/Membership.php +++ b/lib/Model/Membership.php @@ -31,19 +31,19 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\MembershipNotFoundException; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; /** * Class Membership * * @package OCA\Circles\Model */ -class Membership extends ManagedModel implements IDeserializable, INC22QueryRow, JsonSerializable { +class Membership extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable { use TArrayTools; @@ -298,10 +298,10 @@ public function import(array $data): IDeserializable { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws MembershipNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->get($prefix . 'single_id', $data) === '') { throw new MembershipNotFoundException(); } diff --git a/lib/Model/ModelManager.php b/lib/Model/ModelManager.php index 8eaf306ce..020e0df2b 100644 --- a/lib/Model/ModelManager.php +++ b/lib/Model/ModelManager.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\CoreQueryBuilder; @@ -64,7 +64,7 @@ * @package OCA\Circles\Model */ class ModelManager { - use TNC22Logger; + use TNCLogger; /** @var IURLGenerator */ @@ -533,9 +533,7 @@ public function fixInstance(string $instance): string { */ public function generateLinkToCircle(string $singleId): string { return $this->urlGenerator->linkToRoute( - $this->configService->getAppValue( - ConfigService::ROUTE_TO_CIRCLE - ), + $this->configService->getAppValue(ConfigService::ROUTE_TO_CIRCLE), ['singleId' => $singleId] ); } diff --git a/lib/Model/Mount.php b/lib/Model/Mount.php index c32d9a7fc..6a09132e6 100644 --- a/lib/Model/Mount.php +++ b/lib/Model/Mount.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\MountManager\CircleMountManager; @@ -45,7 +45,7 @@ * * @package OCA\Circles\Model */ -class Mount extends ManagedModel implements IDeserializable, INC22QueryRow, JsonSerializable { +class Mount extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable { use TArrayTools; @@ -458,7 +458,7 @@ public function import(array $data): IDeserializable { * * @return Mount */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { $this->setId($this->getInt('id', $data)); $this->setCircleId($this->get('circle_id', $data)); $this->setToken($this->get('token', $data)); diff --git a/lib/Model/Mountpoint.php b/lib/Model/Mountpoint.php index aaee68174..231d4bf78 100644 --- a/lib/Model/Mountpoint.php +++ b/lib/Model/Mountpoint.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** diff --git a/lib/Model/Report.php b/lib/Model/Report.php index 1400dd7df..c799ec5ca 100644 --- a/lib/Model/Report.php +++ b/lib/Model/Report.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; /** diff --git a/lib/Model/ShareToken.php b/lib/Model/ShareToken.php index 02d22bab2..7ef3bc3a4 100644 --- a/lib/Model/ShareToken.php +++ b/lib/Model/ShareToken.php @@ -31,15 +31,15 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCA\Circles\Exceptions\ShareTokenNotFoundException; use OCP\Share\IShare; -class ShareToken implements IDeserializable, INC22QueryRow, JsonSerializable { +class ShareToken implements IDeserializable, IQueryRow, JsonSerializable { use TArrayTools; @@ -277,10 +277,10 @@ public function import(array $data): IDeserializable { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow * @throws ShareTokenNotFoundException */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { if ($this->get($prefix . 'token', $data) === '') { throw new ShareTokenNotFoundException(); } diff --git a/lib/Model/ShareWrapper.php b/lib/Model/ShareWrapper.php index d5772ae58..2a242f99b 100644 --- a/lib/Model/ShareWrapper.php +++ b/lib/Model/ShareWrapper.php @@ -31,11 +31,11 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc22\INC22QueryRow; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\IDeserializable; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Db\IQueryRow; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TArrayTools; use DateTime; use JsonSerializable; use OC; @@ -54,9 +54,9 @@ * * @package OCA\Circles\Model */ -class ShareWrapper extends ManagedModel implements IDeserializable, INC22QueryRow, JsonSerializable { +class ShareWrapper extends ManagedModel implements IDeserializable, IQueryRow, JsonSerializable { use TArrayTools; - use TNC22Deserialize; + use TDeserialize; /** @var string */ @@ -781,9 +781,9 @@ public function import(array $data): IDeserializable { * @param array $data * @param string $prefix * - * @return INC22QueryRow + * @return IQueryRow */ - public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { + public function importFromDatabase(array $data, string $prefix = ''): IQueryRow { $shareTime = new DateTime(); $shareTime->setTimestamp($this->getInt($prefix . 'stime', $data)); diff --git a/lib/Model/SharesToken.php b/lib/Model/SharesToken.php index cd9eb19c9..ab807b031 100644 --- a/lib/Model/SharesToken.php +++ b/lib/Model/SharesToken.php @@ -26,7 +26,7 @@ namespace OCA\Circles\Model; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use JsonSerializable; use OCP\Share\IShare; diff --git a/lib/MountManager/CircleMount.php b/lib/MountManager/CircleMount.php index 29ac827dc..33de496e6 100644 --- a/lib/MountManager/CircleMount.php +++ b/lib/MountManager/CircleMount.php @@ -31,7 +31,7 @@ namespace OCA\Circles\MountManager; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use JsonSerializable; use OC\Files\Mount\MountPoint; diff --git a/lib/MountManager/CircleMountProvider.php b/lib/MountManager/CircleMountProvider.php index 8aec54102..a205e461a 100644 --- a/lib/MountManager/CircleMountProvider.php +++ b/lib/MountManager/CircleMountProvider.php @@ -31,7 +31,7 @@ namespace OCA\Circles\MountManager; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OCA\Circles\Db\MountRequest; use OCA\Circles\Exceptions\FederatedUserException; diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index eed062941..a43d5740b 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Notification; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use InvalidArgumentException; use OCA\Circles\AppInfo\Application; @@ -60,7 +60,7 @@ * @package OCA\Circles\Notification */ class Notifier implements INotifier { - use TNC22Logger; + use TNCLogger; /** @var IL10N */ diff --git a/lib/Search/GlobalScaleUsers.php b/lib/Search/GlobalScaleUsers.php index 9b59e6f32..f05f69450 100644 --- a/lib/Search/GlobalScaleUsers.php +++ b/lib/Search/GlobalScaleUsers.php @@ -26,12 +26,12 @@ namespace OCA\Circles\Search; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultNotJsonException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\RequestResultNotJsonException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TArrayTools; use OCA\Circles\Exceptions\GSStatusException; use OCA\Circles\ISearch; use OCA\Circles\Model\DeprecatedMember; @@ -45,7 +45,7 @@ * @package OCA\Circles\Search */ class GlobalScaleUsers implements ISearch { - use TNC22Request; + use TNCRequest; use TArrayTools; @@ -79,7 +79,7 @@ public function search(string $search): array { return []; } - $request = new NC22Request(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); + $request = new NCRequest(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); $this->configService->configureRequest($request); $request->basedOnUrl($lookup); $request->addParam('search', $search); diff --git a/lib/Search/LocalUsers.php b/lib/Search/LocalUsers.php index 44dc2685b..21e60e21a 100644 --- a/lib/Search/LocalUsers.php +++ b/lib/Search/LocalUsers.php @@ -26,7 +26,7 @@ namespace OCA\Circles\Search; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use OCA\Circles\ISearch; use OCA\Circles\Model\DeprecatedMember; use OCA\Circles\Model\SearchResult; diff --git a/lib/Service/CircleService.php b/lib/Service/CircleService.php index 3eb225004..843b4a174 100644 --- a/lib/Service/CircleService.php +++ b/lib/Service/CircleService.php @@ -31,10 +31,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; @@ -66,13 +62,17 @@ use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Model\Probes\MemberProbe; use OCA\Circles\StatusCode; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCP\IL10N; use OCP\Security\IHasher; class CircleService { use TArrayTools; use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IL10N */ diff --git a/lib/Service/CirclesService.php b/lib/Service/CirclesService.php index af5cd8d3f..4761b7cd3 100644 --- a/lib/Service/CirclesService.php +++ b/lib/Service/CirclesService.php @@ -29,7 +29,7 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC; use OCA\Circles\AppInfo\Application; diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 9a21f324c..8442b9df9 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -31,10 +31,10 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use OC; use OCA\Circles\AppInfo\Application; use OCA\Circles\Exceptions\GSStatusException; @@ -52,7 +52,7 @@ class ConfigService { use TStringTools; use TArrayTools; - use TNC22Logger; + use TNCLogger; public const FRONTAL_CLOUD_BASE = 'frontal_cloud_base'; @@ -688,12 +688,12 @@ public function displayInstance(string $instance, int $type = self::DISPLAY_NONE * - Create route using getLoopbackAddress() * - perfect for loopback request. * - * @param NC22Request $request + * @param NCRequest $request * @param string $route * @param array $args */ public function configureLoopbackRequest( - NC22Request $request, + NCRequest $request, string $route = '', array $args = [] ): void { @@ -704,9 +704,9 @@ public function configureLoopbackRequest( /** - * @param NC22Request $request + * @param NCRequest $request */ - public function configureRequest(NC22Request $request): void { + public function configureRequest(NCRequest $request): void { $request->setVerifyPeer($this->getAppValue(ConfigService::SELF_SIGNED_CERT) !== '1'); $request->setProtocols(['https', 'http']); $request->setHttpErrorsAllowed(true); diff --git a/lib/Service/ContactService.php b/lib/Service/ContactService.php index 9f63623c7..73153997d 100644 --- a/lib/Service/ContactService.php +++ b/lib/Service/ContactService.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OC; use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; @@ -53,7 +53,7 @@ class ContactService { use TArrayTools; use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IURLGenerator */ diff --git a/lib/Service/EventService.php b/lib/Service/EventService.php index 79f7636dc..004a32283 100644 --- a/lib/Service/EventService.php +++ b/lib/Service/EventService.php @@ -34,8 +34,8 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Events\AddingCircleMemberEvent; use OCA\Circles\Events\CircleCreatedEvent; @@ -70,7 +70,7 @@ * @package OCA\Circles\Service */ class EventService { - use TNC22Logger; + use TNCLogger; /** @var IEventDispatcher */ diff --git a/lib/Service/EventWrapperService.php b/lib/Service/EventWrapperService.php index fbc718798..07ad792d1 100644 --- a/lib/Service/EventWrapperService.php +++ b/lib/Service/EventWrapperService.php @@ -30,21 +30,21 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\ActivityPub\Nextcloud\nc22\NC22Signature; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use Exception; use OCA\Circles\Db\EventWrapperRequest; use OCA\Circles\Model\Federated\EventWrapper; use OCA\Circles\Model\Federated\FederatedEvent; +use OCA\Circles\Tools\ActivityPub\NCSignature; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TStringTools; /** * Class EventWrapperService * * @package OCA\Circles\Service */ -class EventWrapperService extends NC22Signature { - use TNC22Request; +class EventWrapperService extends NCSignature { + use TNCRequest; use TStringTools; diff --git a/lib/Service/FederatedEventService.php b/lib/Service/FederatedEventService.php index bfa335c6a..9759da74c 100644 --- a/lib/Service/FederatedEventService.php +++ b/lib/Service/FederatedEventService.php @@ -30,12 +30,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\ActivityPub\Nextcloud\nc22\NC22Signature; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use OC; use OCA\Circles\Db\EventWrapperRequest; use OCA\Circles\Db\MemberRequest; @@ -72,6 +66,12 @@ use OCA\Circles\Model\Federated\FederatedEvent; use OCA\Circles\Model\Federated\RemoteInstance; use OCA\Circles\Model\Member; +use OCA\Circles\Tools\ActivityPub\NCSignature; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TStringTools; use ReflectionClass; use ReflectionException; @@ -80,8 +80,8 @@ * * @package OCA\Circles\Service */ -class FederatedEventService extends NC22Signature { - use TNC22Request; +class FederatedEventService extends NCSignature { + use TNCRequest; use TStringTools; @@ -415,7 +415,7 @@ public function initBroadcast(FederatedEvent $event): void { $this->eventWrapperRequest->save($wrapper); } - $request = new NC22Request('', Request::TYPE_POST); + $request = new NCRequest('', Request::TYPE_POST); $this->configService->configureLoopbackRequest( $request, 'circles.EventWrapper.asyncBroadcast', diff --git a/lib/Service/FederatedShareService.php b/lib/Service/FederatedShareService.php index a8f047b95..5ed5afa2e 100644 --- a/lib/Service/FederatedShareService.php +++ b/lib/Service/FederatedShareService.php @@ -30,11 +30,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\ActivityPub\Nextcloud\nc22\NC22Signature; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Exceptions\UnknownTypeException; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\FederatedEventDSyncException; use OCA\Circles\Exceptions\FederatedEventException; @@ -49,13 +44,18 @@ use OCA\Circles\FederatedItems\ItemLock; use OCA\Circles\Model\Federated\FederatedEvent; use OCA\Circles\Model\Federated\FederatedShare; +use OCA\Circles\Tools\ActivityPub\NCSignature; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; /** * Class FederatedShareService * * @package OCA\Circles\Service */ -class FederatedShareService extends NC22Signature { +class FederatedShareService extends NCSignature { /** @var FederatedEventService */ diff --git a/lib/Service/FederatedUserService.php b/lib/Service/FederatedUserService.php index 88875a4ea..8bb0577a5 100644 --- a/lib/Service/FederatedUserService.php +++ b/lib/Service/FederatedUserService.php @@ -31,11 +31,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use Exception; use OC; use OCA\Circles\AppInfo\Application; @@ -71,6 +66,11 @@ use OCA\Circles\Model\ManagedModel; use OCA\Circles\Model\Member; use OCA\Circles\Model\Probes\CircleProbe; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCP\ICache; use OCP\ICacheFactory; use OCP\IGroupManager; @@ -86,8 +86,8 @@ class FederatedUserService { use TArrayTools; use TStringTools; - use TNC22Logger; - use TNC22Deserialize; + use TNCLogger; + use TDeserialize; public const CACHE_SINGLE_CIRCLE = 'circles/singleCircle'; diff --git a/lib/Service/GSUpstreamService.php b/lib/Service/GSUpstreamService.php index ac7f12fff..7684f558a 100644 --- a/lib/Service/GSUpstreamService.php +++ b/lib/Service/GSUpstreamService.php @@ -31,15 +31,15 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestContentException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultNotJsonException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultSizeException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestServerException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; +use OCA\Circles\Tools\Exceptions\RequestContentException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\RequestResultNotJsonException; +use OCA\Circles\Tools\Exceptions\RequestResultSizeException; +use OCA\Circles\Tools\Exceptions\RequestServerException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCRequest; use Exception; use OCA\Circles\Db\DeprecatedCirclesRequest; use OCA\Circles\Db\DeprecatedMembersRequest; @@ -60,7 +60,7 @@ * @package OCA\Circles\Service */ class GSUpstreamService { - use TNC22Request; + use TNCRequest; /** @var string */ @@ -189,11 +189,11 @@ public function broadcastEvent(GSEvent $event, string $instance): void { $this->signEvent($event); if ($this->configService->isLocalInstance($instance)) { - $request = new NC22Request('', Request::TYPE_POST); + $request = new NCRequest('', Request::TYPE_POST); $this->configService->configureRequest($request, 'circles.EventWrapper.broadcast'); } else { $path = $this->urlGenerator->linkToRoute('circles.EventWrapper.broadcast'); - $request = new NC22Request($path, Request::TYPE_POST); + $request = new NCRequest($path, Request::TYPE_POST); $this->configService->configureRequest($request); $request->setInstance($instance); } @@ -222,7 +222,7 @@ public function confirmEvent(GSEvent &$event): void { $owner = $circle->getOwner(); $path = $this->urlGenerator->linkToRoute('circles.EventWrapper.event'); - $request = new NC22Request($path, Request::TYPE_POST); + $request = new NCRequest($path, Request::TYPE_POST); $this->configService->configureRequest($request); $request->basedOnUrl($owner->getInstance()); @@ -404,7 +404,7 @@ public function confirmCircleStatus(DeprecatedCircle $circle): bool { $this->signEvent($event); $path = $this->urlGenerator->linkToRoute('circles.EventWrapper.status'); - $request = new NC22Request($path, Request::TYPE_POST); + $request = new NCRequest($path, Request::TYPE_POST); $this->configService->configureRequest($request); $request->setDataSerialize($event); diff --git a/lib/Service/GlobalScaleService.php b/lib/Service/GlobalScaleService.php index 1735562e7..4d37f90e5 100644 --- a/lib/Service/GlobalScaleService.php +++ b/lib/Service/GlobalScaleService.php @@ -31,11 +31,11 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TStringTools; use OC\Security\IdentityProof\Signer; use OCA\Circles\Db\EventWrapperRequest; use OCA\Circles\Exceptions\GSStatusException; @@ -49,7 +49,7 @@ * @package OCA\Circles\Service */ class GlobalScaleService { - use TNC22Request; + use TNCRequest; use TStringTools; @@ -116,7 +116,7 @@ public function getGlobalScaleInstances(): array { try { $lookup = $this->configService->getGSLookup(); - $request = new NC22Request(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST); + $request = new NCRequest(ConfigService::GS_LOOKUP_INSTANCES, Request::TYPE_POST); $this->configService->configureRequest($request); $request->basedOnUrl($lookup); $request->addData('authKey', $this->configService->getGSInfo(ConfigService::GS_KEY)); diff --git a/lib/Service/InterfaceService.php b/lib/Service/InterfaceService.php index 33eac4b24..d72fdf5f0 100644 --- a/lib/Service/InterfaceService.php +++ b/lib/Service/InterfaceService.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\RemoteRequest; use OCA\Circles\Exceptions\RemoteNotFoundException; @@ -69,7 +69,7 @@ class InterfaceService { use TStringTools; use TArrayTools; - use TNC22Logger; + use TNCLogger; /** @var IURLGenerator */ diff --git a/lib/Service/MaintenanceService.php b/lib/Service/MaintenanceService.php index 4d5f0a47f..e10c8081b 100644 --- a/lib/Service/MaintenanceService.php +++ b/lib/Service/MaintenanceService.php @@ -31,7 +31,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; use Exception; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; @@ -43,6 +42,7 @@ use OCA\Circles\Model\Member; use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Model\ShareWrapper; +use OCA\Circles\Tools\Traits\TNCLogger; use OCP\IUserManager; use Symfony\Component\Console\Output\OutputInterface; @@ -52,7 +52,7 @@ * @package OCA\Circles\Service */ class MaintenanceService { - use TNC22Logger; + use TNCLogger; public const TIMEOUT = 18000; diff --git a/lib/Service/MemberService.php b/lib/Service/MemberService.php index f38a60226..58e1d261c 100644 --- a/lib/Service/MemberService.php +++ b/lib/Service/MemberService.php @@ -31,10 +31,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\CircleNotFoundException; @@ -64,6 +60,10 @@ use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; use OCA\Circles\Model\Probes\MemberProbe; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; /** * Class MemberService @@ -73,7 +73,7 @@ class MemberService { use TArrayTools; use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var CircleRequest */ @@ -296,8 +296,10 @@ function (FederatedUser $federatedUser) use ($patron) { */ public function removeMember(string $memberId): array { $this->federatedUserService->mustHaveCurrentUser(); - $member = - $this->memberRequest->getMemberById($memberId, $this->federatedUserService->getCurrentUser()); + $member = $this->memberRequest->getMemberById( + $memberId, + $this->federatedUserService->getCurrentUser() + ); $event = new FederatedEvent(MemberRemove::class); $event->setCircle($member->getCircle()); diff --git a/lib/Service/MembersService.php b/lib/Service/MembersService.php index 11288df0b..e1558f6b9 100644 --- a/lib/Service/MembersService.php +++ b/lib/Service/MembersService.php @@ -26,12 +26,12 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestResultNotJsonException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\RequestResultNotJsonException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Traits\TNCRequest; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC; use OC\User\NoUserException; @@ -64,7 +64,7 @@ * @package OCA\Circles\Service */ class MembersService { - use TNC22Request; + use TNCRequest; use TArrayTools; @@ -719,7 +719,7 @@ public function getUserDisplayName(string $ident, bool $fresh = false): string { private function getGlobalScaleUserDisplayName(string $ident): string { $lookup = $this->configService->getGSLookup(); - $request = new NC22Request(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); + $request = new NCRequest(ConfigService::GS_LOOKUP_USERS, Request::TYPE_GET); $this->configService->configureRequest($request); $request->basedOnUrl($lookup); $request->addParam('search', $ident); diff --git a/lib/Service/MembershipService.php b/lib/Service/MembershipService.php index d13663063..e91b9ccc5 100644 --- a/lib/Service/MembershipService.php +++ b/lib/Service/MembershipService.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\ItemNotFoundException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Db\MembershipRequest; @@ -51,7 +51,7 @@ * @package OCA\Circles\Service */ class MembershipService { - use TNC22Logger; + use TNCLogger; /** @var MembershipRequest */ diff --git a/lib/Service/MigrationService.php b/lib/Service/MigrationService.php index e70e01ed3..5ae0689ab 100644 --- a/lib/Service/MigrationService.php +++ b/lib/Service/MigrationService.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OC; use OCA\Circles\AppInfo\Application; @@ -77,7 +77,7 @@ */ class MigrationService { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IDBConnection */ diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index 03d17197f..f7e59d06e 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -26,7 +26,7 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TArrayTools; use Exception; use OC; use OC\User\NoUserException; diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 5d5c4cbcf..6853c68cf 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -34,7 +34,7 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\RequestBuilderException; @@ -49,7 +49,7 @@ * @package OCA\Circles\Service */ class NotificationService { - use TNC22Logger; + use TNCLogger; /** @var IURLGenerator */ diff --git a/lib/Service/OutputService.php b/lib/Service/OutputService.php index cb6f628e3..a988b8145 100644 --- a/lib/Service/OutputService.php +++ b/lib/Service/OutputService.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use OCP\Migration\IOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -43,7 +43,7 @@ */ class OutputService { use TStringTools; - use TNC22Logger; + use TNCLogger; /** @var IOutput */ diff --git a/lib/Service/RemoteDownstreamService.php b/lib/Service/RemoteDownstreamService.php index 8b6d19e35..3385292b9 100644 --- a/lib/Service/RemoteDownstreamService.php +++ b/lib/Service/RemoteDownstreamService.php @@ -31,11 +31,11 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TAsync; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Traits\TAsync; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; @@ -61,7 +61,7 @@ * @package OCA\Circles\Service */ class RemoteDownstreamService { - use TNC22Logger; + use TNCLogger; use TAsync; diff --git a/lib/Service/RemoteService.php b/lib/Service/RemoteService.php index 5cbabed1f..826b3fd3b 100644 --- a/lib/Service/RemoteService.php +++ b/lib/Service/RemoteService.php @@ -30,12 +30,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\ActivityPub\Nextcloud\nc22\NC22Signature; -use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; use OCA\Circles\Db\CircleRequest; use OCA\Circles\Db\MemberRequest; use OCA\Circles\Exceptions\CircleNotFoundException; @@ -53,13 +47,19 @@ use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; use OCA\Circles\Model\Membership; +use OCA\Circles\Tools\ActivityPub\NCSignature; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Model\SimpleDataStore; /** * Class RemoteService * * @package OCA\Circles\Service */ -class RemoteService extends NC22Signature { +class RemoteService extends NCSignature { /** @var CircleRequest */ diff --git a/lib/Service/RemoteStreamService.php b/lib/Service/RemoteStreamService.php index 1e15c7746..4e3b95ab2 100644 --- a/lib/Service/RemoteStreamService.php +++ b/lib/Service/RemoteStreamService.php @@ -30,21 +30,6 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\ActivityPub\Nextcloud\nc22\NC22Signature; -use ArtificialOwl\MySmallPhpTools\Exceptions\RequestNetworkException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException; -use ArtificialOwl\MySmallPhpTools\Exceptions\SignatureException; -use ArtificialOwl\MySmallPhpTools\Exceptions\WellKnownLinkNotFoundException; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Request; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22RequestResult; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22Signatory; -use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc22\NC22SignedRequest; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22LocalSignatory; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22WellKnown; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; use JsonSerializable; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\RemoteRequest; @@ -57,6 +42,21 @@ use OCA\Circles\Exceptions\UnknownInterfaceException; use OCA\Circles\Exceptions\UnknownRemoteException; use OCA\Circles\Model\Federated\RemoteInstance; +use OCA\Circles\Tools\ActivityPub\NCSignature; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\SignatureException; +use OCA\Circles\Tools\Exceptions\WellKnownLinkNotFoundException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\NCRequestResult; +use OCA\Circles\Tools\Model\NCSignatory; +use OCA\Circles\Tools\Model\NCSignedRequest; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TDeserialize; +use OCA\Circles\Tools\Traits\TNCLocalSignatory; +use OCA\Circles\Tools\Traits\TNCWellKnown; +use OCA\Circles\Tools\Traits\TStringTools; use OCP\AppFramework\Http; use OCP\IURLGenerator; use ReflectionClass; @@ -67,11 +67,11 @@ * * @package OCA\Circles\Service */ -class RemoteStreamService extends NC22Signature { - use TNC22Deserialize; - use TNC22LocalSignatory; +class RemoteStreamService extends NCSignature { + use TDeserialize; + use TNCLocalSignatory; use TStringTools; - use TNC22WellKnown; + use TNCWellKnown; public const UPDATE_DATA = 'data'; @@ -253,7 +253,7 @@ public function resultRequestRemoteInstance( * @param JsonSerializable|null $object * @param array $params * - * @return NC22SignedRequest + * @return NCSignedRequest * @throws RemoteNotFoundException * @throws RemoteResourceNotFoundException * @throws UnknownRemoteException @@ -266,8 +266,8 @@ private function requestRemoteInstance( int $type = Request::TYPE_GET, ?JsonSerializable $object = null, array $params = [] - ): NC22SignedRequest { - $request = new NC22Request('', $type); + ): NCSignedRequest { + $request = new NCRequest('', $type); $this->configService->configureRequest($request); $link = $this->getRemoteInstanceEntry($instance, $item, $params); $request->basedOnUrl($link); @@ -283,7 +283,7 @@ private function requestRemoteInstance( try { $app = $this->getAppSignatory(); -// $app->setAlgorithm(NC22Signatory::SHA512); +// $app->setAlgorithm(NCSignatory::SHA512); $signedRequest = $this->signOutgoingRequest($request, $app); $this->doRequest($signedRequest->getOutgoingRequest(), false); } catch (RequestNetworkException | SignatoryException $e) { @@ -369,10 +369,10 @@ public function retrieveRemoteInstance(string $instance): RemoteInstance { * @throws SignatoryException * @throws SignatureException */ - public function retrieveSignatory(string $keyId, bool $refresh = true): NC22Signatory { + public function retrieveSignatory(string $keyId, bool $refresh = true): NCSignatory { if (!$refresh) { try { - return $this->remoteRequest->getFromHref(NC22Signatory::removeFragment($keyId)); + return $this->remoteRequest->getFromHref(NCSignatory::removeFragment($keyId)); } catch (RemoteNotFoundException $e) { throw new SignatoryException(); } @@ -381,7 +381,7 @@ public function retrieveSignatory(string $keyId, bool $refresh = true): NC22Sign $remoteInstance = new RemoteInstance($keyId); $confirm = $this->uuid(); - $request = new NC22Request(); + $request = new NCRequest(); $this->configService->configureRequest($request); $this->downloadSignatory($remoteInstance, $keyId, ['auth' => $confirm], $request); @@ -502,11 +502,11 @@ private function confirmAuth(RemoteInstance $remote, string $auth): void { /** - * @param NC22RequestResult $result + * @param NCRequestResult $result * * @return FederatedItemException */ - private function getFederatedItemExceptionFromResult(NC22RequestResult $result): FederatedItemException { + private function getFederatedItemExceptionFromResult(NCRequestResult $result): FederatedItemException { $data = $result->getAsArray(); $message = $this->get('message', $data); diff --git a/lib/Service/RemoteUpstreamService.php b/lib/Service/RemoteUpstreamService.php index abeaa1161..e5346e845 100644 --- a/lib/Service/RemoteUpstreamService.php +++ b/lib/Service/RemoteUpstreamService.php @@ -31,9 +31,9 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Model\Request; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Request; +use OCA\Circles\Tools\Model\Request; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCRequest; use OCA\Circles\Db\EventWrapperRequest; use OCA\Circles\Exceptions\FederatedItemException; use OCA\Circles\Exceptions\OwnerNotFoundException; @@ -51,7 +51,7 @@ * @package OCA\Circles\Service */ class RemoteUpstreamService { - use TNC22Request; + use TNCRequest; /** @var EventWrapperRequest */ diff --git a/lib/Service/ShareTokenService.php b/lib/Service/ShareTokenService.php index 3930cd860..122e8bf3e 100644 --- a/lib/Service/ShareTokenService.php +++ b/lib/Service/ShareTokenService.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\ShareTokenRequest; use OCA\Circles\Exceptions\ShareTokenAlreadyExistException; use OCA\Circles\Exceptions\ShareTokenNotFoundException; diff --git a/lib/Service/ShareWrapperService.php b/lib/Service/ShareWrapperService.php index 78c323549..0636c1e9f 100644 --- a/lib/Service/ShareWrapperService.php +++ b/lib/Service/ShareWrapperService.php @@ -31,7 +31,7 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TStringTools; use OCA\Circles\Db\ShareWrapperRequest; use OCA\Circles\Exceptions\RequestBuilderException; use OCA\Circles\Exceptions\ShareWrapperNotFoundException; diff --git a/lib/Service/SyncService.php b/lib/Service/SyncService.php index 5eab05c8e..0fb12f435 100644 --- a/lib/Service/SyncService.php +++ b/lib/Service/SyncService.php @@ -31,8 +31,8 @@ namespace OCA\Circles\Service; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TStringTools; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\CircleRequest; @@ -71,7 +71,7 @@ */ class SyncService { use TStringTools; - use TNC22Logger; + use TNCLogger; public const SYNC_APPS = 1; diff --git a/lib/ShareByCircleProvider.php b/lib/ShareByCircleProvider.php index 81d8f5e14..393de658d 100644 --- a/lib/ShareByCircleProvider.php +++ b/lib/ShareByCircleProvider.php @@ -34,9 +34,9 @@ namespace OCA\Circles; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; -use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools; -use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; +use OCA\Circles\Tools\Traits\TNCLogger; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCA\Circles\Tools\Traits\TStringTools; use OC; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; @@ -93,7 +93,7 @@ class ShareByCircleProvider implements IShareProvider { use TArrayTools; use TStringTools; - use TNC22Logger; + use TNCLogger; public const IDENTIFIER = 'ocCircleShare'; diff --git a/lib/ShareByCircleProviderDeprecated.php b/lib/ShareByCircleProviderDeprecated.php index b1ad60739..2ab31d66f 100644 --- a/lib/ShareByCircleProviderDeprecated.php +++ b/lib/ShareByCircleProviderDeprecated.php @@ -30,7 +30,7 @@ namespace OCA\Circles; -use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore; +use OCA\Circles\Tools\Model\SimpleDataStore; use Exception; use OC; use OC\Files\Cache\Cache; diff --git a/lib/Tools/ActivityPub/NCSignature.php b/lib/Tools/ActivityPub/NCSignature.php new file mode 100644 index 000000000..f58ea8c08 --- /dev/null +++ b/lib/Tools/ActivityPub/NCSignature.php @@ -0,0 +1,413 @@ + + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +/** + * Circles - Bring cloud-users closer together. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\ActivityPub; + +use DateTime; +use Exception; +use OC; +use OCA\Circles\Tools\Exceptions\InvalidOriginException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\MalformedArrayException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\SignatureException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\NCSignatory; +use OCA\Circles\Tools\Model\NCSignedRequest; +use OCA\Circles\Tools\Model\SimpleDataStore; +use OCA\Circles\Tools\Traits\TNCSignatory; +use OCP\IRequest; + +class NCSignature { + public const DATE_HEADER = 'D, d M Y H:i:s T'; + public const DATE_OBJECT = 'Y-m-d\TH:i:s\Z'; + + public const DATE_TTL = 300; + + + use TNCSignatory; + + + /** @var int */ + private $ttl = self::DATE_TTL; + private $dateHeader = self::DATE_HEADER; + + + /** + * @param string $body + * + * @return NCSignedRequest + * @throws InvalidOriginException + * @throws MalformedArrayException + * @throws SignatoryException + * @throws SignatureException + */ + public function incomingSignedRequest(string $body = ''): NCSignedRequest { + if ($body === '') { + $body = file_get_contents('php://input'); + } + + $this->debug('[<<] incoming', ['body' => $body]); + + $signedRequest = new NCSignedRequest($body); + $signedRequest->setIncomingRequest(OC::$server->get(IRequest::class)); + + $this->verifyIncomingRequestTime($signedRequest); + $this->verifyIncomingRequestContent($signedRequest); + $this->setIncomingSignatureHeader($signedRequest); + $this->setIncomingClearSignature($signedRequest); + $this->parseIncomingSignatureHeader($signedRequest); + $this->verifyIncomingRequestSignature($signedRequest); + + return $signedRequest; + } + + + /** + * @param NCRequest $request + * @param NCSignatory $signatory + * + * @return NCSignedRequest + * @throws SignatoryException + */ + public function signOutgoingRequest(NCRequest $request, NCSignatory $signatory): NCSignedRequest { + $signedRequest = new NCSignedRequest($request->getDataBody()); + $signedRequest->setOutgoingRequest($request) + ->setSignatory($signatory); + + $this->setOutgoingSignatureHeader($signedRequest); + $this->setOutgoingClearSignature($signedRequest); + $this->setOutgoingSignedSignature($signedRequest); + $this->signingOutgoingRequest($signedRequest); + + return $signedRequest; + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatureException + */ + private function verifyIncomingRequestTime(NCSignedRequest $signedRequest): void { + $request = $signedRequest->getIncomingRequest(); + + try { + $dTime = new DateTime($request->getHeader('date')); + $signedRequest->setTime($dTime->getTimestamp()); + } catch (Exception $e) { + $this->e($e, ['header' => $request->getHeader('date')]); + throw new SignatureException('datetime exception'); + } + + if ($signedRequest->getTime() < (time() - $this->ttl)) { + throw new SignatureException('object is too old'); + } + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatureException + */ + private function verifyIncomingRequestContent(NCSignedRequest $signedRequest): void { + $request = $signedRequest->getIncomingRequest(); + + if (strlen($signedRequest->getBody()) !== (int)$request->getHeader('content-length')) { + throw new SignatureException('issue with content-length'); + } + + if ($request->getHeader('digest') !== '' + && $signedRequest->getDigest() !== $request->getHeader('digest')) { + throw new SignatureException('issue with digest'); + } + } + + /** + * @param NCSignedRequest $signedRequest + */ + private function setIncomingSignatureHeader(NCSignedRequest $signedRequest): void { + $sign = []; + $request = $signedRequest->getIncomingRequest(); + foreach (explode(',', $request->getHeader('Signature')) as $entry) { + if ($entry === '' || !strpos($entry, '=')) { + continue; + } + + [$k, $v] = explode('=', $entry, 2); + preg_match('/"([^"]+)"/', $v, $varr); + if ($varr[0] !== null) { + $v = trim($varr[0], '"'); + } + $sign[$k] = $v; + } + + $signedRequest->setSignatureHeader(new SimpleDataStore($sign)); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatureException + */ + private function setIncomingClearSignature(NCSignedRequest $signedRequest): void { + $request = $signedRequest->getIncomingRequest(); + $headers = explode(' ', $signedRequest->getSignatureHeader()->g('headers')); + + $enforceHeaders = array_merge( + ['content-length', 'date', 'host'], + $this->setupArray('enforceSignatureHeaders') + ); + if (!empty(array_diff($enforceHeaders, $headers))) { + throw new SignatureException('missing elements in \'headers\''); + } + + $target = strtolower($request->getMethod()) . " " . $request->getRequestUri(); + $estimated = ['(request-target): ' . $target]; + + foreach ($headers as $key) { + $value = $request->getHeader($key); + if (strtolower($key) === 'host') { + $value = $signedRequest->getIncomingRequest()->getServerHost(); + } + if ($value === '') { + throw new SignatureException('empty elements in \'headers\''); + } + + $estimated[] = $key . ': ' . $value; + } + $signedRequest->setClearSignature(implode("\n", $estimated)); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws MalformedArrayException + * @throws InvalidOriginException + */ + private function parseIncomingSignatureHeader(NCSignedRequest $signedRequest): void { + $data = $signedRequest->getSignatureHeader(); + $data->hasKeys(['keyId', 'headers', 'signature'], true); + + $signedRequest->setOrigin($this->getKeyOrigin($data->g('keyId'))); + $signedRequest->setSignedSignature($data->g('signature')); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatoryException + * @throws SignatureException + */ + private function verifyIncomingRequestSignature(NCSignedRequest $signedRequest) { + $data = $signedRequest->getSignatureHeader(); + + try { + $signedRequest->setSignatory($this->retrieveSignatory($data->g('keyId'), false)); + $this->verifySignedRequest($signedRequest); + } catch (SignatoryException $e) { + $signedRequest->setSignatory($this->retrieveSignatory($data->g('keyId'), true)); + $this->verifySignedRequest($signedRequest); + } + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatureException + */ + private function verifySignedRequest(NCSignedRequest $signedRequest) { + $publicKey = $signedRequest->getSignatory()->getPublicKey(); + if ($publicKey === '') { + throw new SignatureException('empty public key'); + } + + try { + $this->verifyString( + $signedRequest->getClearSignature(), + base64_decode($signedRequest->getSignedSignature()), + $publicKey, + $this->getUsedEncryption($signedRequest) + ); + } catch (SignatureException $e) { + $this->debug('signature issue', ['signed' => $signedRequest]); + throw $e; + } + } + + + /** + * @param NCSignedRequest $signedRequest + */ + private function setOutgoingSignatureHeader(NCSignedRequest $signedRequest): void { + $request = $signedRequest->getOutgoingRequest(); + + $data = new SimpleDataStore(); + $data->s('(request-target)', NCRequest::method($request->getType()) . ' ' . $request->getPath()) + ->sInt('content-length', strlen($signedRequest->getBody())) + ->s('date', gmdate($this->dateHeader)) + ->s('digest', $signedRequest->getDigest()) + ->s('host', $request->getHost()); + + $signedRequest->setSignatureHeader($data); + } + + + /** + * @param NCSignedRequest $signedRequest + */ + private function setOutgoingClearSignature(NCSignedRequest $signedRequest): void { + $signing = []; + $data = $signedRequest->getSignatureHeader(); + foreach ($data->keys() as $element) { + try { + $value = $data->gItem($element); + $signing[] = $element . ': ' . $value; + if ($element !== '(request-target)') { + $signedRequest->getOutgoingRequest()->addHeader($element, $value); + } + } catch (ItemNotFoundException $e) { + } + } + + $signedRequest->setClearSignature(implode("\n", $signing)); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @throws SignatoryException + */ + private function setOutgoingSignedSignature(NCSignedRequest $signedRequest): void { + $clear = $signedRequest->getClearSignature(); + $signed = $this->signString($clear, $signedRequest->getSignatory()); + $signedRequest->setSignedSignature($signed); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @return void + */ + private function signingOutgoingRequest(NCSignedRequest $signedRequest): void { + $headers = array_diff($signedRequest->getSignatureHeader()->keys(), ['(request-target)']); + $signatory = $signedRequest->getSignatory(); + $signatureElements = [ + 'keyId="' . $signatory->getKeyId() . '"', + 'algorithm="' . $this->getChosenEncryption($signatory) . '"', + 'headers="' . implode(' ', $headers) . '"', + 'signature="' . $signedRequest->getSignedSignature() . '"' + ]; + + $signedRequest->getOutgoingRequest()->addHeader('Signature', implode(',', $signatureElements)); + } + + + /** + * @param NCSignedRequest $signedRequest + * + * @return string + */ + private function getUsedEncryption(NCSignedRequest $signedRequest): string { + switch ($signedRequest->getSignatureHeader()->g('algorithm')) { + case 'rsa-sha512': + return NCSignatory::SHA512; + + case 'rsa-sha256': + default: + return NCSignatory::SHA256; + } + } + + /** + * @param NCSignatory $signatory + * + * @return string + */ + private function getChosenEncryption(NCSignatory $signatory): string { + switch ($signatory->getAlgorithm()) { + case NCSignatory::SHA512: + return 'ras-sha512'; + + case NCSignatory::SHA256: + default: + return 'ras-sha256'; + } + } + + + /** + * @param NCSignatory $signatory + * + * @return int + */ + public function getOpenSSLAlgo(NCSignatory $signatory): int { + switch ($signatory->getAlgorithm()) { + case NCSignatory::SHA512: + return OPENSSL_ALGO_SHA512; + + case NCSignatory::SHA256: + default: + return OPENSSL_ALGO_SHA256; + } + } +} diff --git a/lib/Tools/Db/ExtendedQueryBuilder.php b/lib/Tools/Db/ExtendedQueryBuilder.php new file mode 100644 index 000000000..3ef6dc45a --- /dev/null +++ b/lib/Tools/Db/ExtendedQueryBuilder.php @@ -0,0 +1,1135 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Db; + +use DateInterval; +use DateTime; +use Doctrine\DBAL\Query\QueryBuilder as DBALQueryBuilder; +use Exception; +use OC; +use OC\DB\QueryBuilder\QueryBuilder; +use OC\SystemConfig; +use OCA\Circles\Tools\Exceptions\DateTimeException; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\RowNotFoundException; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCP\DB\QueryBuilder\ICompositeExpression; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\ILogger; + +class ExtendedQueryBuilder extends QueryBuilder { + use TArrayTools; + + + /** @var string */ + private $defaultSelectAlias = ''; + + /** @var array */ + private $defaultValues = []; + + + public function __construct() { + parent::__construct( + OC::$server->get(IDBConnection::class), + OC::$server->get(SystemConfig::class), + OC::$server->get(ILogger::class) + ); + } + + + /** + * @param string $alias + * + * @return self + */ + public function setDefaultSelectAlias(string $alias): self { + $this->defaultSelectAlias = $alias; + + return $this; + } + + /** + * @return string + */ + public function getDefaultSelectAlias(): string { + return $this->defaultSelectAlias; + } + + + /** + * @return array + */ + public function getDefaultValues(): array { + return $this->defaultValues; + } + + /** + * @param string $key + * @param string $value + * + * @return $this + */ + public function addDefaultValue(string $key, string $value): self { + $this->defaultValues[$key] = $value; + + return $this; + } + + /** + * @param int $size + * @param int $page + */ + public function paginate(int $size, int $page = 0): void { + if ($page < 0) { + $page = 0; + } + + $this->chunk($page * $size, $size); + } + + /** + * @param int $offset + * @param int $limit + */ + public function chunk(int $offset, int $limit): void { + if ($offset > -1) { + $this->setFirstResult($offset); + } + + if ($limit > 0) { + $this->setMaxResults($limit); + } + } + + + /** + * Limit the request to the Id + * + * @param int $id + */ + public function limitToId(int $id): void { + $this->limitInt('id', $id); + } + + /** + * @param array $ids + */ + public function limitToIds(array $ids): void { + $this->limitArray('id', $ids); + } + + /** + * @param string $id + */ + public function limitToIdString(string $id): void { + $this->limit('id', $id); + } + + /** + * @param string $userId + */ + public function limitToUserId(string $userId): void { + $this->limit('user_id', $userId); + } + + /** + * @param string $uniqueId + */ + public function limitToUniqueId(string $uniqueId): void { + $this->limit('unique_id', $uniqueId); + } + + /** + * @param string $memberId + */ + public function limitToMemberId(string $memberId): void { + $this->limit('member_id', $memberId); + } + + /** + * @param string $status + */ + public function limitToStatus(string $status): void { + $this->limit('status', $status, '', false); + } + + /** + * @param int $type + */ + public function limitToType(int $type): void { + $this->limitInt('type', $type); + } + + /** + * @param string $type + */ + public function limitToTypeString(string $type): void { + $this->limit('type', $type, '', false); + } + + /** + * @param string $token + */ + public function limitToToken(string $token): void { + $this->limit('token', $token); + } + + + /** + * Limit the request to the creation + * + * @param int $delay + * + * @return self + * @throws Exception + */ + public function limitToCreation(int $delay = 0): self { + $date = new DateTime('now'); + $date->sub(new DateInterval('PT' . $delay . 'M')); + + $this->limitToDBFieldDateTime('creation', $date, true); + + return $this; + } + + + /** + * @param string $field + * @param DateTime $date + * @param bool $orNull + */ + public function limitToDBFieldDateTime(string $field, DateTime $date, bool $orNull = false): void { + $expr = $this->expr(); + $pf = ($this->getType() === DBALQueryBuilder::SELECT) ? $this->getDefaultSelectAlias() + . '.' : ''; + $field = $pf . $field; + + $orX = $expr->orX(); + $orX->add( + $expr->lte($field, $this->createNamedParameter($date, IQueryBuilder::PARAM_DATE)) + ); + + if ($orNull === true) { + $orX->add($expr->isNull($field)); + } + + $this->andWhere($orX); + } + + + /** + * @param int $timestamp + * @param string $field + * + * @throws DateTimeException + */ + public function limitToSince(int $timestamp, string $field): void { + try { + $dTime = new DateTime(); + $dTime->setTimestamp($timestamp); + } catch (Exception $e) { + throw new DateTimeException($e->getMessage()); + } + + $expr = $this->expr(); + $pf = ($this->getType() === DBALQueryBuilder::SELECT) ? $this->getDefaultSelectAlias() . '.' : ''; + $field = $pf . $field; + + $orX = $expr->orX(); + $orX->add( + $expr->gte($field, $this->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)) + ); + + $this->andWhere($orX); + } + + + /** + * @param string $field + * @param string $value + */ + public function searchInDBField(string $field, string $value): void { + $expr = $this->expr(); + + $pf = ($this->getType() === DBALQueryBuilder::SELECT) ? $this->getDefaultSelectAlias() . '.' : ''; + $field = $pf . $field; + + $this->andWhere($expr->iLike($field, $this->createNamedParameter($value))); + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + */ + public function like(string $field, string $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprLike($field, $value, $alias, $cs)); + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + */ + public function limit(string $field, string $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprLimit($field, $value, $alias, $cs)); + } + + /** + * @param string $field + * @param int $value + * @param string $alias + */ + public function limitInt(string $field, int $value, string $alias = ''): void { + $this->andWhere($this->exprLimitInt($field, $value, $alias)); + } + + /** + * @param string $field + * @param bool $value + * @param string $alias + */ + public function limitBool(string $field, bool $value, string $alias = ''): void { + $this->andWhere($this->exprLimitBool($field, $value, $alias)); + } + + /** + * @param string $field + * @param bool $orNull + * @param string $alias + */ + public function limitEmpty(string $field, bool $orNull = false, string $alias = ''): void { + $this->andWhere($this->exprLimitEmpty($field, $orNull, $alias)); + } + + /** + * @param string $field + * @param bool $orEmpty + * @param string $alias + */ + public function limitNull(string $field, bool $orEmpty = false, string $alias = ''): void { + $this->andWhere($this->exprLimitNull($field, $orEmpty, $alias)); + } + + /** + * @param string $field + * @param array $value + * @param string $alias + * @param bool $cs + */ + public function limitArray(string $field, array $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprLimitArray($field, $value, $alias, $cs)); + } + + /** + * @param string $field + * @param array $value + * @param string $alias + */ + public function limitInArray(string $field, array $value, string $alias = ''): void { + $this->andWhere($this->exprLimitInArray($field, $value, $alias)); + } + + /** + * @param string $field + * @param int $flag + * @param string $alias + */ + public function limitBitwise(string $field, int $flag, string $alias = ''): void { + $this->andWhere($this->exprLimitBitwise($field, $flag, $alias)); + } + + /** + * @param string $field + * @param int $value + * @param bool $gte + * @param string $alias + */ + public function gt(string $field, int $value, bool $gte = false, string $alias = ''): void { + $this->andWhere($this->exprGt($field, $value, $gte, $alias)); + } + + /** + * @param string $field + * @param int $value + * @param bool $lte + * @param string $alias + */ + public function lt(string $field, int $value, bool $lte = false, string $alias = ''): void { + $this->andWhere($this->exprLt($field, $value, $lte, $alias)); + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + * + * @return string + */ + public function exprLike(string $field, string $value, string $alias = '', bool $cs = true): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + if ($cs) { + return $expr->like($field, $this->createNamedParameter($value)); + } else { + return $expr->iLike($field, $this->createNamedParameter($value)); + } + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + * + * @return string + */ + public function exprLimit(string $field, string $value, string $alias = '', bool $cs = true): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + if ($value === '') { + return $expr->emptyString($field); + } + if ($cs) { + return $expr->eq($field, $this->createNamedParameter($value)); + } else { + $func = $this->func(); + + return $expr->eq($func->lower($field), $func->lower($this->createNamedParameter($value))); + } + } + + + /** + * @param string $field + * @param int $value + * @param string $alias + * + * @return string + */ + public function exprLimitInt(string $field, int $value, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->eq($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } + + + /** + * @param string $field + * @param bool $value + * @param string $alias + * + * @return string + */ + public function exprLimitBool(string $field, bool $value, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->eq($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_BOOL)); + } + + /** + * @param string $field + * @param bool $orNull + * @param string $alias + * + * @return ICompositeExpression + */ + public function exprLimitEmpty( + string $field, + bool $orNull = false, + string $alias = '' + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + $orX = $expr->orX(); + $orX->add($expr->emptyString($field)); + if ($orNull) { + $orX->add($expr->isNull($field)); + } + + return $orX; + } + + /** + * @param string $field + * @param bool $orEmpty + * @param string $alias + * + * @return ICompositeExpression + */ + public function exprLimitNull( + string $field, + bool $orEmpty = false, + string $alias = '' + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + $orX = $expr->orX(); + $orX->add($expr->isNull($field)); + if ($orEmpty) { + $orX->add($expr->emptyString($field)); + } + + return $orX; + } + + + /** + * @param string $field + * @param array $values + * @param string $alias + * @param bool $cs + * + * @return ICompositeExpression + */ + public function exprLimitArray( + string $field, + array $values, + string $alias = '', + bool $cs = true + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $andX = $this->expr()->andX(); + foreach ($values as $value) { + if (is_integer($value)) { + $andX->add($this->exprLimitInt($field, $value, $alias)); + } else { + $andX->add($this->exprLimit($field, $value, $alias, $cs)); + } + } + + return $andX; + } + + + /** + * @param string $field + * @param array $values + * @param string $alias + * + * @return string + */ + public function exprLimitInArray(string $field, array $values, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->in($field, $this->createNamedParameter($values, IQueryBuilder::PARAM_STR_ARRAY)); + } + + + /** + * @param string $field + * @param int $flag + * @param string $alias + * + * @return string + */ + public function exprLimitBitwise(string $field, int $flag, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->gt( + $expr->bitwiseAnd($field, $flag), + $this->createNamedParameter(0, IQueryBuilder::PARAM_INT) + ); + } + + + /** + * @param string $field + * @param int $value + * @param bool $lte + * @param string $alias + * + * @return string + */ + public function exprLt(string $field, int $value, bool $lte = false, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + if ($lte) { + return $expr->lte($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } else { + return $expr->lt($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } + } + + /** + * @param string $field + * @param int $value + * @param bool $gte + * @param string $alias + * + * @return string + */ + public function exprGt(string $field, int $value, bool $gte = false, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + if ($gte) { + return $expr->gte($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } else { + return $expr->gt($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + */ + public function unlike(string $field, string $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprUnlike($field, $value, $alias, $cs)); + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + */ + public function filter(string $field, string $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprFilter($field, $value, $alias, $cs)); + } + + /** + * @param string $field + * @param int $value + * @param string $alias + */ + public function filterInt(string $field, int $value, string $alias = ''): void { + $this->andWhere($this->exprFilterInt($field, $value, $alias)); + } + + /** + * @param string $field + * @param bool $value + * @param string $alias + */ + public function filterBool(string $field, bool $value, string $alias = ''): void { + $this->andWhere($this->exprFilterBool($field, $value, $alias)); + } + + /** + * @param string $field + * @param bool $norNull + * @param string $alias + */ + public function filterEmpty(string $field, bool $norNull = false, string $alias = ''): void { + $this->andWhere($this->exprFilterEmpty($field, $norNull, $alias)); + } + + /** + * @param string $field + * @param bool $norEmpty + * @param string $alias + */ + public function filterNull(string $field, bool $norEmpty = false, string $alias = ''): void { + $this->andWhere($this->exprFilterNull($field, $norEmpty, $alias)); + } + + /** + * @param string $field + * @param array $value + * @param string $alias + * @param bool $cs + */ + public function filterArray(string $field, array $value, string $alias = '', bool $cs = true): void { + $this->andWhere($this->exprFilterArray($field, $value, $alias, $cs)); + } + + /** + * @param string $field + * @param array $value + * @param string $alias + */ + public function filterInArray(string $field, array $value, string $alias = ''): void { + $this->andWhere($this->exprFilterInArray($field, $value, $alias)); + } + + /** + * @param string $field + * @param int $flag + * @param string $alias + */ + public function filterBitwise(string $field, int $flag, string $alias = ''): void { + $this->andWhere($this->exprFilterBitwise($field, $flag, $alias)); + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + * + * @return string + */ + public function exprUnlike(string $field, string $value, string $alias = '', bool $cs = true): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + if ($cs) { + return $expr->notLike($field, $this->createNamedParameter($value)); + } else { + $func = $this->func(); + + return $expr->notLike($func->lower($field), $func->lower($this->createNamedParameter($value))); + } + } + + + /** + * @param string $field + * @param string $value + * @param string $alias + * @param bool $cs + * + * @return string + */ + public function exprFilter(string $field, string $value, string $alias = '', bool $cs = true): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + if ($value === '') { + return $expr->nonEmptyString($field); + } + if ($cs) { + return $expr->neq($field, $this->createNamedParameter($value)); + } else { + $func = $this->func(); + + return $expr->neq($func->lower($field), $func->lower($this->createNamedParameter($value))); + } + } + + + /** + * @param string $field + * @param int $value + * @param string $alias + * + * @return string + */ + public function exprFilterInt(string $field, int $value, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->neq($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_INT)); + } + + + /** + * @param string $field + * @param bool $value + * @param string $alias + * + * @return string + */ + public function exprFilterBool(string $field, bool $value, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->neq($field, $this->createNamedParameter($value, IQueryBuilder::PARAM_BOOL)); + } + + /** + * @param string $field + * @param bool $norNull + * @param string $alias + * + * @return ICompositeExpression + */ + public function exprFilterEmpty( + string $field, + bool $norNull = false, + string $alias = '' + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + $andX = $expr->andX(); + $andX->add($expr->nonEmptyString($field)); + if ($norNull) { + $andX->add($expr->isNotNull($field)); + } + + return $andX; + } + + /** + * @param string $field + * @param bool $norEmpty + * @param string $alias + * + * @return ICompositeExpression + */ + public function exprFilterNull( + string $field, + bool $norEmpty = false, + string $alias = '' + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + $andX = $expr->andX(); + $andX->add($expr->isNotNull($field)); + if ($norEmpty) { + $andX->add($expr->nonEmptyString($field)); + } + + return $andX; + } + + + /** + * @param string $field + * @param array $values + * @param string $alias + * @param bool $cs + * + * @return ICompositeExpression + */ + public function exprFilterArray( + string $field, + array $values, + string $alias = '', + bool $cs = true + ): ICompositeExpression { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $orX = $this->expr()->orX(); + foreach ($values as $value) { + if (is_integer($value)) { + $orX->add($this->exprFilterInt($field, $value, $alias)); + } else { + $orX->add($this->exprFilter($field, $value, $alias, $cs)); + } + } + + return $orX; + } + + + /** + * @param string $field + * @param array $values + * @param string $alias + * + * @return string + */ + public function exprFilterInArray(string $field, array $values, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->notIn($field, $this->createNamedParameter($values, IQueryBuilder::PARAM_STR_ARRAY)); + } + + + /** + * @param string $field + * @param int $flag + * @param string $alias + * + * @return string + */ + public function exprFilterBitwise(string $field, int $flag, string $alias = ''): string { + if ($this->getType() === DBALQueryBuilder::SELECT) { + $field = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.' . $field; + } + + $expr = $this->expr(); + + return $expr->eq( + $expr->bitwiseAnd($field, $flag), + $this->createNamedParameter(0, IQueryBuilder::PARAM_INT) + ); + } + + + /** + * @param string $object + * @param array $params + * + * @return IQueryRow + * @throws RowNotFoundException + * @throws InvalidItemException + */ + public function asItem(string $object, array $params = []): IQueryRow { + return $this->getRow([$this, 'parseSimpleSelectSql'], $object, $params); + } + + /** + * @param string $object + * @param array $params + * + * @return IQueryRow[] + */ + public function asItems(string $object, array $params = []): array { + return $this->getRows([$this, 'parseSimpleSelectSql'], $object, $params); + } + + + /** + * @param string $field + * @param array $params + * + * @return IQueryRow + * @throws InvalidItemException + * @throws RowNotFoundException + */ + public function asItemFromField(string $field, array $params = []): IQueryRow { + $param['modelFromField'] = $field; + + return $this->getRow([$this, 'parseSimpleSelectSql'], '', $params); + } + + /** + * @param string $field + * @param array $params + * + * @return IQueryRow[] + */ + public function asItemsFromField(string $field, array $params = []): array { + $param['modelFromField'] = $field; + + return $this->getRows([$this, 'parseSimpleSelectSql'], $field, $params); + } + + + /** + * @param array $data + * @param ExtendedQueryBuilder $qb + * @param string $object + * @param array $params + * + * @return IQueryRow + * @throws InvalidItemException + */ + private function parseSimpleSelectSql( + array $data, + ExtendedQueryBuilder $qb, + string $object, + array $params + ): IQueryRow { + $fromField = $this->get('modelFromField', $params); + if ($fromField !== '') { + $object = $fromField; + } + + $item = new $object(); + if (!($item instanceof IQueryRow)) { + throw new InvalidItemException(); + } + + if (!empty($params)) { + $data['_params'] = $params; + } + + foreach ($qb->getDefaultValues() as $k => $v) { + if ($this->get($k, $data) === '') { + $data[$k] = $v; + } + } + + $data = array_merge($qb->getDefaultValues(), $data); + + $item->importFromDatabase($data); + + return $item; + } + + + /** + * @param callable $method + * @param string $object + * @param array $params + * + * @return IQueryRow + * @throws RowNotFoundException + */ + public function getRow(callable $method, string $object = '', array $params = []): IQueryRow { + $cursor = $this->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new RowNotFoundException(); + } + + return $method($data, $this, $object, $params); + } + + + /** + * @param callable $method + * @param string $object + * @param array $params + * + * @return IQueryRow[] + */ + public function getRows(callable $method, string $object = '', array $params = []): array { + $rows = []; + $cursor = $this->execute(); + while ($data = $cursor->fetch()) { + try { + $rows[] = $method($data, $this, $object, $params); + } catch (Exception $e) { + } + } + $cursor->closeCursor(); + + return $rows; + } + + + /** + * @param string $table + * @param array $fields + * @param string $alias + * + * @return $this + */ + public function generateSelect( + string $table, + array $fields, + string $alias = '' + ): self { + $selectFields = array_map( + function (string $item) use ($alias) { + if ($alias === '') { + return $item; + } + + return $alias . '.' . $item; + }, $fields + ); + + $this->select($selectFields) + ->from($table, $alias) + ->setDefaultSelectAlias($alias); + + return $this; + } + + + /** + * @param array $fields + * @param string $alias + * @param string $prefix + * @param array $default + * + * @return $this + */ + public function generateSelectAlias( + array $fields, + string $alias, + string $prefix, + array $default = [] + ): self { + $prefix = trim($prefix) . '_'; + foreach ($default as $k => $v) { + $this->addDefaultValue($prefix . $k, (string)$v); + } + + foreach ($fields as $field) { + $this->selectAlias($alias . '.' . $field, $prefix . $field); + } + + return $this; + } +} diff --git a/lib/Tools/Db/IQueryRow.php b/lib/Tools/Db/IQueryRow.php new file mode 100644 index 000000000..3d42f4311 --- /dev/null +++ b/lib/Tools/Db/IQueryRow.php @@ -0,0 +1,49 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Db; + +/** + * Interface IQueryRow + * + * @package OCA\Circles\Tools\Db + */ +interface IQueryRow { + + /** + * import data to feed the model. + * + * @param array $data + * + * @return IQueryRow + */ + public function importFromDatabase(array $data): self; +} diff --git a/lib/Tools/Exceptions/ArrayNotFoundException.php b/lib/Tools/Exceptions/ArrayNotFoundException.php new file mode 100644 index 000000000..aece177b5 --- /dev/null +++ b/lib/Tools/Exceptions/ArrayNotFoundException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class ArrayNotFoundException + * + * @package OCA\Circles\Tools\Exceptions + */ +class ArrayNotFoundException extends Exception { +} diff --git a/lib/Tools/Exceptions/DateTimeException.php b/lib/Tools/Exceptions/DateTimeException.php new file mode 100644 index 000000000..638b7649d --- /dev/null +++ b/lib/Tools/Exceptions/DateTimeException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class DateTimeException + * + * @package OCA\Circles\Tools\Exceptions + */ +class DateTimeException extends Exception { +} diff --git a/lib/Tools/Exceptions/InvalidItemException.php b/lib/Tools/Exceptions/InvalidItemException.php new file mode 100644 index 000000000..9c5f205a8 --- /dev/null +++ b/lib/Tools/Exceptions/InvalidItemException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class InvalidItemException + * + * @package OCA\Circles\Tools\Exceptions + */ +class InvalidItemException extends Exception { +} diff --git a/lib/Tools/Exceptions/InvalidOriginException.php b/lib/Tools/Exceptions/InvalidOriginException.php new file mode 100644 index 000000000..e43e8b486 --- /dev/null +++ b/lib/Tools/Exceptions/InvalidOriginException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class InvalidOriginException + * + * @package OCA\Circles\Tools\Exceptions + */ +class InvalidOriginException extends Exception { +} diff --git a/lib/Tools/Exceptions/ItemNotFoundException.php b/lib/Tools/Exceptions/ItemNotFoundException.php new file mode 100644 index 000000000..858d4033f --- /dev/null +++ b/lib/Tools/Exceptions/ItemNotFoundException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class ItemNotFoundException + * + * @package OCA\Circles\Tools\Exceptions + */ +class ItemNotFoundException extends Exception { +} diff --git a/lib/Tools/Exceptions/MalformedArrayException.php b/lib/Tools/Exceptions/MalformedArrayException.php new file mode 100644 index 000000000..acf4c00d1 --- /dev/null +++ b/lib/Tools/Exceptions/MalformedArrayException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class MalformedArrayException + * + * @package OCA\Circles\Tools\Exceptions + */ +class MalformedArrayException extends Exception { +} diff --git a/lib/Tools/Exceptions/RequestContentException.php b/lib/Tools/Exceptions/RequestContentException.php new file mode 100644 index 000000000..ce7fca736 --- /dev/null +++ b/lib/Tools/Exceptions/RequestContentException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RequestContentException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RequestContentException extends Exception { +} diff --git a/lib/Tools/Exceptions/RequestNetworkException.php b/lib/Tools/Exceptions/RequestNetworkException.php new file mode 100644 index 000000000..81254ea21 --- /dev/null +++ b/lib/Tools/Exceptions/RequestNetworkException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RequestNetworkException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RequestNetworkException extends Exception { +} diff --git a/lib/Tools/Exceptions/RequestResultNotJsonException.php b/lib/Tools/Exceptions/RequestResultNotJsonException.php new file mode 100644 index 000000000..08c1bfe8b --- /dev/null +++ b/lib/Tools/Exceptions/RequestResultNotJsonException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RequestResultNotJsonException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RequestResultNotJsonException extends Exception { +} diff --git a/lib/Tools/Exceptions/RequestResultSizeException.php b/lib/Tools/Exceptions/RequestResultSizeException.php new file mode 100644 index 000000000..0ae8bb27d --- /dev/null +++ b/lib/Tools/Exceptions/RequestResultSizeException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RequestResultSizeException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RequestResultSizeException extends Exception { +} diff --git a/lib/Tools/Exceptions/RequestServerException.php b/lib/Tools/Exceptions/RequestServerException.php new file mode 100644 index 000000000..fa4871e42 --- /dev/null +++ b/lib/Tools/Exceptions/RequestServerException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RequestServerException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RequestServerException extends Exception { +} diff --git a/lib/Tools/Exceptions/RowNotFoundException.php b/lib/Tools/Exceptions/RowNotFoundException.php new file mode 100644 index 000000000..1db4c324b --- /dev/null +++ b/lib/Tools/Exceptions/RowNotFoundException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class RowNotFoundException + * + * @package OCA\Circles\Tools\Exceptions + */ +class RowNotFoundException extends Exception { +} diff --git a/lib/Tools/Exceptions/SignatoryException.php b/lib/Tools/Exceptions/SignatoryException.php new file mode 100644 index 000000000..e40219a59 --- /dev/null +++ b/lib/Tools/Exceptions/SignatoryException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class SignatoryException + * + * @package OCA\Circles\Tools\Exceptions + */ +class SignatoryException extends Exception { +} diff --git a/lib/Tools/Exceptions/SignatureException.php b/lib/Tools/Exceptions/SignatureException.php new file mode 100644 index 000000000..94a92efab --- /dev/null +++ b/lib/Tools/Exceptions/SignatureException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class SignatureException + * + * @package OCA\Circles\Tools\Exceptions + */ +class SignatureException extends Exception { +} diff --git a/lib/Tools/Exceptions/UnknownTypeException.php b/lib/Tools/Exceptions/UnknownTypeException.php new file mode 100644 index 000000000..af0bab799 --- /dev/null +++ b/lib/Tools/Exceptions/UnknownTypeException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class UnknownTypeException + * + * @package OCA\Circles\Tools\Exceptions + */ +class UnknownTypeException extends Exception { +} diff --git a/lib/Tools/Exceptions/WellKnownLinkNotFoundException.php b/lib/Tools/Exceptions/WellKnownLinkNotFoundException.php new file mode 100644 index 000000000..acc856546 --- /dev/null +++ b/lib/Tools/Exceptions/WellKnownLinkNotFoundException.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Exceptions; + +use Exception; + +/** + * Class WellKnownLinkNotFoundException + * + * @package OCA\Circles\Tools\Exceptions + */ +class WellKnownLinkNotFoundException extends Exception { +} diff --git a/lib/Tools/IDeserializable.php b/lib/Tools/IDeserializable.php new file mode 100644 index 000000000..bf8d82179 --- /dev/null +++ b/lib/Tools/IDeserializable.php @@ -0,0 +1,42 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools; + +interface IDeserializable { + + /** + * @param array $data + * + * @return self + */ + public function import(array $data): self; +} diff --git a/lib/Tools/Model/NCRequest.php b/lib/Tools/Model/NCRequest.php new file mode 100644 index 000000000..a2aed1e61 --- /dev/null +++ b/lib/Tools/Model/NCRequest.php @@ -0,0 +1,174 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use OCP\Http\Client\IClient; + +class NCRequest extends Request { + + + /** @var IClient */ + private $client; + + /** @var array */ + private $clientOptions = []; + + /** @var bool */ + private $localAddressAllowed = false; + + /** @var NCRequestResult */ + private $result; + + /** @var NCRequestResult[] */ + private $previousResults = []; + + + /** + * @param IClient $client + * + * @return $this + */ + public function setClient(IClient $client): self { + $this->client = $client; + + return $this; + } + + /** + * @return IClient + */ + public function getClient(): IClient { + return $this->client; + } + + + /** + * @return array + */ + public function getClientOptions(): array { + return $this->clientOptions; + } + + /** + * @param array $clientOptions + * + * @return self + */ + public function setClientOptions(array $clientOptions): self { + $this->clientOptions = $clientOptions; + + return $this; + } + + + /** + * @return bool + */ + public function isLocalAddressAllowed(): bool { + return $this->localAddressAllowed; + } + + /** + * @param bool $allowed + * + * @return self + */ + public function setLocalAddressAllowed(bool $allowed): self { + $this->localAddressAllowed = $allowed; + + return $this; + } + + + /** + * @return bool + */ + public function hasResult(): bool { + return ($this->result !== null); + } + + /** + * @return NCRequestResult + */ + public function getResult(): NCRequestResult { + return $this->result; + } + + /** + * @param NCRequestResult $result + * + * @return self + */ + public function setResult(NCRequestResult $result): self { + if (!is_null($this->result)) { + $this->previousResults[] = $this->result; + } + + $this->result = $result; + + return $this; + } + + /** + * @return NCRequestResult[] + */ + public function getPreviousResults(): array { + return $this->previousResults; + } + + /** + * @return NCRequestResult[] + */ + public function getAllResults(): array { + return array_values(array_merge([$this->getResult()], $this->previousResults)); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + $result = null; + if ($this->hasResult()) { + $result = $this->getResult(); + } + + return array_merge( + parent::jsonSerialize(), + [ + 'clientOptions' => $this->getClientOptions(), + 'localAddressAllowed' => $this->isLocalAddressAllowed(), + 'result' => $result + ] + ); + } +} diff --git a/lib/Tools/Model/NCRequestResult.php b/lib/Tools/Model/NCRequestResult.php new file mode 100644 index 000000000..83968c977 --- /dev/null +++ b/lib/Tools/Model/NCRequestResult.php @@ -0,0 +1,321 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use GuzzleHttp\Exception\BadResponseException; +use JsonSerializable; +use OCA\Circles\Tools\Exceptions\RequestContentException; +use OCA\Circles\Tools\Traits\TArrayTools; +use OCP\Http\Client\IResponse; + +class NCRequestResult implements JsonSerializable { + use TArrayTools; + + + public const TYPE_STRING = 0; + public const TYPE_BINARY = 1; + public const TYPE_JSON = 2; + public const TYPE_XRD = 3; + + + /** @var int */ + private $statusCode = 0; + + /** @var array */ + private $headers = []; + + /** @var mixed */ + private $content; + + /** @var array */ + private $contentAsArray = []; + + /** @var int */ + private $contentType = 0; + + /** @var BadResponseException */ + private $exception = null; + + + /** + * NCRequestResult constructor. + * + * @param IResponse|null $response + * @param BadResponseException|null $e + */ + public function __construct(?IResponse $response, ?BadResponseException $e = null) { + if (!is_null($response)) { + $this->setStatusCode($response->getStatusCode()); + $this->setContent($response->getBody()); + $this->setHeaders($response->getHeaders()); + } + + if (!is_null($e)) { + $this->setException($e); + } + + $this->generateMeta(); + } + + + /** + * @return int + */ + public function getStatusCode(): int { + return $this->statusCode; + } + + /** + * @param int $statusCode + * + * @return self + */ + public function setStatusCode(int $statusCode): self { + $this->statusCode = $statusCode; + + return $this; + } + + + /** + * @return array + */ + public function getHeaders(): array { + return $this->headers; + } + + /** + * @param array $headers + * + * @return self + */ + public function setHeaders(array $headers): self { + $this->headers = $headers; + + return $this; + } + + /** + * @param string $key + * + * @return array + */ + public function getHeader(string $key): array { + return $this->getArray($key, $this->headers); + } + + public function withinHeader(string $key, string $needle): bool { + foreach ($this->getHeader($key) as $header) { + if (strpos($header, $needle) !== false) { + return true; + } + } + + return false; + } + + + /** + * @param string $content + * + * @return self + */ + public function setContent(string $content): self { + $this->content = $content; + + return $this; + } + + + /** + * @return string + * @throws RequestContentException + */ + public function getContent(): string { + if (is_null($this->content) || !is_string($this->content)) { + throw new RequestContentException(); + } + + return $this->content; + } + + /** + * @return array + */ + public function getAsArray(): array { + if (empty($this->contentAsArray)) { + $this->generateContentAsArray(); + } + + return $this->contentAsArray; + } + + + /** + * @return string + */ + public function getBinary() { + return $this->content; + } + + + /** + * @return int + */ + public function getContentType(): int { + return $this->contentType; + } + + /** + * @param int $type + * + * @return $this + */ + public function setContentType(int $type): self { + $this->contentType = $type; + + return $this; + } + + /** + * @param int $type + * + * @return bool + */ + public function isContentType(int $type): bool { + return ($this->contentType === $type); + } + + + /** + * + */ + private function generateMeta(): void { + $this->setContentType($this->discoverContentType()); + $this->generateContentAsArray(); + } + + /** + * @return int + */ + private function discoverContentType(): int { + if ($this->withinHeader('Content-Type', 'application/xrd')) { + return self::TYPE_XRD; + } + + if ($this->withinHeader('Content-Type', 'application/json') + || $this->withinHeader('Content-Type', 'application/jrd') + ) { + return self::TYPE_JSON; + } + + try { + $content = $this->getContent(); + } catch (RequestContentException $e) { + return self::TYPE_BINARY; + } + + // in case header failure + $arr = json_decode($content, true); + if (is_array($arr)) { + return self::TYPE_JSON; + } + + return self::TYPE_STRING; + } + + /** + * + */ + private function generateContentAsArray(): void { + try { + $content = $this->getContent(); + if ($this->isContentType(self::TYPE_XRD)) { + $xml = simplexml_load_string($content); + $content = json_encode($xml, JSON_UNESCAPED_SLASHES); + } + + $arr = json_decode($content, true); + if (is_array($arr)) { + $this->contentAsArray = $arr; + } + } catch (RequestContentException $e) { + } + } + + + /** + * @param BadResponseException $e + * + * @return self + */ + public function setException(BadResponseException $e): self { + $this->exception = $e; + $this->setStatusCode($e->getResponse()->getStatusCode()); + + return $this; + } + + /** + * @return BadResponseException + */ + public function getException(): BadResponseException { + return $this->exception; + } + + /** + * @return bool + */ + public function hasException(): bool { + return (!is_null($this->exception)); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + try { + $content = $this->getContent(); + } catch (RequestContentException $e) { + $content = 'not a string'; + } + + return [ + 'statusCode' => $this->getStatusCode(), + 'headers' => $this->getHeaders(), + 'content' => $content, + 'contentAsArray' => $this->contentAsArray, + 'contentType' => $this->getContentType() + ]; + } +} diff --git a/lib/Tools/Model/NCSignatory.php b/lib/Tools/Model/NCSignatory.php new file mode 100644 index 000000000..4533e2238 --- /dev/null +++ b/lib/Tools/Model/NCSignatory.php @@ -0,0 +1,293 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCA\Circles\Tools\Traits\TArrayTools; + +class NCSignatory implements JsonSerializable { + use TArrayTools; + + + public const SHA256 = 'sha256'; + public const SHA512 = 'sha512'; + + + /** @var string */ + private $instance = ''; + + /** @var string */ + private $id = ''; + + /** @var string */ + private $keyOwner = ''; + + /** @var string */ + private $keyId = ''; + + /** @var string */ + private $publicKey = ''; + + /** @var string */ + private $privateKey = ''; + + /** @var array */ + private $origData = []; + + /** @var string */ + private $algorithm = self::SHA256; + + + /** + * NC22Signatory constructor. + * + * @param string $id + */ + public function __construct(string $id = '') { + $this->id = self::removeFragment($id); + } + + + /** + * @param string $instance + * + * @return self + */ + public function setInstance(string $instance): self { + $this->instance = $instance; + + return $this; + } + + /** + * @return string + */ + public function getInstance(): string { + return $this->instance; + } + + + /** + * @return array + */ + public function getOrigData(): array { + return $this->origData; + } + + /** + * /** + * @param array $data + * + * @return $this + */ + public function setOrigData(array $data): self { + $this->origData = $data; + + return $this; + } + + + /** + * @return string + */ + public function getId(): string { + return $this->id; + } + + /** + * @param string $id + * + * @return self + */ + public function setId(string $id): self { + $this->id = $id; + + return $this; + } + + + /** + * @param string $keyId + * + * @return self + */ + public function setKeyId(string $keyId): self { + $this->keyId = $keyId; + + return $this; + } + + /** + * @return string + */ + public function getKeyId(): string { + return $this->keyId; + } + + + /** + * @param string $keyOwner + * + * @return self + */ + public function setKeyOwner(string $keyOwner): self { + $this->keyOwner = $keyOwner; + + return $this; + } + + /** + * @return string + */ + public function getKeyOwner(): string { + return $this->keyOwner; + } + + + /** + * @param string $publicKey + * + * @return self + */ + public function setPublicKey(string $publicKey): self { + $this->publicKey = $publicKey; + + return $this; + } + + /** + * @param string $privateKey + * + * @return self + */ + public function setPrivateKey(string $privateKey): self { + $this->privateKey = $privateKey; + + return $this; + } + + /** + * @return string + */ + public function getPublicKey(): string { + return $this->publicKey; + } + + /** + * @return string + */ + public function getPrivateKey(): string { + return $this->privateKey; + } + + /** + * @return bool + */ + public function hasPublicKey(): bool { + return ($this->publicKey !== ''); + } + + /** + * @return bool + */ + public function hasPrivateKey(): bool { + return ($this->privateKey !== ''); + } + + + /** + * @param string $algorithm + * + * @return self + */ + public function setAlgorithm(string $algorithm): self { + $this->algorithm = $algorithm; + + return $this; + } + + /** + * @return string + */ + public function getAlgorithm(): string { + return $this->algorithm; + } + + + /** + * @param array $data + * + * @return $this + */ + public function import(array $data): self { + if ($this->getId() === '') { + $this->setId($this->get('id', $data)); + } + + $this->setKeyId($this->get('publicKey.id', $data)); + $this->setKeyOwner($this->get('publicKey.owner', $data)); + $this->setPublicKey($this->get('publicKey.publicKeyPem', $data)); + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'publicKey' => + [ + 'id' => $this->getKeyId(), + 'owner' => $this->getKeyOwner(), + 'publicKeyPem' => $this->getPublicKey() + ] + ]; + } + + + /** + * @param string $id + * + * @return string + */ + public static function removeFragment(string $id): string { + $temp = strtok($id, '#'); + if (is_string($temp)) { + $id = $temp; + } + + return $id; + } +} diff --git a/lib/Tools/Model/NCSignedRequest.php b/lib/Tools/Model/NCSignedRequest.php new file mode 100644 index 000000000..f8be4ce4b --- /dev/null +++ b/lib/Tools/Model/NCSignedRequest.php @@ -0,0 +1,348 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCP\IRequest; + +class NCSignedRequest implements JsonSerializable { + + + /** @var string */ + private $body = ''; + + /** @var int */ + private $time = 0; + + /** @var IRequest */ + private $incomingRequest; + + /** @var NCRequest */ + private $outgoingRequest; + + /** @var string */ + private $origin = ''; + + /** @var string */ + private $digest = ''; + + /** @var SimpleDataStore */ + private $signatureHeader; + + /** @var string */ + private $host = ''; + + /** @var string */ + private $clearSignature = ''; + + /** @var string */ + private $signedSignature = ''; + + /** @var NCSignatory */ + private $signatory; + + + public function __construct(string $body = '') { + $this->setBody($body); + } + + + /** + * IRequest of the incoming request + * incoming + * + * @return IRequest + */ + public function getIncomingRequest(): IRequest { + return $this->incomingRequest; + } + + /** + * @param IRequest $request + * + * @return NCSignedRequest + */ + public function setIncomingRequest(IRequest $request): self { + $this->incomingRequest = $request; + + return $this; + } + + + /** + * NCRequest of the outgoing request + * outgoing + * + * @param NCRequest $request + * + * @return NCSignedRequest + */ + public function setOutgoingRequest(NCRequest $request): self { + $this->outgoingRequest = $request; + + return $this; + } + + /** + * @return NCRequest + */ + public function getOutgoingRequest(): NCRequest { + return $this->outgoingRequest; + } + + + /** + * Body content of the request + * incoming/outgoing + * + * @return string + */ + public function getBody(): string { + return $this->body; + } + + /** + * @param string $body + * + * @return self + */ + public function setBody(string $body): self { + $this->body = $body; + $this->setDigest('SHA-256=' . base64_encode(hash("sha256", utf8_encode($body), true))); + + return $this; + } + + + /** + * Timestamp of the request + * incoming (outgoing ?) + * + * @return int + */ + public function getTime(): int { + return $this->time; + } + + /** + * @param int $time + * + * @return self + */ + public function setTime(int $time): self { + $this->time = $time; + + return $this; + } + + + /** + * Origin of the request, based on the keyId + * incoming + * + * @return string + */ + public function getOrigin(): string { + return $this->origin; + } + + /** + * @param string $origin + * + * @return self + */ + public function setOrigin(string $origin): self { + $this->origin = $origin; + + return $this; + } + + + /** + * @return string + */ + public function getDigest(): string { + return $this->digest; + } + + /** + * @param string $digest + * + * @return $this + */ + public function setDigest(string $digest): self { + $this->digest = $digest; + + return $this; + } + + + /** + * Data from the 'Signature' header + * incoming/outgoing + * + * @return SimpleDataStore + */ + public function getSignatureHeader(): SimpleDataStore { + return $this->signatureHeader; + } + + /** + * @param SimpleDataStore $signatureHeader + * + * @return self + */ + public function setSignatureHeader(SimpleDataStore $signatureHeader): self { + $this->signatureHeader = $signatureHeader; + + return $this; + } + + + /** + * _Clear_ value of the Signature. + * incoming/outgoing + * + * - estimated signature on incoming request + * - generated signature on outgoing request + * + * @param string $clearSignature + * + * @return NCSignedRequest + */ + public function setClearSignature(string $clearSignature): self { + $this->clearSignature = $clearSignature; + + return $this; + } + + /** + * @return string + */ + public function getClearSignature(): string { + return $this->clearSignature; + } + + + /** + * _Signed_ value of the signature. + * /!\ base64_encoded, not RAW /!\ + * + * incoming/outgoing + * + * @param string $signedSignature + * + * @return self + */ + public function setSignedSignature(string $signedSignature): self { + $this->signedSignature = $signedSignature; + + return $this; + } + + /** + * @return string + */ + public function getSignedSignature(): string { + return $this->signedSignature; + } + + + /** + * Host/Address to be used in the signature. + * incoming/outgoing + * + * - incoming should set the local address + * - outgoing should set the recipient address + * + * @param string $host + * + * @return NCSignedRequest + */ + public function setHost(string $host): self { + $this->host = $host; + + return $this; + } + + /** + * @return string + */ + public function getHost(): string { + return $this->host; + } + + + /** + * Signatory used to sign the request + * incoming/outgoing + * + * @param NCSignatory $signatory + */ + public function setSignatory(NCSignatory $signatory): void { + $this->signatory = $signatory; + } + + /** + * @return NCSignatory + */ + public function getSignatory(): NCSignatory { + return $this->signatory; + } + + /** + * @return bool + */ + public function hasSignatory(): bool { + return ($this->signatory !== null); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'body' => $this->getBody(), + 'time' => $this->getTime(), + 'incomingRequest' => ($this->incomingRequest !== null), + 'outgoingRequest' => $this->outgoingRequest !== null ? $this->getOutgoingRequest() : false, + 'origin' => $this->getOrigin(), + 'digest' => $this->getDigest(), + 'signatureHeader' => ($this->signatureHeader !== null) ? $this->getSignatureHeader() : false, + 'host' => $this->getHost(), + 'clearSignature' => $this->getClearSignature(), + 'signedSignature' => base64_encode($this->getSignedSignature()), + 'signatory' => ($this->hasSignatory()) ? $this->getSignatory() : false, + ]; + } +} diff --git a/lib/Tools/Model/NCWebfinger.php b/lib/Tools/Model/NCWebfinger.php new file mode 100644 index 000000000..f5594bd79 --- /dev/null +++ b/lib/Tools/Model/NCWebfinger.php @@ -0,0 +1,197 @@ + + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +/** + * Circles - Bring cloud-users closer together. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCA\Circles\Tools\Traits\TArrayTools; + +class NCWebfinger implements JsonSerializable { + use TArrayTools; + + + /** @var string */ + private $subject = ''; + + /** @var array */ + private $aliases = []; + + /** @var array */ + private $properties = []; + + /** @var NCWellKnownLink[] */ + private $links = []; + + + /** + * NC22Webfinger constructor. + * + * @param array $json + */ + public function __construct(array $json = []) { + $this->setSubject($this->get('subject', $json)); + $this->setAliases($this->getArray('subject', $json)); + $this->setProperties($this->getArray('properties', $json)); + + foreach ($this->getArray('links', $json) as $link) { + $this->addLink(new NCWellKnownLink($link)); + } + } + + + /** + * @return string + */ + public function getSubject(): string { + return $this->subject; + } + + /** + * @param string $subject + * + * @return self + */ + public function setSubject(string $subject): self { + $this->subject = $subject; + + return $this; + } + + + /** + * @return array + */ + public function getAliases(): array { + return $this->aliases; + } + + /** + * @param array $aliases + * + * @return self + */ + public function setAliases(array $aliases): self { + $this->aliases = $aliases; + + return $this; + } + + + /** + * @return array + */ + public function getProperties(): array { + return $this->properties; + } + + /** + * @param array $properties + * + * @return self + */ + public function setProperties(array $properties): self { + $this->properties = $properties; + + return $this; + } + + /** + * @param string $key + * + * @return string + */ + public function getProperty(string $key): string { + return $this->get($key, $this->properties); + } + + + /** + * @return NCWellKnownLink[] + */ + public function getLinks(): array { + return $this->links; + } + + /** + * @param NCWellKnownLink[] $links + * + * @return self + */ + public function setLinks(array $links): self { + $this->links = $links; + + return $this; + } + + public function addLink(NCWellKnownLink $link): self { + $this->links[] = $link; + + return $this; + } + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_filter( + [ + 'subject' => $this->getSubject(), + 'aliases' => $this->getAliases(), + 'properties' => $this->getProperties(), + 'links' => $this->getLinks() + ] + ); + } +} diff --git a/lib/Tools/Model/NCWellKnownLink.php b/lib/Tools/Model/NCWellKnownLink.php new file mode 100644 index 000000000..5506d6b49 --- /dev/null +++ b/lib/Tools/Model/NCWellKnownLink.php @@ -0,0 +1,222 @@ + + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +/** + * Circles - Bring cloud-users closer together. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCA\Circles\Tools\Traits\TArrayTools; + +class NCWellKnownLink implements JsonSerializable { + use TArrayTools; + + + /** @var string */ + private $rel = ''; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $href = ''; + + /** @var array */ + private $titles = []; + + /** @var array */ + private $properties = []; + + + /** + * NC22WellKnownLink constructor. + * + * @param array $json + */ + public function __construct(array $json = []) { + $this->setRel($this->get('rel', $json)); + $this->setType($this->get('type', $json)); + $this->setHref($this->get('href', $json)); + $this->setTitles($this->getArray('titles', $json)); + $this->setProperties($this->getArray('properties', $json)); + } + + + /** + * @return string + */ + public function getRel(): string { + return $this->rel; + } + + /** + * @param string $rel + * + * @return self + */ + public function setRel(string $rel): self { + $this->rel = $rel; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return self + */ + public function setType(string $type): self { + $this->type = $type; + + return $this; + } + + + /** + * @return string + */ + public function getHref(): string { + return $this->href; + } + + /** + * @param string $href + * + * @return self + */ + public function setHref(string $href): self { + $this->href = $href; + + return $this; + } + + + /** + * @return array + */ + public function getTitles(): array { + return $this->titles; + } + + /** + * @param array $titles + * + * @return self + */ + public function setTitles(array $titles): self { + $this->titles = $titles; + + return $this; + } + + /** + * @param string $key + * + * @return string + */ + public function getTitle(string $key): string { + return $this->get($key, $this->properties); + } + + + /** + * @return array + */ + public function getProperties(): array { + return $this->properties; + } + + /** + * @param array $properties + * + * @return self + */ + public function setProperties(array $properties): self { + $this->properties = $properties; + + return $this; + } + + /** + * @param string $key + * + * @return string + */ + public function getProperty(string $key): string { + return $this->get($key, $this->properties); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_filter( + [ + 'rel' => $this->getRel(), + 'type' => $this->getType(), + 'href' => $this->getHref(), + 'titles' => $this->getTitles(), + 'properties' => $this->getProperties() + ] + ); + } +} diff --git a/lib/Tools/Model/Request.php b/lib/Tools/Model/Request.php new file mode 100644 index 000000000..0675fd049 --- /dev/null +++ b/lib/Tools/Model/Request.php @@ -0,0 +1,832 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCA\Circles\Tools\Traits\TArrayTools; + +class Request implements JsonSerializable { + use TArrayTools; + + + public const TYPE_GET = 0; + public const TYPE_POST = 1; + public const TYPE_PUT = 2; + public const TYPE_DELETE = 3; + + + public const QS_VAR_DUPLICATE = 1; + public const QS_VAR_ARRAY = 2; + + + /** @var string */ + private $protocol = ''; + + /** @var array */ + private $protocols = ['https']; + + /** @var string */ + private $host = ''; + + /** @var int */ + private $port = 0; + + /** @var string */ + private $url = ''; + + /** @var string */ + private $baseUrl = ''; + + /** @var int */ + private $type = 0; + + /** @var bool */ + private $binary = false; + + /** @var bool */ + private $verifyPeer = true; + + /** @var bool */ + private $httpErrorsAllowed = false; + + /** @var bool */ + private $followLocation = true; + + /** @var array */ + private $headers = []; + + /** @var array */ + private $cookies = []; + + /** @var array */ + private $params = []; + + /** @var array */ + private $data = []; + + /** @var int */ + private $queryStringType = self::QS_VAR_DUPLICATE; + + /** @var int */ + private $timeout = 10; + + /** @var string */ + private $userAgent = ''; + + /** @var int */ + private $resultCode = 0; + + /** @var string */ + private $contentType = ''; + + + /** + * Request constructor. + * + * @param string $url + * @param int $type + * @param bool $binary + */ + public function __construct(string $url = '', int $type = 0, bool $binary = false) { + $this->url = $url; + $this->type = $type; + $this->binary = $binary; + } + + + /** + * @param string $protocol + * + * @return Request + */ + public function setProtocol(string $protocol): Request { + $this->protocols = [$protocol]; + + return $this; + } + + /** + * @param array $protocols + * + * @return Request + */ + public function setProtocols(array $protocols): Request { + $this->protocols = $protocols; + + return $this; + } + + /** + * @return string[] + */ + public function getProtocols(): array { + return $this->protocols; + } + + /** + * @return string + */ + public function getUsedProtocol(): string { + return $this->protocol; + } + + /** + * @param string $protocol + * + * @return Request + */ + public function setUsedProtocol(string $protocol): Request { + $this->protocol = $protocol; + + return $this; + } + + + /** + * @return string + * @deprecated - 19 - use getHost(); + */ + public function getAddress(): string { + return $this->getHost(); + } + + /** + * @param string $address + * + * @return Request + * @deprecated - 19 - use setHost(); + */ + public function setAddress(string $address): Request { + $this->setHost($address); + + return $this; + } + + /** + * @return string + */ + public function getHost(): string { + return $this->host; + } + + /** + * @param string $host + * + * @return Request + */ + public function setHost(string $host): Request { + $this->host = $host; + + return $this; + } + + + /** + * @return int + */ + public function getPort(): int { + return $this->port; + } + + /** + * @param int $port + * + * @return Request + */ + public function setPort(int $port): Request { + $this->port = $port; + + return $this; + } + + + /** + * @param string $instance + * + * @return Request + */ + public function setInstance(string $instance): Request { + if (strpos($instance, ':') === false) { + $this->setHost($instance); + + return $this; + } + + [$host, $port] = explode(':', $instance, 2); + $this->setHost($host); + if ($port !== '') { + $this->setPort((int)$port); + } + + return $this; + } + + + /** + * @return string + */ + public function getInstance(): string { + $instance = $this->getHost(); + if ($this->getPort() > 0) { + $instance .= ':' . $this->getPort(); + } + + return $instance; + } + + + /** + * @param string $url + * + * @deprecated - 19 - use basedOnUrl(); + */ + public function setAddressFromUrl(string $url) { + $this->basedOnUrl($url); + } + + /** + * @param string $url + */ + public function basedOnUrl(string $url) { + $protocol = parse_url($url, PHP_URL_SCHEME); + if ($protocol === null) { + if (strpos($url, '/') > -1) { + [$address, $baseUrl] = explode('/', $url, 2); + $this->setBaseUrl('/' . $baseUrl); + } else { + $address = $url; + } + if (strpos($address, ':') > -1) { + [$address, $port] = explode(':', $address, 2); + $this->setPort((int)$port); + } + $this->setHost($address); + } else { + $this->setProtocols([$protocol]); + $this->setUsedProtocol($protocol); + $this->setHost(parse_url($url, PHP_URL_HOST)); + $this->setBaseUrl(parse_url($url, PHP_URL_PATH)); + if (is_numeric($port = parse_url($url, PHP_URL_PORT))) { + $this->setPort($port); + } + } + } + + /** + * @param string|null $baseUrl + * + * @return Request + */ + public function setBaseUrl(?string $baseUrl): Request { + if ($baseUrl !== null) { + $this->baseUrl = $baseUrl; + } + + return $this; + } + + /** + * @return bool + */ + public function isBinary(): bool { + return $this->binary; + } + + + /** + * @param bool $verifyPeer + * + * @return $this + */ + public function setVerifyPeer(bool $verifyPeer): Request { + $this->verifyPeer = $verifyPeer; + + return $this; + } + + /** + * @return bool + */ + public function isVerifyPeer(): bool { + return $this->verifyPeer; + } + + + /** + * @param bool $httpErrorsAllowed + * + * @return Request + */ + public function setHttpErrorsAllowed(bool $httpErrorsAllowed): Request { + $this->httpErrorsAllowed = $httpErrorsAllowed; + + return $this; + } + + /** + * @return bool + */ + public function isHttpErrorsAllowed(): bool { + return $this->httpErrorsAllowed; + } + + + /** + * @param bool $followLocation + * + * @return $this + */ + public function setFollowLocation(bool $followLocation): Request { + $this->followLocation = $followLocation; + + return $this; + } + + /** + * @return bool + */ + public function isFollowLocation(): bool { + return $this->followLocation; + } + + + /** + * @return string + * @deprecated - 19 - use getParametersUrl() + addParam() + */ + public function getParsedUrl(): string { + $url = $this->getPath(); + $ak = array_keys($this->getData()); + foreach ($ak as $k) { + if (!is_string($this->data[$k])) { + continue; + } + + $url = str_replace(':' . $k, $this->data[$k], $url); + } + + return $url; + } + + /** + * @return string + */ + public function getParametersUrl(): string { + $url = $this->getPath(); + $ak = array_keys($this->getParams()); + foreach ($ak as $k) { + if (!is_string($this->params[$k])) { + continue; + } + + $url = str_replace(':' . $k, $this->params[$k], $url); + } + + return $url; + } + + + /** + * @return string + */ + public function getPath(): string { + return $this->baseUrl . $this->url; + } + + + /** + * @return string + * @deprecated - 19 - use getPath() + */ + public function getUrl(): string { + return $this->getPath(); + } + + + /** + * @return string + */ + public function getCompleteUrl(): string { + $port = ($this->getPort() > 0) ? ':' . $this->getPort() : ''; + + return $this->getUsedProtocol() . '://' . $this->getHost() . $port . $this->getParametersUrl(); + } + + + /** + * @return int + */ + public function getType(): int { + return $this->type; + } + + + public function addHeader($key, $value): Request { + $header = $this->get($key, $this->headers); + if ($header !== '') { + $header .= ', ' . $value; + } else { + $header = $value; + } + + $this->headers[$key] = $header; + + return $this; + } + + /** + * @return array + */ + public function getHeaders(): array { + return array_merge(['User-Agent' => $this->getUserAgent()], $this->headers); + } + + /** + * @param array $headers + * + * @return Request + */ + public function setHeaders(array $headers): Request { + $this->headers = $headers; + + return $this; + } + + + /** + * @return array + */ + public function getCookies(): array { + return $this->cookies; + } + + /** + * @param array $cookies + * + * @return Request + */ + public function setCookies(array $cookies): Request { + $this->cookies = $cookies; + + return $this; + } + + + /** + * @param int $queryStringType + * + * @return Request + */ + public function setQueryStringType(int $queryStringType): self { + $this->queryStringType = $queryStringType; + + return $this; + } + + /** + * @return int + */ + public function getQueryStringType(): int { + return $this->queryStringType; + } + + + /** + * @return array + */ + public function getData(): array { + return $this->data; + } + + + /** + * @param array $data + * + * @return Request + */ + public function setData(array $data): Request { + $this->data = $data; + + return $this; + } + + + /** + * @param string $data + * + * @return Request + */ + public function setDataJson(string $data): Request { + $this->setData(json_decode($data, true)); + + return $this; + } + + + /** + * @param JsonSerializable $data + * + * @return Request + */ + public function setDataSerialize(JsonSerializable $data): Request { + $this->setDataJson(json_encode($data)); + + return $this; + } + + + /** + * @return array + */ + public function getParams(): array { + return $this->params; + } + + /** + * @param array $params + * + * @return Request + */ + public function setParams(array $params): Request { + $this->params = $params; + + return $this; + } + + + /** + * @param string $k + * @param string $v + * + * @return Request + */ + public function addParam(string $k, string $v): Request { + $this->params[$k] = $v; + + return $this; + } + + + /** + * @param string $k + * @param int $v + * + * @return Request + */ + public function addParamInt(string $k, int $v): Request { + $this->params[$k] = $v; + + return $this; + } + + + /** + * @param string $k + * @param string $v + * + * @return Request + */ + public function addData(string $k, string $v): Request { + $this->data[$k] = $v; + + return $this; + } + + + /** + * @param string $k + * @param int $v + * + * @return Request + */ + public function addDataInt(string $k, int $v): Request { + $this->data[$k] = $v; + + return $this; + } + + + /** + * @return string + */ + public function getDataBody(): string { + return json_encode($this->getData()); + } + + /** + * @return string + * @deprecated - 19 - use getUrlParams(); + */ + public function getUrlData(): string { + if ($this->getData() === []) { + return ''; + } + + return preg_replace( + '/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getData()) + ); + } + + /** + * @return string + * @deprecated - 21 - use getQueryString(); + */ + public function getUrlParams(): string { + if ($this->getParams() === []) { + return ''; + } + + return preg_replace( + '/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getParams()) + ); + } + + + /** + * @param int $type + * + * @return string + */ + public function getQueryString(): string { + if (empty($this->getParams())) { + return ''; + } + + switch ($this->getQueryStringType()) { + case self::QS_VAR_ARRAY: + return '?' . http_build_query($this->getParams()); + + case self::QS_VAR_DUPLICATE: + default: + return '?' . preg_replace( + '/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($this->getParams()) + ); + } + } + + + /** + * @return int + */ + public function getTimeout(): int { + return $this->timeout; + } + + /** + * @param int $timeout + * + * @return Request + */ + public function setTimeout(int $timeout): Request { + $this->timeout = $timeout; + + return $this; + } + + + /** + * @return string + */ + public function getUserAgent(): string { + return $this->userAgent; + } + + /** + * @param string $userAgent + * + * @return Request + */ + public function setUserAgent(string $userAgent): Request { + $this->userAgent = $userAgent; + + return $this; + } + + + /** + * @return int + */ + public function getResultCode(): int { + return $this->resultCode; + } + + /** + * @param int $resultCode + * + * @return Request + */ + public function setResultCode(int $resultCode): Request { + $this->resultCode = $resultCode; + + return $this; + } + + + /** + * @return string + */ + public function getContentType(): string { + return $this->contentType; + } + + /** + * @param string $contentType + * + * @return Request + */ + public function setContentType(string $contentType): Request { + $this->contentType = $contentType; + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'protocols' => $this->getProtocols(), + 'used_protocol' => $this->getUsedProtocol(), + 'port' => $this->getPort(), + 'host' => $this->getHost(), + 'url' => $this->getPath(), + 'timeout' => $this->getTimeout(), + 'type' => $this->getType(), + 'cookies' => $this->getCookies(), + 'headers' => $this->getHeaders(), + 'params' => $this->getParams(), + 'data' => $this->getData(), + 'userAgent' => $this->getUserAgent(), + 'followLocation' => $this->isFollowLocation(), + 'verifyPeer' => $this->isVerifyPeer(), + 'binary' => $this->isBinary() + ]; + } + + + /** + * @param string $type + * + * @return int + */ + public static function type(string $type): int { + switch (strtoupper($type)) { + case 'GET': + return self::TYPE_GET; + case 'POST': + return self::TYPE_POST; + case 'PUT': + return self::TYPE_PUT; + case 'DELETE': + return self::TYPE_DELETE; + } + + return 0; + } + + + public static function method(int $type): string { + switch ($type) { + case self::TYPE_GET: + return 'get'; + case self::TYPE_POST: + return 'post'; + case self::TYPE_PUT: + return 'put'; + case self::TYPE_DELETE: + return 'delete'; + } + + return ''; + } +} diff --git a/lib/Tools/Model/SimpleDataStore.php b/lib/Tools/Model/SimpleDataStore.php new file mode 100644 index 000000000..5c9a237fe --- /dev/null +++ b/lib/Tools/Model/SimpleDataStore.php @@ -0,0 +1,488 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +use JsonSerializable; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\MalformedArrayException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; +use OCA\Circles\Tools\IDeserializable; +use OCA\Circles\Tools\Traits\TArrayTools; + +class SimpleDataStore implements JsonSerializable { + use TArrayTools; + + + /** @var array|JsonSerializable */ + private $data; + + + /** + * SimpleDataStore constructor. + * + * @param array|null $data + */ + public function __construct(?array $data = []) { + if (!is_array($data)) { + $data = []; + } + + $this->data = $data; + } + + + /** + * @param array $default + */ + public function default(array $default = []) { + $this->data = array_merge($default, $this->data); + } + + + /** + * @param string $key + * @param string $value + * + * @return SimpleDataStore + */ + public function s(string $key, string $value): self { + $this->data[$key] = $value; + + return $this; + } + + /** + * @param string $key + * + * @return string + */ + public function g(string $key): string { + return $this->get($key, $this->data); + } + + /** + * @param string $key + * + * @return $this + */ + public function u(string $key): self { + if ($this->hasKey($key)) { + unset($this->data[$key]); + } + + return $this; + } + + /** + * @param string $key + * @param string $value + * + * @return SimpleDataStore + */ + public function a(string $key, string $value): self { + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = []; + } + + $this->data[$key][] = $value; + + return $this; + } + + + /** + * @param string $key + * @param int $value + * + * @return SimpleDataStore + */ + public function sInt(string $key, int $value): self { + $this->data[$key] = $value; + + return $this; + } + + /** + * @param string $key + * + * @return int + */ + public function gInt(string $key): int { + return $this->getInt($key, $this->data); + } + + /** + * @param string $key + * @param int $value + * + * @return SimpleDataStore + */ + public function aInt(string $key, int $value): self { + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = []; + } + + $this->data[$key][] = $value; + + return $this; + } + + + /** + * @param string $key + * @param bool $value + * + * @return SimpleDataStore + */ + public function sBool(string $key, bool $value): self { + $this->data[$key] = $value; + + return $this; + } + + /** + * @param string $key + * + * @return bool + */ + public function gBool(string $key): bool { + return $this->getBool($key, $this->data); + } + + /** + * @param string $key + * @param bool $value + * + * @return SimpleDataStore + */ + public function aBool(string $key, bool $value): self { + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = []; + } + + $this->data[$key][] = $value; + + return $this; + } + + + /** + * @param string $key + * @param array $values + * + * @return SimpleDataStore + */ + public function sArray(string $key, array $values): self { + $this->data[$key] = $values; + + return $this; + } + + /** + * @param string $key + * + * @return array + */ + public function gArray(string $key): array { + return $this->getArray($key, $this->data); + } + + /** + * @param string $key + * @param array $values + * + * @return SimpleDataStore + */ + public function aArray(string $key, array $values): self { + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = []; + } + + $this->data[$key] = array_merge($this->data[$key], $values); + + return $this; + } + + + /** + * @param string $key + * @param JsonSerializable $value + * + * @return SimpleDataStore + */ + public function sObj(string $key, JsonSerializable $value): self { + $this->data[$key] = $value; + + return $this; + } + + + /** + * @param string $key + * @param string $class + * + * @return JsonSerializable[] + */ + public function gObjs(string $key, string $class = ''): array { + $list = $this->gArray($key); + $result = []; + foreach ($list as $item) { + $data = new SimpleDataStore([$key => $item]); + $result[] = $data->gObj($key, $class); + } + + return array_filter($result); + } + + + /** + * @param string $key + * @param string $class + * + * @return null|JsonSerializable + * @throws InvalidItemException + * @throws UnknownTypeException + * @throws ItemNotFoundException + */ + public function gObj(string $key, string $class = ''): ?JsonSerializable { + $type = $this->typeOf($key, $this->data); + + if ($type === self::$TYPE_NULL) { + if ($class === '') { + return null; + } + + throw new InvalidItemException(); + } + + if ($type === self::$TYPE_SERIALIZABLE) { + return $this->getObj($key, $this->data); + } + + if ($type === self::$TYPE_ARRAY && $class !== '') { + $item = new $class(); + if (!$item instanceof IDeserializable && !$item instanceof JsonSerializable) { + throw new InvalidItemException( + $class . ' does not implement IDeserializable and JsonSerializable' + ); + } + + $item->import($this->getArray($key, $this->data)); + + return $item; + } + + throw new InvalidItemException(); + } + + /** + * @param string $key + * @param JsonSerializable $value + * + * @return SimpleDataStore + */ + public function aObj(string $key, JsonSerializable $value): self { + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = []; + } + + $this->data[$key][] = $value; + + return $this; + } + + + /** + * @param string $key + * @param SimpleDataStore $data + * + * @return $this + */ + public function sData(string $key, SimpleDataStore $data): self { + $this->data[$key] = $data->gAll(); + + return $this; + } + + /** + * @param string $key + * @param SimpleDataStore $data + * + * @return $this + */ + public function aData(string $key, SimpleDataStore $data): self { + if (!array_key_exists($key, $this->data) || !is_array($this->data[$key])) { + $this->data[$key] = []; + } + + $this->data[$key][] = $data->gAll(); + + return $this; + } + + /** + * @param string $key + * + * @return SimpleDataStore + */ + public function gData(string $key): SimpleDataStore { + return new SimpleDataStore($this->getArray($key, $this->data)); + } + + + /** + * @param string $key + * + * @return mixed + * @throws ItemNotFoundException + */ + public function gItem(string $key) { + if (!array_key_exists($key, $this->data)) { + throw new ItemNotFoundException(); + } + + return $this->data[$key]; + } + + + /** + * @return array + */ + public function gAll(): array { + return $this->data; + } + + /** + * @param array $data + * + * @return SimpleDataStore + */ + public function sAll(array $data): self { + $this->data = $data; + + return $this; + } + + + public function keys(): array { + return array_keys($this->data); + } + + /** + * @param string $key + * + * @return bool + */ + public function hasKey(string $key): bool { + return (array_key_exists($key, $this->data)); + } + + + /** + * @param array $keys + * + * @param bool $must + * + * @return bool + * @throws MalformedArrayException + */ + public function hasKeys(array $keys, bool $must = false): bool { + foreach ($keys as $key) { + if (!$this->haveKey($key)) { + if ($must) { + throw new MalformedArrayException($key . ' missing in ' . json_encode($this->keys())); + } + + return false; + } + } + + return true; + } + + + /** + * @param array $keys + * @param bool $must + * + * @return bool + * @throws MalformedArrayException + * @deprecated + */ + public function haveKeys(array $keys, bool $must = false): bool { + return $this->hasKeys($keys, $must); + } + + /** + * @param string $key + * + * @return bool + * @deprecated + */ + public function haveKey(string $key): bool { + return $this->hasKey($key); + } + + + /** + * @param string $json + * + * @return $this + */ + public function json(string $json): self { + $data = json_decode($json, true); + if (is_array($data)) { + $this->data = $data; + } + + return $this; + } + + /** + * @param JsonSerializable $obj + * + * @return $this + */ + public function obj(JsonSerializable $obj): self { + $this->data = $obj; + + return $this; + } + + /** + * @return array + */ + public function jsonSerialize(): array { + return $this->data; + } +} diff --git a/lib/Tools/Model/TreeNode.php b/lib/Tools/Model/TreeNode.php new file mode 100644 index 000000000..67c706e80 --- /dev/null +++ b/lib/Tools/Model/TreeNode.php @@ -0,0 +1,232 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Model; + +class TreeNode { + + + /** @var self[] */ + private $children = []; + + /** @var self */ + private $parent; + + /** @var SimpleDataStore */ + private $item; + + + /** @var self */ + private $currentChild; + + /** @var bool */ + private $displayed = false; + + /** @var bool */ + private $splited = false; + + + /** + * NC22TreeNode constructor. + * + * @param self|null $parent + * @param SimpleDataStore $item + */ + public function __construct(?TreeNode $parent, SimpleDataStore $item) { + $this->parent = $parent; + $this->item = $item; + + if ($this->parent !== null) { + $this->parent->addChild($this); + } + } + + /** + * @return bool + */ + public function isRoot(): bool { + return (is_null($this->parent)); + } + + + /** + * @param array $children + * + * @return TreeNode + */ + public function setChildren(array $children): self { + $this->children = $children; + + return $this; + } + + /** + * @param TreeNode $child + * + * @return $this + */ + public function addChild(TreeNode $child): self { + $this->children[] = $child; + + return $this; + } + + + /** + * @return SimpleDataStore + */ + public function getItem(): SimpleDataStore { + $this->displayed = true; + + return $this->item; + } + + + /** + * @return TreeNode + */ + public function getParent(): TreeNode { + return $this->parent; + } + + + /** + * @return $this + */ + public function getRoot(): TreeNode { + if ($this->isRoot()) { + return $this; + } + + return $this->getParent()->getRoot(); + } + + + /** + * @return TreeNode[] + */ + public function getPath(): array { + if ($this->isRoot()) { + return [$this]; + } + + return array_merge($this->parent->getPath(), [$this]); + } + + + /** + * @return int + */ + public function getLevel(): int { + if ($this->isRoot()) { + return 0; + } + + return $this->getParent()->getLevel() + 1; + } + + + /** + * @return TreeNode|null + */ + public function current(): ?TreeNode { + if (!$this->isDisplayed()) { + return $this; + } + + $this->splited = true; + if ($this->initCurrentChild()) { + $next = $this->getCurrentChild()->current(); + if (!is_null($next)) { + return $next; + } + } + + if (!$this->haveNext()) { + return null; + } + + return $this->next(); + } + + + /** + * @return TreeNode + */ + private function next(): TreeNode { + $this->currentChild = array_shift($this->children); + + return $this->currentChild; + } + + /** + * @return bool + */ + public function haveNext(): bool { + return !empty($this->children); + } + + + /** + * @return bool + */ + private function initCurrentChild(): bool { + if (is_null($this->currentChild)) { + if (!$this->haveNext()) { + return false; + } + $this->next(); + } + + return true; + } + + /** + * @return TreeNode|null + */ + private function getCurrentChild(): ?TreeNode { + return $this->currentChild; + } + + /** + * @return bool + */ + private function isDisplayed(): bool { + return $this->displayed; + } + + /** + * @return bool + */ + public function isSplited(): bool { + return $this->splited; + } +} diff --git a/lib/Tools/Traits/TArrayTools.php b/lib/Tools/Traits/TArrayTools.php new file mode 100644 index 000000000..9c2f0bda6 --- /dev/null +++ b/lib/Tools/Traits/TArrayTools.php @@ -0,0 +1,432 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use Exception; +use JsonSerializable; +use OCA\Circles\Tools\Exceptions\ArrayNotFoundException; +use OCA\Circles\Tools\Exceptions\ItemNotFoundException; +use OCA\Circles\Tools\Exceptions\MalformedArrayException; +use OCA\Circles\Tools\Exceptions\UnknownTypeException; + +trait TArrayTools { + public static $TYPE_NULL = 'Null'; + public static $TYPE_STRING = 'String'; + public static $TYPE_ARRAY = 'Array'; + public static $TYPE_BOOLEAN = 'Boolean'; + public static $TYPE_INTEGER = 'Integer'; + public static $TYPE_SERIALIZABLE = 'Serializable'; + + + /** + * @param string $k + * @param array $arr + * @param string $default + * + * @return string + */ + protected function get(string $k, array $arr, string $default = ''): string { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + $r = $arr[$subs[0]]; + if (!is_array($r)) { + return $default; + } + + return $this->get($subs[1], $r, $default); + } else { + return $default; + } + } + + if ($arr[$k] === null || !is_string($arr[$k]) && (!is_int($arr[$k]))) { + return $default; + } + + return (string)$arr[$k]; + } + + + /** + * @param string $k + * @param array $arr + * @param int $default + * + * @return int + */ + protected function getInt(string $k, array $arr, int $default = 0): int { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + $r = $arr[$subs[0]]; + if (!is_array($r)) { + return $default; + } + + return $this->getInt($subs[1], $r, $default); + } else { + return $default; + } + } + + if ($arr[$k] === null) { + return $default; + } + + return intval($arr[$k]); + } + + + /** + * @param string $k + * @param array $arr + * @param float $default + * + * @return float + */ + protected function getFloat(string $k, array $arr, float $default = 0): float { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + $r = $arr[$subs[0]]; + if (!is_array($r)) { + return $default; + } + + return $this->getFloat($subs[1], $r, $default); + } else { + return $default; + } + } + + if ($arr[$k] === null) { + return $default; + } + + return intval($arr[$k]); + } + + + /** + * @param string $k + * @param array $arr + * @param bool $default + * + * @return bool + */ + protected function getBool(string $k, array $arr, bool $default = false): bool { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + return $this->getBool($subs[1], $arr[$subs[0]], $default); + } else { + return $default; + } + } + + if ($arr[$k] === null) { + return $default; + } + + if (is_bool($arr[$k])) { + return $arr[$k]; + } + + $sk = (string)$arr[$k]; + if ($sk === '1' || strtolower($sk) === 'true') { + return true; + } + + if ($sk === '0' || strtolower($sk) === 'false') { + return false; + } + + return $default; + } + + + /** + * @param string $k + * @param array $arr + * @param JsonSerializable|null $default + * + * @return mixed + */ + protected function getObj(string $k, array $arr, ?JsonSerializable $default = null): ?JsonSerializable { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + return $this->getObj($subs[1], $arr[$subs[0]], $default); + } else { + return $default; + } + } + + return $arr[$k]; + } + + + /** + * @param string $k + * @param array $arr + * @param array $default + * + * @return array + */ + protected function getArray(string $k, array $arr, array $default = []): array { + if (!array_key_exists($k, $arr)) { + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return $default; + } + + $r = $arr[$subs[0]]; + if (!is_array($r)) { + return $default; + } + + return $this->getArray($subs[1], $r, $default); + } else { + return $default; + } + } + + $r = $arr[$k]; + if (!is_array($r) && !is_string($r)) { + return $default; + } + + if (is_string($r)) { + $r = json_decode($r, true); + } + + if (!is_array($r)) { + return $default; + } + + return $r; + } + + + /** + * @param string $k + * @param array $arr + * + * @return bool + */ + public function validKey(string $k, array $arr): bool { + if (array_key_exists($k, $arr)) { + return true; + } + + $subs = explode('.', $k, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + return false; + } + + $r = $arr[$subs[0]]; + if (!is_array($r)) { + return false; + } + + return $this->validKey($subs[1], $r); + } + + return false; + } + + + /** + * @param string $k + * @param array $arr + * @param array $import + * @param array $default + * + * @return array + */ + protected function getList(string $k, array $arr, array $import, array $default = []): array { + $list = $this->getArray($k, $arr, $default); + + $r = []; + [$obj, $method] = $import; + foreach ($list as $item) { + try { + $o = new $obj(); + $o->$method($item); + + $r[] = $o; + } catch (Exception $e) { + } + } + + return $r; + } + + + /** + * @param string $k + * @param string $value + * @param array $list + * + * @return mixed + * @throws ArrayNotFoundException + */ + protected function extractArray(string $k, string $value, array $list) { + foreach ($list as $arr) { + if (!array_key_exists($k, $arr)) { + continue; + } + + if ($arr[$k] === $value) { + return $arr; + } + } + + throw new ArrayNotFoundException(); + } + + + /** + * @param string $key + * @param array $arr + * @param bool $root + * + * @return string + * @throws ItemNotFoundException + * @throws UnknownTypeException + */ + public function typeOf(string $key, array $arr, bool $root = true): string { + if (array_key_exists($key, $arr)) { + $item = $arr[$key]; + + if (is_null($item)) { + return self::$TYPE_NULL; + } + + if (is_string($item)) { + return self::$TYPE_STRING; + } + + if (is_array($item)) { + return self::$TYPE_ARRAY; + } + + if (is_bool($item)) { + return self::$TYPE_BOOLEAN; + } + + if (is_int($item)) { + return self::$TYPE_INTEGER; + } + + if ($item instanceof JsonSerializable) { + return self::$TYPE_SERIALIZABLE; + } + + throw new UnknownTypeException(); + } + + $subs = explode('.', $key, 2); + if (sizeof($subs) > 1) { + if (!array_key_exists($subs[0], $arr)) { + throw new ItemNotFoundException(); + } + + $r = $arr[$subs[0]]; + if (is_array($r)) { + return $this->typeOf($subs[1], $r); + } + } + + throw new ItemNotFoundException(); + } + + + /** + * @param array $keys + * @param array $arr + * + * @throws MalformedArrayException + */ + protected function mustContains(array $keys, array $arr) { + foreach ($keys as $key) { + if (!array_key_exists($key, $arr)) { + throw new MalformedArrayException( + 'source: ' . json_encode($arr) . ' - missing key: ' . $key + ); + } + } + } + + + /** + * @param array $arr + */ + protected function cleanArray(array &$arr) { + $arr = array_filter( + $arr, + function ($v) { + if (is_string($v)) { + return ($v !== ''); + } + if (is_array($v)) { + return !empty($v); + } + + return true; + } + ); + } +} diff --git a/lib/Tools/Traits/TAsync.php b/lib/Tools/Traits/TAsync.php new file mode 100644 index 000000000..1a0b5de97 --- /dev/null +++ b/lib/Tools/Traits/TAsync.php @@ -0,0 +1,75 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use JsonSerializable; + +trait TAsync { + use TNCSetup; + + + /** @var string */ + public static $SETUP_TIME_LIMIT = 'async_time_limit'; + + + /** + * Hacky way to async the rest of the process without keeping client on hold. + * + * @param string $result + */ + public function async(string $result = ''): void { + if (ob_get_contents() !== false) { + ob_end_clean(); + } + + header('Connection: close'); + header('Content-Encoding: none'); + ignore_user_abort(); + $timeLimit = $this->setupInt(self::$SETUP_TIME_LIMIT); + set_time_limit(($timeLimit > 0) ? $timeLimit : 0); + ob_start(); + + echo($result); + + $size = ob_get_length(); + header('Content-Length: ' . $size); + ob_end_flush(); + flush(); + } + + /** + * @param JsonSerializable $obj + */ + public function asyncObj(JsonSerializable $obj): void { + $this->async(json_encode($obj)); + } +} diff --git a/lib/Tools/Traits/TConsoleTree.php b/lib/Tools/Traits/TConsoleTree.php new file mode 100644 index 000000000..96e512357 --- /dev/null +++ b/lib/Tools/Traits/TConsoleTree.php @@ -0,0 +1,142 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OCA\Circles\Tools\Model\TreeNode; +use Symfony\Component\Console\Output\ConsoleOutput; + +trait TConsoleTree { + + + /** + * @param TreeNode $root + * @param callable $method + * @param array $config + */ + public function drawTree( + TreeNode $root, + callable $method, + array $config = [ + 'height' => 1, + 'node-spacing' => 0, + 'item-spacing' => 0, + ] + ): void { + $config = array_merge( + [ + 'height' => 1, + 'node-spacing' => 0, + 'item-spacing' => 0 + ], $config + ); + + $output = new ConsoleOutput(); + + while (true) { + $node = $root->current(); + if ($node === null) { + return; + } + + $path = $node->getPath(); + array_pop($path); + + $line = $empty = $spacing = ''; + $p = 0; + foreach ($path as $k => $i) { + $line .= ' '; + $empty .= ' '; + if ($k === array_key_last($path)) { + if ($i->haveNext()) { + $line .= '├'; + $empty .= '│'; + } else { + $line .= '└'; + $empty .= ' '; + } + $line .= '── '; + $empty .= ' '; + } else { + if ($i->haveNext()) { + $line .= '│'; + $empty .= '│'; + } else { + $line .= ' '; + $empty .= ' '; + } + $line .= ' '; + $empty .= ' '; + } + $p++; + } + + if ($p < $prec) { + for ($i = 0; $i < $config['node-spacing']; $i++) { + $spacing = substr($empty, 0, -3); + if (substr($spacing, -1) === ' ') { + $spacing = substr($spacing, 0, -1) . '│'; + } + $output->writeln($spacing); + } + } + + $prec = $p; + + for ($i = 1; $i <= $config['height']; $i++) { + $draw = $method($node->getItem(), $i); + if ($draw === '') { + continue; + } + if ($i === 1) { + $output->write($line); + } else { + $output->write($empty); + } + $output->writeln($draw); + } + + if ($node->haveNext()) { + $empty .= ' │'; + } + + if (!$node->isSplited() && $node->haveNext()) { + for ($i = 0; $i < $config['node-spacing']; $i++) { + $output->writeln($empty); + } + } + + for ($i = 0; $i < $config['item-spacing']; $i++) { + $output->writeln($empty); + } + } + } +} diff --git a/lib/Tools/Traits/TDeserialize.php b/lib/Tools/Traits/TDeserialize.php new file mode 100644 index 000000000..e58899458 --- /dev/null +++ b/lib/Tools/Traits/TDeserialize.php @@ -0,0 +1,109 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use JsonSerializable; +use OCA\Circles\Tools\Exceptions\InvalidItemException; +use OCA\Circles\Tools\IDeserializable; + +trait TDeserialize { + + + /** + * @param JsonSerializable $model + * + * @return array + */ + public function serialize(JsonSerializable $model): array { + return json_decode(json_encode($model), true); + } + + /** + * @param array $data + * + * @return array + */ + public function serializeArray(array $data): array { + return json_decode(json_encode($data), true); + } + + + /** + * @param array $data + * @param string $class + * + * @return IDeserializable + * @throws InvalidItemException + */ + public function deserialize(array $data, string $class): IDeserializable { + if ($class instanceof IDeserializable) { + throw new InvalidItemException(get_class($class) . ' does not implement IDeserializable'); + } + + /** @var IDeserializable $item */ + $item = new $class; + $item->import($data); + + return $item; + } + + + /** + * @param array $data + * @param string $class + * + * @return IDeserializable[] + * @throws InvalidItemException + */ + public function deserializeArray(array $data, string $class): array { + $arr = []; + foreach ($data as $entry) { + $arr[] = $this->deserialize($entry, $class); + } + + return $arr; + } + + + /** + * @param string $json + * @param string $class + * + * @return IDeserializable + * @throws InvalidItemException + */ + public function deserializeJson(string $json, string $class): IDeserializable { + $data = json_decode($json, true); + + return $this->deserialize($data, $class); + } +} diff --git a/lib/Tools/Traits/TNCLocalSignatory.php b/lib/Tools/Traits/TNCLocalSignatory.php new file mode 100644 index 000000000..939db98c0 --- /dev/null +++ b/lib/Tools/Traits/TNCLocalSignatory.php @@ -0,0 +1,111 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OC; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Model\NCSignatory; +use OCP\IConfig; + +trait TNCLocalSignatory { + use TNCSignatory; + + public static $SIGNATORIES_APP = 'signatories'; + + + /** + * @param NCSignatory $signatory + * @param bool $generate + * + * @throws SignatoryException + */ + public function fillSimpleSignatory(NCSignatory $signatory, bool $generate = false): void { + $app = $this->setup('app', '', self::$SIGNATORIES_APP); + $signatories = json_decode(OC::$server->get(IConfig::class)->getAppValue($app, 'key_pairs'), true); + if (!is_array($signatories)) { + $signatories = []; + } + + $sign = $this->getArray($signatory->getId(), $signatories); + if (!empty($sign)) { + $signatory->setKeyId($this->get('keyId', $sign)) + ->setKeyOwner($this->get('keyOwner', $sign)) + ->setPublicKey($this->get('publicKey', $sign)) + ->setPrivateKey($this->get('privateKey', $sign)); + + return; + } + + if (!$generate) { + throw new SignatoryException('signatory not found'); + } + + $this->createSimpleSignatory($signatory); + } + + + /** + * @param NCSignatory $signatory + */ + public function createSimpleSignatory(NCSignatory $signatory): void { + $app = $this->setup('app', '', self::$SIGNATORIES_APP); + $signatory->setKeyId($signatory->getId() . '#main-key'); + $signatory->setKeyOwner($signatory->getId()); + $this->generateKeys($signatory); + + $signatories = + json_decode(OC::$server->get(IConfig::class)->getAppValue($app, 'key_pairs', '[]'), true); + $signatories[$signatory->getId()] = [ + 'keyId' => $signatory->getKeyId(), + 'keyOwner' => $signatory->getKeyOwner(), + 'publicKey' => $signatory->getPublicKey(), + 'privateKey' => $signatory->getPrivateKey() + ]; + + OC::$server->get(IConfig::class)->setAppValue($app, 'key_pairs', json_encode($signatories)); + } + + + /** + * @param NCSignatory $signatory + */ + public function removeSimpleSignatory(NCSignatory $signatory): void { + $app = $this->setup('app', '', self::$SIGNATORIES_APP); + $signatories = json_decode(OC::$server->get(IConfig::class)->getAppValue($app, 'key_pairs'), true); + if (!is_array($signatories)) { + $signatories = []; + } + + unset($signatories[$signatory->getId()]); + OC::$server->get(IConfig::class)->setAppValue($app, 'key_pairs', json_encode($signatories)); + } +} diff --git a/lib/Tools/Traits/TNCLogger.php b/lib/Tools/Traits/TNCLogger.php new file mode 100644 index 000000000..9b0077350 --- /dev/null +++ b/lib/Tools/Traits/TNCLogger.php @@ -0,0 +1,201 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use Exception; +use OC; +use OC\HintException; +use Psr\Log\LoggerInterface; +use Throwable; + +trait TNCLogger { + use TNCSetup; + + + public static $EMERGENCY = 4; + public static $ALERT = 3; + public static $CRITICAL = 3; + public static $ERROR = 3; + public static $WARNING = 2; + public static $NOTICE = 1; + public static $INFO = 1; + public static $DEBUG = 0; + + + /** + * @param Throwable $t + * @param array $serializable + */ + public function t(Throwable $t, array $serializable = []): void { + $this->throwable($t, self::$ERROR, $serializable); + } + + /** + * @param Throwable $t + * @param int $level + * @param array $serializable + */ + public function throwable(Throwable $t, int $level = 3, array $serializable = []): void { + $message = ''; + if (!empty($serializable)) { + $message = json_encode($serializable); + } + + $this->logger() + ->log( + $level, + $message, + [ + 'app' => $this->setup('app'), + 'exception' => $t + ] + ); + } + + + /** + * @param Exception $e + * @param array $serializable + */ + public function e(Exception $e, array $serializable = []): void { + $this->exception($e, self::$ERROR, $serializable); + } + + /** + * @param Exception $e + * @param int|array $level + * @param array $serializable + */ + public function exception(Exception $e, $level = 3, array $serializable = []): void { + if (is_array($level) && empty($serializable)) { + $serializable = $level; + $level = 3; + } + + $message = ''; + if (!empty($serializable)) { + $message = json_encode($serializable); + } + + if ($level === self::$DEBUG) { + $level = (int)$this->appConfig('debug_level'); + } + + $this->logger() + ->log( + $level, + $message, + [ + 'app' => $this->setup('app'), + 'exception' => $e + ] + ); + } + + + /** + * @param string $message + * @param bool $trace + * @param array $serializable + */ + public function emergency(string $message, bool $trace = false, array $serializable = []): void { + $this->log(self::$EMERGENCY, '[emergency] ' . $message, $trace, $serializable); + } + + /** + * @param string $message + * @param bool $trace + * @param array $serializable + */ + public function alert(string $message, bool $trace = false, array $serializable = []): void { + $this->log(self::$ALERT, '[alert] ' . $message, $trace, $serializable); + } + + /** + * @param string $message + * @param bool $trace + * @param array $serializable + */ + public function warning(string $message, bool $trace = false, array $serializable = []): void { + $this->log(self::$WARNING, '[warning] ' . $message, $trace, $serializable); + } + + /** + * @param string $message + * @param bool $trace + * @param array $serializable + */ + public function notice(string $message, bool $trace = false, array $serializable = []): void { + $this->log(self::$NOTICE, '[notice] ' . $message, $trace, $serializable); + } + + /** + * @param string $message + * @param array $serializable + */ + public function debug(string $message, array $serializable = []): void { + $message = '[debug] ' . $message; + $debugLevel = (int)$this->appConfig('debug_level'); + $this->log($debugLevel, $message, ($this->appConfig('debug_trace') === '1'), $serializable); + } + + + /** + * @param int $level + * @param string $message + * @param bool $trace + * @param array $serializable + */ + public function log(int $level, string $message, bool $trace = false, array $serializable = []): void { + $opts = ['app' => $this->setup('app')]; + if ($trace) { + $opts['exception'] = new HintException($message, json_encode($serializable)); + } elseif (!empty($serializable)) { + $message .= ' -- ' . json_encode($serializable); + } + + $this->logger() + ->log($level, $message, $opts); + } + + + /** + * @return LoggerInterface + */ + public function logger(): LoggerInterface { + if (isset($this->logger) && $this->logger instanceof LoggerInterface) { + return $this->logger; + } else { + return OC::$server->get(LoggerInterface::class); + } + } +} diff --git a/lib/Tools/Traits/TNCRequest.php b/lib/Tools/Traits/TNCRequest.php new file mode 100644 index 000000000..1528fb2d1 --- /dev/null +++ b/lib/Tools/Traits/TNCRequest.php @@ -0,0 +1,178 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OCA\Circles\Tools\Model\NCRequest; +use Exception; +use GuzzleHttp\Exception\ClientException; +use OC; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Model\NCRequestResult; +use OCA\Circles\Tools\Model\Request; +use OCP\Http\Client\IClientService; +use OCP\Http\Client\IResponse; + +trait TNCRequest { + use TNCLogger; + + + /** + * @param int $size + */ + public function setMaxDownloadSize(int $size) { + } + + + /** + * @param NCRequest $request + * + * @return array + * @throws RequestNetworkException + */ + public function retrieveJson(NCRequest $request): array { + $this->doRequest($request); + $requestResult = $request->getResult(); + + return $requestResult->getAsArray(); + } + + + /** + * @param NCRequest $request + * @param bool $exceptionOnIssue + * + * @throws RequestNetworkException + */ + public function doRequest(NCRequest $request, bool $exceptionOnIssue = true): void { + $request->setClient( + $this->clientService() + ->newClient() + ); + + $this->generationClientOptions($request); + + $this->debug('doRequest initiated', ['request' => $request]); + foreach ($request->getProtocols() as $protocol) { + $request->setUsedProtocol($protocol); + try { + $response = $this->useClient($request); + $request->setResult(new NCRequestResult($response)); + break; + } catch (ClientException $e) { + $request->setResult(new NCRequestResult(null, $e)); + } catch (Exception $e) { + $this->exception($e, self::$DEBUG, ['request' => $request]); + } + } + + $this->debug('doRequest done', ['request' => $request]); + + if ($exceptionOnIssue && (!$request->hasResult() || $request->getResult()->hasException())) { + throw new RequestNetworkException(); + } + } + + + /** + * @return IClientService + */ + public function clientService(): IClientService { + if (isset($this->clientService) && $this->clientService instanceof IClientService) { + return $this->clientService; + } else { + return OC::$server->get(IClientService::class); + } + } + + + /** + * @param NCRequest $request + */ + private function generationClientOptions(NCRequest $request) { + $options = [ + 'headers' => $request->getHeaders(), + 'cookies' => $request->getCookies(), + 'verify' => $request->isVerifyPeer(), + 'timeout' => $request->getTimeout(), + 'http_errors' => !$request->isHttpErrorsAllowed() + ]; + + if (!empty($request->getData())) { + $options['body'] = $request->getDataBody(); + } + + if (!empty($request->getParams())) { + $options['form_params'] = $request->getParams(); + } + + if ($request->isLocalAddressAllowed()) { + $options['nextcloud']['allow_local_address'] = true; + } + + if ($request->isFollowLocation()) { + $options['allow_redirects'] = [ + 'max' => 10, + 'strict' => true, + 'referer' => true, + ]; + } else { + $options['allow_redirects'] = false; + } + + $request->setClientOptions($options); + } + + + /** + * @param NCRequest $request + * + * @return IResponse + * @throws Exception + */ + private function useClient(NCRequest $request): IResponse { + $client = $request->getClient(); + switch ($request->getType()) { + case Request::TYPE_POST: + return $client->post($request->getCompleteUrl(), $request->getClientOptions()); + case Request::TYPE_PUT: + return $client->put($request->getCompleteUrl(), $request->getClientOptions()); + case Request::TYPE_DELETE: + return $client->delete($request->getCompleteUrl(), $request->getClientOptions()); + case Request::TYPE_GET: + return $client->get( + $request->getCompleteUrl() . $request->getQueryString(), $request->getClientOptions() + ); + default: + throw new Exception('unknown request type ' . json_encode($request)); + } + } +} diff --git a/lib/Tools/Traits/TNCSetup.php b/lib/Tools/Traits/TNCSetup.php new file mode 100644 index 000000000..8d70df10c --- /dev/null +++ b/lib/Tools/Traits/TNCSetup.php @@ -0,0 +1,107 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OC; +use OCP\IConfig; + +trait TNCSetup { + use TArrayTools; + + + /** @var array */ + private $_setup = []; + + + /** + * @param string $key + * @param string $value + * + * @param string $default + * + * @return string + */ + public function setup(string $key, string $value = '', string $default = ''): string { + if ($value !== '') { + $this->_setup[$key] = $value; + } + + return $this->get($key, $this->_setup, $default); + } + + /** + * @param string $key + * @param array $value + * @param array $default + * + * @return array + */ + public function setupArray(string $key, array $value = [], array $default = []): array { + if (!empty($value)) { + $this->_setup[$key] = $value; + } + + return $this->getArray($key, $this->_setup, $default); + } + + /** + * @param string $key + * @param int $value + * @param int $default + * + * @return int + */ + public function setupInt(string $key, int $value = -999, int $default = 0): int { + if ($value !== -999) { + $this->_setup[$key] = $value; + } + + return $this->getInt($key, $this->_setup, $default); + } + + /** + * @param string $key + * + * @return string + */ + public function appConfig(string $key): string { + $app = $this->setup('app'); + if ($app === '') { + return ''; + } + + /** @var IConfig $config */ + $config = OC::$server->get(IConfig::class); + + return $config->getAppValue($app, $key, ''); + } +} diff --git a/lib/Tools/Traits/TNCSignatory.php b/lib/Tools/Traits/TNCSignatory.php new file mode 100644 index 000000000..0d28fedf1 --- /dev/null +++ b/lib/Tools/Traits/TNCSignatory.php @@ -0,0 +1,207 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OCA\Circles\Tools\Exceptions\InvalidOriginException; +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\SignatoryException; +use OCA\Circles\Tools\Exceptions\SignatureException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\NCSignatory; + +trait TNCSignatory { + use TNCRequest; + + + /** + * return Signatory by its Id from cache or from direct request. + * Should be overwritten. + * + * @param string $keyId + * @param bool $refresh + * + * @return NCSignatory + * @throws SignatoryException + */ + public function retrieveSignatory(string $keyId, bool $refresh = false): NCSignatory { + if (!$refresh) { + throw new SignatoryException(); + } + + $signatory = new NCSignatory($keyId); + $this->downloadSignatory($signatory, $keyId); + + return $signatory; + } + + + /** + * @param NCSignatory $signatory + * @param string $keyId + * @param array $params + * @param NCRequest|null $request + * + * @throws SignatoryException + */ + public function downloadSignatory( + NCSignatory $signatory, + string $keyId = '', + array $params = [], + ?NCRequest $request = null + ): void { + if (is_null($request)) { + $request = new NCRequest(); + $request->setFollowLocation(true); + $request->setTimeout(5); + } + + $request->basedOnUrl(($keyId !== '') ? $keyId : $signatory->getId()); + $request->setParams($params); + $request->addHeader('Accept', 'application/ld+json'); + + try { + $this->updateSignatory($signatory, $this->retrieveJson($request), $keyId); + } catch (RequestNetworkException $e) { + $this->debug('network issue while downloading Signatory', ['request' => $request]); + throw new SignatoryException('network issue: ' . $e->getMessage()); + } + } + + + /** + * @param NCSignatory $signatory + * @param array $json + * @param string $keyId + * + * @throws SignatoryException + */ + public function updateSignatory(NCSignatory $signatory, array $json, string $keyId = ''): void { + $signatory->setOrigData($json) + ->import($json); + + if ($keyId === '') { + $keyId = $signatory->getKeyId(); + } + + try { + if (($signatory->getId() !== $keyId && $signatory->getKeyId() !== $keyId) + || $signatory->getId() !== $signatory->getKeyOwner() + || $this->getKeyOrigin($signatory->getKeyId()) !== $this->getKeyOrigin($signatory->getId()) + || $signatory->getPublicKey() === '') { + $this->debug('invalid format', ['signatory' => $signatory, 'keyId' => $keyId]); + throw new SignatoryException('invalid format'); + } + } catch (InvalidOriginException $e) { + throw new SignatoryException('invalid origin'); + } + } + + + /** + * @param string $keyId + * + * @return string + * @throws InvalidOriginException + */ + public function getKeyOrigin(string $keyId) { + $host = parse_url($keyId, PHP_URL_HOST); + if (is_string($host) && ($host !== '')) { + return $host; + } + + throw new InvalidOriginException('cannot retrieve origin from ' . $keyId); + } + + + /** + * @param NCSignatory $signatory + * @param string $digest + * @param int $bits + * @param int $type + */ + public function generateKeys( + NCSignatory $signatory, + string $digest = 'rsa', + int $bits = 2048, + int $type = OPENSSL_KEYTYPE_RSA + ) { + $res = openssl_pkey_new( + [ + 'digest_alg' => $digest, + 'private_key_bits' => $bits, + 'private_key_type' => $type, + ] + ); + + openssl_pkey_export($res, $privateKey); + $publicKey = openssl_pkey_get_details($res)['key']; + + $signatory->setPublicKey($publicKey); + $signatory->setPrivateKey($privateKey); + } + + + /** + * @param string $clear + * @param NCSignatory $signatory + * + * @return string + * @throws SignatoryException + */ + public function signString(string $clear, NCSignatory $signatory): string { + $privateKey = $signatory->getPrivateKey(); + if ($privateKey === '') { + throw new SignatoryException('empty private key'); + } + + openssl_sign($clear, $signed, $privateKey, $this->getOpenSSLAlgo($signatory)); + + return base64_encode($signed); + } + + + /** + * @param string $clear + * @param string $signed + * @param string $publicKey + * @param string $algo + * + * @throws SignatureException + */ + public function verifyString( + string $clear, string $signed, string $publicKey, string $algo = NCSignatory::SHA256 + ) { + if (openssl_verify($clear, $signed, $publicKey, $algo) !== 1) { + throw new SignatureException('signature issue'); + } + } +} diff --git a/lib/Tools/Traits/TNCWellKnown.php b/lib/Tools/Traits/TNCWellKnown.php new file mode 100644 index 000000000..334f322df --- /dev/null +++ b/lib/Tools/Traits/TNCWellKnown.php @@ -0,0 +1,128 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use OCA\Circles\Tools\Exceptions\RequestNetworkException; +use OCA\Circles\Tools\Exceptions\WellKnownLinkNotFoundException; +use OCA\Circles\Tools\Model\NCRequest; +use OCA\Circles\Tools\Model\NCWebfinger; +use OCA\Circles\Tools\Model\NCWellKnownLink; +use OCA\Circles\Tools\Model\SimpleDataStore; + +trait TNCWellKnown { + use TNCRequest; + + public static $WEBFINGER = '/.well-known/webfinger'; + + + /** + * @param string $host + * @param string $subject + * @param string $rel + * + * @return SimpleDataStore + * @throws RequestNetworkException + * @throws WellKnownLinkNotFoundException + */ + public function getResourceData(string $host, string $subject, string $rel): SimpleDataStore { + $link = $this->getLink($host, $subject, $rel); + + $request = new NCRequest(''); + $request->basedOnUrl($link->getHref()); + $request->addHeader('Accept', $link->getType()); + $request->setFollowLocation(true); + $request->setLocalAddressAllowed(true); + $request->setTimeout(5); + $data = $this->retrieveJson($request); + + return new SimpleDataStore($data); + } + + + /** + * @param string $host + * @param string $subject + * @param string $rel + * + * @return NCWellKnownLink + * @throws RequestNetworkException + * @throws WellKnownLinkNotFoundException + */ + public function getLink(string $host, string $subject, string $rel): NCWellKnownLink { + return $this->extractLink($rel, $this->getWebfinger($host, $subject)); + } + + + /** + * @param string $host + * @param string $subject + * @param string $rel + * + * @return NCWebfinger + * @throws RequestNetworkException + */ + public function getWebfinger(string $host, string $subject, string $rel = ''): NCWebfinger { + $request = new NCRequest(self::$WEBFINGER); + $request->setHost($host); + $request->setProtocols(['https', 'http']); + $request->setFollowLocation(true); + $request->setLocalAddressAllowed(true); + $request->setTimeout(5); + + $request->addParam('resource', $subject); + if ($rel !== '') { + $request->addParam('rel', $rel); + } + + $result = $this->retrieveJson($request); + + return new NCWebfinger($result); + } + + + /** + * @param string $rel + * @param NCWebfinger $webfinger + * + * @return NCWellKnownLink + * @throws WellKnownLinkNotFoundException + */ + public function extractLink(string $rel, NCWebfinger $webfinger): NCWellKnownLink { + foreach ($webfinger->getLinks() as $link) { + if ($link->getRel() === $rel) { + return $link; + } + } + + throw new WellKnownLinkNotFoundException(); + } +} diff --git a/lib/Tools/Traits/TStringTools.php b/lib/Tools/Traits/TStringTools.php new file mode 100644 index 000000000..38641caa5 --- /dev/null +++ b/lib/Tools/Traits/TStringTools.php @@ -0,0 +1,258 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Tools\Traits; + +use DateTime; +use Exception; + +trait TStringTools { + use TArrayTools; + + + /** + * @param int $length + * + * @return string + */ + protected function token(int $length = 15): string { + $chars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890'; + + $str = ''; + $max = strlen($chars); + for ($i = 0; $i < $length; $i++) { + try { + $str .= $chars[random_int(0, $max - 2)]; + } catch (Exception $e) { + } + } + + return $str; + } + + + /** + * Generate uuid: 2b5a7a87-8db1-445f-a17b-405790f91c80 + * + * @param int $length + * + * @return string + */ + protected function uuid(int $length = 0): string { + $uuid = sprintf( + '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), + mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + + if ($length > 0) { + if ($length <= 16) { + $uuid = str_replace('-', '', $uuid); + } + + $uuid = substr($uuid, 0, $length); + } + + return $uuid; + } + + + /** + * @param string $line + * @param int $length + * + * @return string + */ + protected function cut(string $line, int $length): string { + if (strlen($line) < $length) { + return $line; + } + + return substr($line, 0, $length - 5) . ' (..)'; + } + + /** + * @param string $str1 + * @param string $str2 + * @param bool $cs case sensitive ? + * + * @return string + */ + protected function commonPart(string $str1, string $str2, bool $cs = true): string { + for ($i = 0; $i < strlen($str1) && $i < strlen($str2); $i++) { + $chr1 = $str1[$i]; + $chr2 = $str2[$i]; + + if (!$cs) { + $chr1 = strtolower($chr1); + $chr2 = strtolower($chr2); + } + + if ($chr1 !== $chr2) { + break; + } + } + + return substr($str1, 0, $i); + } + + + /** + * @param string $line + * @param array $params + * + * @return string + */ + protected function feedStringWithParams(string $line, array $params): string { + $ak = array_keys($params); + foreach ($ak as $k) { + $line = str_replace('{' . $k . '}', (string)$params[$k], $line); + } + + return $line; + } + + + /** + * @param int $words + * + * @return string + */ + public function generateRandomSentence(int $words = 5): string { + $sentence = []; + for ($i = 0; $i < $words; $i++) { + $sentence[] = $this->generateRandomWord(rand(2, 12)); + } + + return implode(' ', $sentence); + } + + + /** + * @param int $length + * + * @return string + */ + public function generateRandomWord(int $length = 8): string { + $c = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v']; + $v = ['a', 'e', 'i', 'o', 'u', 'y']; + + $word = []; + for ($i = 0; $i <= ($length / 2); $i++) { + $word[] = $c[array_rand($c)]; + $word[] = $v[array_rand($v)]; + } + + return implode('', $word); + } + + + /** + * @param int $bytes + * + * @return string + */ + public function humanReadable(int $bytes): string { + if ($bytes == 0) { + return '0.00 B'; + } + + $s = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; + $e = floor(log($bytes, 1024)); + + return round($bytes / pow(1024, $e), 2) . ' ' . $s[$e]; + } + + + /** + * @param int $first + * @param int $second + * @param bool $short + * + * @return string + * @throws Exception + */ + public function getDateDiff( + int $first, + int $second = 0, + bool $short = false, + array $words = [] + ): string { + if ($second === 0) { + $first = time() - $first; + $second = time(); + } + + $f = new DateTime('@' . $first); + $s = new DateTime('@' . $second); + $duration = $second - $first; + if ($short) { + $minutes = $this->get('minutes', $words, 'M'); + $hours = $this->get('hours', $words, 'H'); + $days = $this->get('days', $words, 'D'); + + if ($duration < 60) { + return $f->diff($s)->format('<1' . $minutes); + } + if ($duration < 3600) { + return $f->diff($s)->format('%i' . $minutes); + } + if ($duration < 86400) { + return $f->diff($s)->format('%h' . $hours . ', %i' . $minutes); + } + + return $f->diff($s)->format('%a' . $days . ', %h' . $hours . ', %i' . $minutes); + } + + $seconds = $this->get('seconds', $words, 'seconds'); + $minutes = $this->get('minutes', $words, 'minutes'); + $hours = $this->get('hours', $words, 'hours'); + $days = $this->get('days', $words, 'days'); + if ($duration < 60) { + return $f->diff($s)->format('%s ' . $seconds); + } + + if ($duration < 3600) { + return $f->diff($s)->format('%i ' . $minutes . ' and %s ' . $seconds); + } + + if ($duration < 86400) { + return $f->diff($s)->format('%h ' . $hours . ', %i ' . $minutes . ' and %s ' . $seconds); + } + + return $f->diff($s)->format( + '%a ' . $days . + ', %h ' . $hours . + ', %i ' . $minutes . + ' and %s ' . $seconds + ); + } +} diff --git a/lib/UnifiedSearch/UnifiedSearchProvider.php b/lib/UnifiedSearch/UnifiedSearchProvider.php index dc5ec91c3..a8df02cf9 100644 --- a/lib/UnifiedSearch/UnifiedSearchProvider.php +++ b/lib/UnifiedSearch/UnifiedSearchProvider.php @@ -31,7 +31,7 @@ namespace OCA\Circles\UnifiedSearch; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; +use OCA\Circles\Tools\Traits\TNCLogger; use Exception; use OCA\Circles\AppInfo\Application; use OCA\Circles\Model\Circle; @@ -51,7 +51,7 @@ * @package OCA\Circles\UnifiedSearch */ class UnifiedSearchProvider implements IProvider { - use TNC22Logger; + use TNCLogger; public const ORDER = 9; diff --git a/tests/unit/lib/Controller/AdminControllerTest.php b/tests/unit/lib/Controller/AdminControllerTest.php index 9274846e2..5564ad790 100644 --- a/tests/unit/lib/Controller/AdminControllerTest.php +++ b/tests/unit/lib/Controller/AdminControllerTest.php @@ -23,7 +23,6 @@ namespace OCA\Circles\Tests\Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; use OCA\Circles\AppInfo\Application; use OCA\Circles\Controller\AdminController; use OCA\Circles\Model\Circle; @@ -35,6 +34,7 @@ use OCA\Circles\Service\MemberService; use OCA\Circles\Service\MembershipService; use OCA\Circles\Service\SearchService; +use OCA\Circles\Tools\Traits\TDeserialize; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; use OCP\IRequest; @@ -47,7 +47,7 @@ * @group DB */ class AdminControllerTest extends TestCase { - use TNC22Deserialize; + use TDeserialize; /** @var IRequest|MockObject */ private $request; diff --git a/tests/unit/lib/Controller/LocalControllerTest.php b/tests/unit/lib/Controller/LocalControllerTest.php index 9d42f0cd8..80b36343a 100644 --- a/tests/unit/lib/Controller/LocalControllerTest.php +++ b/tests/unit/lib/Controller/LocalControllerTest.php @@ -23,7 +23,6 @@ namespace OCA\Circles\Tests\Controller; -use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize; use OCA\Circles\AppInfo\Application; use OCA\Circles\Controller\LocalController; use OCA\Circles\Model\Circle; @@ -35,6 +34,7 @@ use OCA\Circles\Service\MemberService; use OCA\Circles\Service\MembershipService; use OCA\Circles\Service\SearchService; +use OCA\Circles\Tools\Traits\TDeserialize; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; use OCP\IRequest; @@ -46,7 +46,7 @@ * @group DB */ class LocalControllerTest extends TestCase { - use TNC22Deserialize; + use TDeserialize; /** @var IRequest|MockObject */ private $request; @@ -100,10 +100,10 @@ public function setUp(): void { public function testCirclesList(int $limit, int $offset): void { $probe = new CircleProbe(); $probe->filterHiddenCircles() - ->filterBackendCircles() - ->addDetail(BasicProbe::DETAILS_POPULATION) - ->setItemsOffset($offset) - ->setItemsLimit($limit); + ->filterBackendCircles() + ->addDetail(BasicProbe::DETAILS_POPULATION) + ->setItemsOffset($offset) + ->setItemsLimit($limit); $circle1 = new Circle(); $circle1->setName('Circle One'); $circle2 = new Circle();