Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dlundgren committed Mar 18, 2024
0 parents commit 8240ff7
Show file tree
Hide file tree
Showing 16 changed files with 444 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 @@
root = true

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

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml,json}]
indent_size = 2
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/phpcs.xml export-ignore
/tests export-ignore
/.editorconfig export-ignore
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: tests

on:
push:
pull_request:

jobs:
test:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.2, 8.1, 8.0]
laravel: ["^10.0", "^9.0"]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: "^10.0"
php: 8.0
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2

- name: Execute tests
run: composer test
28 changes: 28 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: master

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4.15.4
with:
branch: master
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
.idea
composer.lock
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to `syberisle/laravel-castable-archive` will be documented in this file

## 0.0.0 - 2024-03-17

Initial Release
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/syberisle/laravel-castable-archive).

## Pull Requests

- **[SyberIsle Coding Standard](https://github.com/SyberIsle/coding-standards)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/).

- **Create feature branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 SyberIsle, LLC.

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.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Laravel Model attribute to de/compress the value

[![Latest Version on Packagist](https://img.shields.io/packagist/v/syberisle/laravel-castable-archive.svg?style=flat-square)](https://packagist.org/packages/syberisle/laravel-castable-archive)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/syberisle/laravel-castable-archive/run-tests.yml?branch=main&label=Tests)](https://github.com/syberisle/laravel-castable-archive/actions/workflows/tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/syberisle/laravel-castable-archive.svg?style=flat-square)](https://packagist.org/packages/syberisle/laravel-castable-archive)

This package allows you to cast a model attribute as a compressed value using either gzip or bzip.

Available Casts:
- `SyberIsle\Laravel\Cast\Archive\BzArchive`
- `SyberIsle\Laravel\Cast\Archive\GzArchive`

## Installation

```shell
composer install syberisle/laravel-castable-archive
```

## Usage

```php
use SyberIsle\Laravel\Cast\Archive;

class MyModel
{
protected $casts = [
'field_name' => Archive\GzArchive::class
];
}

$model->field_name = 'kakaw' // raw attribute = b"ËNÌN,\x07\x00"
$value = $model->field_name; // = 'kakaw'
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security

If you've found a bug regarding security please report it via the security tab of this repository.

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
53 changes: 53 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "syberisle/laravel-castable-archive",
"description": "Tool for casting a model field as bzip or gzip",
"license": "MIT",
"keywords": [
"laravel",
"model cast",
"gzip",
"bzip"
],
"authors": [
{
"name": "David Lundgren",
"email": "dlundgren@syberisle.com",
"role": "Developer"
}
],
"homepage": "https://github.com/syberisle/laravel-castable-archive",
"require": {
"php": "^8.0",
"ext-bz2": "*",
"ext-zlib": "*",
"illuminate/contracts": "^9.28 || ^10.0 || ^11.0"
},
"require-dev": {
"nunomaduro/collision": "^6.2",
"orchestra/testbench": "^7.7 || ^8.0",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5.24",
"squizlabs/php_codesniffer": "^3.9",
"syberisle/coding-standards": "^2.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"SyberIsle\\Laravel\\Cast\\Archive\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"SyberIsle\\Laravel\\Cast\\Archive\\Test\\": "tests"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"sniff": "@php vendor/bin/phpcs",
"stan": "vendor/bin/phpstan analyse --level 6 src",
"test": "vendor/bin/testbench package:test"
}
}
15 changes: 15 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>Coding standard for this project</description>

<config name="installed_paths" value="vendor/syberisle/coding-standards" />

<file>src</file>
<file>tests</file>

<rule ref="SyberIsle" />

<arg name="colors" />
<arg value="p" />
<arg name="extensions" value="php"/>
</ruleset>
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
stopOnFailure="true"
cacheResult="false"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
41 changes: 41 additions & 0 deletions src/BzArchive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace SyberIsle\Laravel\Cast\Archive;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

/**
* Uses the bzip functions to compress & decompress the data
*
* @implements CastsAttributes<mixed, mixed>
*/
class BzArchive
implements CastsAttributes
{
/**
* @param Model $model
* @param string $key
* @param mixed $value
* @param mixed[] $attributes
*
* @return false|string|null
*/
public function get($model, string $key, $value, array $attributes): mixed
{
return bzdecompress($value);
}

/**
* @param Model $model
* @param string $key
* @param mixed $value
* @param mixed[] $attributes
*
* @return false|string|null
*/
public function set($model, string $key, $value, array $attributes)
{
return bzcompress($value);
}
}
41 changes: 41 additions & 0 deletions src/GzArchive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace SyberIsle\Laravel\Cast\Archive;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

/**
* Uses the gzip deflate functions to compress & decompress the data
*
* @implements CastsAttributes<mixed, mixed>
*/
class GzArchive
implements CastsAttributes
{
/**
* @param Model $model
* @param string $key
* @param mixed $value
* @param mixed[] $attributes
*
* @return false|string|null
*/
public function get($model, string $key, $value, array $attributes): mixed
{
return gzinflate($value);
}

/**
* @param Model $model
* @param string $key
* @param mixed $value
* @param mixed[] $attributes
*
* @return false|string|null
*/
public function set($model, string $key, $value, array $attributes): mixed
{
return gzdeflate($value);
}
}
Loading

0 comments on commit 8240ff7

Please sign in to comment.