|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * (c) Packagist Conductors GmbH <[email protected]> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PrivatePackagist\ApiClient\Api\Suborganizations; |
| 11 | + |
| 12 | +use PrivatePackagist\ApiClient\Api\AbstractApi; |
| 13 | +use PrivatePackagist\ApiClient\Exception\InvalidArgumentException; |
| 14 | +use PrivatePackagist\ApiClient\Payload\CustomPackageConfig; |
| 15 | +use PrivatePackagist\ApiClient\Payload\VcsPackageConfig; |
| 16 | + |
| 17 | +class Packages extends AbstractApi |
| 18 | +{ |
| 19 | + public function all($suborganizationName, array $filters = []) |
| 20 | + { |
| 21 | + if (isset($filters['origin']) && !in_array($filters['origin'], \PrivatePackagist\ApiClient\Api\Packages::AVAILABLE_ORIGINS, true)) { |
| 22 | + throw new InvalidArgumentException('Filter "origin" has to be one of: "' . implode('", "', \PrivatePackagist\ApiClient\Api\Packages::AVAILABLE_ORIGINS) . '".'); |
| 23 | + } |
| 24 | + |
| 25 | + return $this->get(sprintf('/suborganizations/%s/packages/', $suborganizationName), $filters); |
| 26 | + } |
| 27 | + |
| 28 | + public function show($suborganizationName, $packageIdOrName) |
| 29 | + { |
| 30 | + return $this->get(sprintf('/suborganizations/%s/packages/%s', $suborganizationName, $packageIdOrName)); |
| 31 | + } |
| 32 | + |
| 33 | + public function createVcsPackage($suborganizationName, $url, $credentialId = null, $type = 'vcs', $defaultSuborganizationAccess = null) |
| 34 | + { |
| 35 | + $data = new VcsPackageConfig($url, $credentialId, $type, $defaultSuborganizationAccess); |
| 36 | + |
| 37 | + return $this->post(sprintf('/suborganizations/%s/packages/', $suborganizationName), $data->toParameters()); |
| 38 | + } |
| 39 | + |
| 40 | + public function createCustomPackage($suborganizationName, $customJson, $credentialId = null, $defaultSuborganizationAccess = null) |
| 41 | + { |
| 42 | + $data = new CustomPackageConfig($customJson, $credentialId, $defaultSuborganizationAccess); |
| 43 | + |
| 44 | + return $this->post(sprintf('/suborganizations/%s/packages/', $suborganizationName), $data->toParameters()); |
| 45 | + } |
| 46 | + |
| 47 | + public function editVcsPackage($suborganizationName, $packageIdOrName, $url, $credentialId = null, $type = 'vcs', $defaultSuborganizationAccess = null) |
| 48 | + { |
| 49 | + $data = new VcsPackageConfig($url, $credentialId, $type, $defaultSuborganizationAccess); |
| 50 | + |
| 51 | + return $this->put(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName), $data->toParameters()); |
| 52 | + } |
| 53 | + |
| 54 | + public function editCustomPackage($suborganizationName, $packageIdOrName, $customJson, $credentialId = null, $defaultSuborganizationAccess = null) |
| 55 | + { |
| 56 | + $data = new CustomPackageConfig($customJson, $credentialId, $defaultSuborganizationAccess); |
| 57 | + |
| 58 | + return $this->put(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName), $data->toParameters()); |
| 59 | + } |
| 60 | + |
| 61 | + public function remove($suborganizationName, $packageIdOrName) |
| 62 | + { |
| 63 | + return $this->delete(sprintf('/suborganizations/%s/packages/%s/', $suborganizationName, $packageIdOrName)); |
| 64 | + } |
| 65 | + |
| 66 | + public function listDependents($suborganizationName, $packageIdOrName) |
| 67 | + { |
| 68 | + return $this->get(sprintf('/suborganizations/%s/packages/%s/dependents/', $suborganizationName, $packageIdOrName)); |
| 69 | + } |
| 70 | +} |
0 commit comments