Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Dec 26, 2023
0 parents commit 74f1b5a
Show file tree
Hide file tree
Showing 34 changed files with 964 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true

[*.{yml,xml}]
indent_size = 2
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text=auto

*.lock -diff
*.min.js -diff
*.min.css -diff

/.github export-ignore
CHANGELOG.md export-ignore
36 changes: 36 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: phpstan

on: [ push, pull_request ]

jobs:
analyze:
runs-on: ubuntu-latest

name: PHPStan

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: phpstan

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: phpstan-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: phpstan-composer-

- name: Install dependencies
run: composer install --no-interaction --no-suggest

- name: Run analysis
run: phpstan analyse
22 changes: 22 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: pint

on: [ push, pull_request ]

jobs:
analyze:
runs-on: ubuntu-latest

name: Laravel Pint

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: laravel/pint

- name: Run analysis
run: pint
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish

on:
push:
tags:
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get release info
id: query-release-info
uses: release-flow/keep-a-changelog-action@v2
with:
command: query
version: latest

- name: Publish to Github releases
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.query-release-info.outputs.release-notes }}
# prerelease: true
# files: '*.vsix'
64 changes: 64 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.1, 8.2, 8.3 ]
laravel: [ 9.*, 10.* ]
dependency-version: [ prefer-stable ]
include:
- laravel: 9.*
testbench: 7.*

- laravel: 10.*
testbench: 8.*
exclude:
- laravel: 10.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, exif
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.dependency-version }}-

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit -c phpunit.coverage.dist.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./clover.xml
fail_ci_if_error: true
verbose: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/vendor/
/node_modules
composer.lock
phpunit.xml
.DS_Store
coverage
clover.xml
.phpunit.cache
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"open-southeners.vscode-php-extension-pack"
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Open Southeners

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Carbone PHP [![required php version](https://img.shields.io/packagist/php-v/open-southeners/carbone-sdk)](https://www.php.net/supported-versions.php) [![codecov](https://codecov.io/gh/open-southeners/carbone-sdk/branch/main/graph/badge.svg?token=codecov_badge_token)](https://codecov.io/gh/open-southeners/carbone-sdk) [![Edit on VSCode online](https://img.shields.io/badge/vscode-edit%20online-blue?logo=visualstudiocode)](https://vscode.dev/github/open-southeners/carbone-sdk)
===

Unofficial port of the Carbone API SDK to Saloon v3

## Getting started

```
composer require open-southeners/carbone-sdk
```

### Laravel installation

To make this work within a Laravel app you just need to add the following at the very bottom of your `.env` file:

```ini
CARBONE_API_KEY='your-carbone-api-key'
```

### Usage

Within Laravel you've it injected into your application's container:

```php
$response = app('carbone')->template()->base64Upload($templateBase64);

if ($response->failed()) {
throw new \Exception('Template upload failed!');
}

// This is extracted from official Carbone SDK: https://carbone.io/api-reference.html#upload-a-template-carbone-cloud-sdk-php
$templateId = $response->getTemplateId();
```

### Any other framework (or not)

If you are using another framework (or just pure PHP), you can still use this as a standalone library:

```php
$carbone = new Carbone('your-carbone-api-key');

// Use this if you want to use a different API version: https://carbone.io/api-reference.html#api-version
// $carbone = new Carbone('your-carbone-api-key', '4');

$templateBase64 = base64_encode(file_get_contents('path_to_your_template_here'));

$response = $carbone->template()->base64Upload($templateBase64);

if ($response->failed()) {
throw new \Exception('Template upload failed!');
}

// This is extracted from official Carbone SDK: https://carbone.io/api-reference.html#upload-a-template-carbone-cloud-sdk-php
$templateId = $response->getTemplateId();
```

### Differences between official SDK and this

- Use of [Saloon v3](https://github.com/saloonphp/saloon/releases/tag/v3.0.0) not the v1 (which improves at everything typed for better IDE autocompletion support, etc)
- **Replaced the `template()->upload()` method with `template()->base64Upload()`** so the upload method can be used to send `multipart/form-data` POST request instead of a `application/json` with all the file contents base64 encoded
- Added `template()->exists()` to get if template with ID exists in Carbone (just a HEAD request so no content fetch at all)
- Added `status()->fetch()` to get status (not currently publicly documented, only on the OpenAPI, Postman, etc. [Can check them here](https://carbone.io/api-reference.html#api-integration))

[You can still check the official one here](https://github.com/carboneio/carbone-sdk-php).

## Partners

[![skore logo](https://github.com/open-southeners/partners/raw/main/logos/skore_logo.png)](https://getskore.com)

## License

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
15 changes: 15 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Security Policy

## Supported Versions

We're also following the [Laravel's default support policy](https://laravel.com/docs/master/releases#support-policy) on our semantic versioning.

| Version | Supported |
| ------- | ------------------ |
| 1.x | :white_check_mark: |
<!-- | 2.x | :white_check_mark: | -->
<!-- | < 1.0 | :x: | -->

## Reporting a Vulnerability

Send us an email at [email protected]
61 changes: 61 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "open-southeners/carbone-sdk",
"description": "Unofficial port of the Carbone API SDK to Saloon v3",
"license": "MIT",
"keywords": [
"open-southeners",
"carbone",
"carbone-sdk",
"carbone-client",
"carbone-api",
"word",
"excel",
"office",
"pdf",
"generator"
],
"authors": [
{
"name": "Ruben Robles",
"email": "[email protected]",
"homepage": "https://d8vjork.com"
}
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/open-southeners"
}
],
"require": {
"php": "^8.0",
"saloonphp/saloon": "^3.0"
},
"require-dev": {
"larastan/larastan": "^2.0",
"orchestra/testbench": "^7.0 || ^8.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.0 || ^10.0"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"OpenSoutheners\\CarboneSdk\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"OpenSoutheners\\CarboneSdk\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"OpenSoutheners\\CarboneSdk\\ServiceProvider"
]
}
}
}
8 changes: 8 additions & 0 deletions dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# includes:
# - ./vendor/larastan/larastan/extension.neon

parameters:

paths:
- src

level: "max"

checkMissingIterableValueType: false
Loading

0 comments on commit 74f1b5a

Please sign in to comment.