Skip to content

Commit 06bb455

Browse files
committed
add getVersion, getAttachedObject, getRightsTasks methods and tests; run tests and linters
1 parent 0556243 commit 06bb455

File tree

11 files changed

+477
-1
lines changed

11 files changed

+477
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ test-integration-scope-sale:
196196
test-integration-scope-disk:
197197
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_disk
198198

199+
.PHONY: test-integration-disk-service
200+
test-integration-disk-service:
201+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_disk_service
202+
199203
.PHONY: test-integration-disk-file
200204
test-integration-disk-file:
201205
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_disk_file

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
<testsuite name="integration_tests_scope_disk">
128128
<directory>./tests/Integration/Services/Disk/</directory>
129129
</testsuite>
130+
<testsuite name="integration_tests_disk_service">
131+
<directory>./tests/Integration/Services/Disk/Service/</directory>
132+
</testsuite>
130133
<testsuite name="integration_tests_disk_file">
131134
<directory>./tests/Integration/Services/Disk/File/</directory>
132135
</testsuite>

src/Services/Disk/DiskServiceBuilder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,19 @@ public function storage(): Storage\Service\Storage
6969

7070
return $this->serviceCache[__METHOD__];
7171
}
72+
73+
/**
74+
* Get Disk service
75+
*/
76+
public function disk(): Service\Disk
77+
{
78+
if (!isset($this->serviceCache[__METHOD__])) {
79+
$this->serviceCache[__METHOD__] = new Service\Disk(
80+
$this->core,
81+
$this->log
82+
);
83+
}
84+
85+
return $this->serviceCache[__METHOD__];
86+
}
7287
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Disk\Result;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* Class AttachedObjectItemResult
20+
*
21+
* @property-read int $ID // Attachment binding identifier
22+
* @property-read int $OBJECT_ID // File identifier from Drive
23+
* @property-read string $MODULE_ID // Module that owns the user property
24+
* @property-read string $ENTITY_TYPE // Entity type
25+
* @property-read int $ENTITY_ID // Identifier of the entity to which the attachment is made
26+
* @property-read string $CREATE_TIME // Creation time in ISO format
27+
* @property-read int $CREATED_BY // Identifier of the user who created the binding
28+
* @property-read string $DOWNLOAD_URL // Download URL for the file
29+
* @property-read string $NAME // File name
30+
* @property-read int $SIZE // File size in bytes
31+
*/
32+
class AttachedObjectItemResult extends AbstractItem
33+
{
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Disk\Result;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* Class RightItemResult
20+
*
21+
* @property-read int $ID // Identifier of the access level
22+
* @property-read string $NAME // Symbolic code
23+
* @property-read string $TITLE // Title
24+
*/
25+
class RightItemResult extends AbstractItem
26+
{
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Disk\Result;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractResult;
17+
18+
/**
19+
* Class RightsResult
20+
*/
21+
class RightsResult extends AbstractResult
22+
{
23+
/**
24+
* Get array of access rights
25+
*
26+
* @return RightItemResult[]
27+
*/
28+
public function getRights(): array
29+
{
30+
$items = [];
31+
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) {
32+
$items[] = new RightItemResult($item);
33+
}
34+
35+
return $items;
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Disk\Result;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* Class VersionItemResult
20+
*
21+
* @property-read int $ID // Version identifier
22+
* @property-read int $CREATED_BY // Identifier of the user who created the version
23+
* @property-read string $CREATE_TIME // Creation time in ISO format
24+
* @property-read string $DOWNLOAD_URL // Link to download the content
25+
* @property-read int $GLOBAL_CONTENT_VERSION // Incremental version counter relative to the file
26+
* @property-read string $NAME // File name at the time of version creation
27+
* @property-read int $OBJECT_ID // Identifier of the file to which the version belongs
28+
* @property-read int $SIZE // Size of the version in bytes
29+
*/
30+
class VersionItemResult extends AbstractItem
31+
{
32+
}

src/Services/Disk/Service/Disk.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Disk\Service;
15+
16+
use Bitrix24\SDK\Attributes\ApiEndpointMetadata;
17+
use Bitrix24\SDK\Attributes\ApiServiceMetadata;
18+
use Bitrix24\SDK\Core\Contracts\CoreInterface;
19+
use Bitrix24\SDK\Core\Credentials\Scope;
20+
use Bitrix24\SDK\Core\Exceptions\BaseException;
21+
use Bitrix24\SDK\Core\Exceptions\TransportException;
22+
use Bitrix24\SDK\Services\AbstractService;
23+
use Bitrix24\SDK\Services\Disk\Result\VersionItemResult;
24+
use Bitrix24\SDK\Services\Disk\Result\AttachedObjectItemResult;
25+
use Bitrix24\SDK\Services\Disk\Result\RightsResult;
26+
use Psr\Log\LoggerInterface;
27+
28+
#[ApiServiceMetadata(new Scope(['disk']))]
29+
class Disk extends AbstractService
30+
{
31+
public function __construct(CoreInterface $core, LoggerInterface $logger)
32+
{
33+
parent::__construct($core, $logger);
34+
}
35+
36+
/**
37+
* Returns the version by identifier.
38+
*
39+
* @link https://apidocs.bitrix24.com/api-reference/disk/version/disk-version-get.html
40+
*
41+
* @param int $id Version identifier
42+
*
43+
* @throws BaseException
44+
* @throws TransportException
45+
*/
46+
#[ApiEndpointMetadata(
47+
'disk.version.get',
48+
'https://apidocs.bitrix24.com/api-reference/disk/version/disk-version-get.html',
49+
'Returns the version by identifier.'
50+
)]
51+
public function getVersion(int $id): VersionItemResult
52+
{
53+
return new VersionItemResult(
54+
$this->core->call(
55+
'disk.version.get',
56+
['id' => $id]
57+
)->getResponseData()->getResult()
58+
);
59+
}
60+
61+
/**
62+
* Returns information about the attached file.
63+
*
64+
* @link https://apidocs.bitrix24.com/api-reference/disk/attached-object/disk-attached-object-get.html
65+
*
66+
* @param int $id Attachment binding identifier
67+
*
68+
* @throws BaseException
69+
* @throws TransportException
70+
*/
71+
#[ApiEndpointMetadata(
72+
'disk.attachedObject.get',
73+
'https://apidocs.bitrix24.com/api-reference/disk/attached-object/disk-attached-object-get.html',
74+
'Returns information about the attached file.'
75+
)]
76+
public function getAttachedObject(int $id): AttachedObjectItemResult
77+
{
78+
return new AttachedObjectItemResult(
79+
$this->core->call(
80+
'disk.attachedObject.get',
81+
['id' => $id]
82+
)->getResponseData()->getResult()
83+
);
84+
}
85+
86+
/**
87+
* Returns a list of available access levels that can be used for assigning permissions.
88+
*
89+
* @link https://apidocs.bitrix24.com/api-reference/disk/rights/disk-rights-get-tasks.html
90+
*
91+
* @param int|null $start The ordinal number of the list item from which to return the next items
92+
*
93+
* @throws BaseException
94+
* @throws TransportException
95+
*/
96+
#[ApiEndpointMetadata(
97+
'disk.rights.getTasks',
98+
'https://apidocs.bitrix24.com/api-reference/disk/rights/disk-rights-get-tasks.html',
99+
'Returns a list of available access levels that can be used for assigning permissions.'
100+
)]
101+
public function getRightsTasks(?int $start = null): RightsResult
102+
{
103+
$params = [];
104+
if ($start !== null) {
105+
$params['start'] = $start;
106+
}
107+
108+
return new RightsResult(
109+
$this->core->call(
110+
'disk.rights.getTasks',
111+
$params
112+
)
113+
);
114+
}
115+
}

src/Services/Disk/Storage/Result/GetChildrenResult.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ public function items(): array
3535
if (!is_array($itemData)) {
3636
continue;
3737
}
38+
3839
if (!isset($itemData['TYPE'])) {
3940
continue;
4041
}
42+
4143
if ($itemData['TYPE'] === 'file') {
4244
$items[] = new FileItemResult($itemData);
4345
} elseif ($itemData['TYPE'] === 'folder') {

0 commit comments

Comments
 (0)