diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..63d0972 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,38 @@ +name: PHP tests +on: [push, pull_request] +jobs: + # Check there is no syntax errors in the project + php-linter: + name: PHP Syntax check 8.1 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: PHP syntax checker 8.1 + uses: prestashop/github-action-php-lint/8.1@master + + # Check the PHP code follow the coding standards + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + - name: Install dependencies + run: composer install + + - name: Run PHP-CS-Fixer + run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..5b524f8 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,9 @@ +setUsingCache(true)->getFinder(); +$finder->in(__DIR__)->exclude('vendor'); + +return $config; diff --git a/src/ApiPlatform/Resources/ApiAccess.php b/src/ApiPlatform/Resources/ApiAccess.php new file mode 100644 index 0000000..9525a19 --- /dev/null +++ b/src/ApiPlatform/Resources/ApiAccess.php @@ -0,0 +1,84 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources; + +use ApiPlatform\Core\Annotation\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Exception\ApiAccessNotFoundException; +use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Query\GetApiAccessForEditing; +use PrestaShopBundle\ApiPlatform\Provider\QueryProvider; + +#[ApiResource( + operations: [ + new Get( + uriTemplate: '/api-access/{apiAccessId}', + requirements: ['apiAccessId' => '\d+'], + openapiContext: [ + 'summary' => 'Get API Access details', + 'description' => 'Get API Access public details only, sensitive informations like secrets are not returned', + 'parameters' => [ + [ + 'name' => 'id', + 'in' => 'path', + 'required' => true, + 'schema' => [ + 'type' => 'string', + ], + 'description' => 'Id of the API Access you are requesting the details from', + ], + [ + 'name' => 'Authorization', + 'in' => 'scopes', + 'description' => 'api_access_read', + ], + ], + ], + exceptionToStatus: [ApiAccessNotFoundException::class => 404], + provider: QueryProvider::class, + extraProperties: [ + 'query' => GetApiAccessForEditing::class, + 'scopes' => ['api_access_read'], + ] + ), + ], +)] +class ApiAccess +{ + #[ApiProperty(identifier: true)] + public int $apiAccessId; + + public string $clientName; + + public string $clientId; + + public string $description; + + public bool $enabled; +}