Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Base image is from Microsoft
FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04

# Avoid interactive prompts (e.g. tzdata) during installation
ENV DEBIAN_FRONTEND=noninteractive

RUN mkdir -p /var/www/html

# Install 8.3 from Ondrej's PPA
RUN apt-get update && apt-get install -y \
software-properties-common \
&& add-apt-repository ppa:ondrej/php -y \
&& apt-get update && apt-get install -y sqlite3 \
&& apt-get install -y php8.4-cli php8.4-dev \
php8.4-pgsql php8.4-sqlite3 php8.4-gd \
php8.4-curl \
php8.4-imap php8.4-mysql php8.4-mbstring \
php8.4-xml php8.4-zip php8.4-bcmath php8.4-soap \
php8.4-intl php8.4-readline \
php8.4-ldap \
php8.4-msgpack php8.4-igbinary php8.4-redis php8.4-swoole \
php8.4-memcached php8.4-pcov php8.4-imagick php8.4-xdebug \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
&& composer --version
46 changes: 46 additions & 0 deletions .devcontainer/devcontainer.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
alias art='php artisan --ansi'
alias tinker='art tinker'
alias format='php vendor/bin/pint'
alias analyze='php vendor/bin/phpstan analyse'
alias test='php vendor/bin/paratest --coverage-html coverage'
alias stf='php vendor/bin/phpunit --filter'

# commit AI
function commit() {
commitMessage="$*"

git add .

if [ "$commitMessage" = "" ]; then
aicommits
return
fi

eval "git commit -a -m '${commitMessage}'"
}

# function gfind
function gfind() {
local excludeVendor="--exclude-dir=vendor" # Default to excluding the vendor directory
local searchString=""
local searchPath="./"

# Process all arguments
for arg in "$@"; do
if [[ "$arg" == "-w" || "$arg" == "--with-vendor" ]]; then
excludeVendor="" # Remove the exclude directive to include vendor
elif [[ -z "$searchString" && "$arg" != -* ]]; then
searchString="$arg" # Set the search string if it's not a flag and is the first non-flag argument
fi
done

# Check if a search string was provided
if [[ -z "$searchString" ]]; then
echo -e "${RED}Error: Missing required search string.${NC}"
echo -e "${YELLOW}Usage: ${NC}gfind searchString [-w|--with-vendor]"
return 1
fi

# Execute grep command
grep --include=\*.php $excludeVendor -rnw $searchPath -e "$searchString"
}
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Sanitizer",
"build": {
"dockerfile": "Dockerfile",
"context": "."
},
"features": {},
"customizations": {
"vscode": {
"extensions": [
"bmewburn.vscode-intelephense-client",
"calebporzio.better-phpunit",
"laravel.vscode-laravel",
"mikestead.dotenv",
"ms-azuretools.vscode-docker",
"php.intelephense"
],
"settings": {
"intelephense.environment.phpVersion": "8.4"
}
}
},
"remoteUser": "vscode",
"postCreateCommand": "cat ./.devcontainer/devcontainer.bash >> /home/vscode/.bashrc",
"forwardPorts": [],
"portsAttributes": {}
}
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
33 changes: 33 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: dependabot-auto-merge
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
runs-on: ubuntu-latest
timeout-minutes: 5
if: ${{ github.actor == 'dependabot[bot]' }}
steps:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.5.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
File renamed without changes.
32 changes: 32 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Update Changelog"

on:
release:
types: [released]

permissions:
contents: write

jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: main

- 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@v7
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/vendor/
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1" />](https://supportukrainenow.org)

# Sanitizer

![https://github.com/binary-cats/sanitizer/actions](https://github.com/binary-cats/sanitizer/workflows/Laravel/badge.svg)
![https://github.styleci.io/repos/316763653](https://github.styleci.io/repos/316763653/shield)
![https://scrutinizer-ci.com/g/binary-cats/sanitizer/](https://scrutinizer-ci.com/g/binary-cats/sanitizer/badges/quality-score.png?b=master)
[![Build Status](https://img.shields.io/travis/binary-cats/sanitizer/master.svg?style=flat-square)](https://travis-ci.org/binary-cats/sanitizer)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/binary-cats/sanitizer.svg?style=flat-square)](https://packagist.org/packages/binary-cats/sanitizer)
[![Tests](https://img.shields.io/github/actions/workflow/status/binary-cats/sanitizer/run-tests.yml?branch=v13.x&label=tests&style=flat-square)](https://github.com/binary-cats/sanitizer/actions/workflows/run-tests.yml)
[![Code Style Action Status](https://github.styleci.io/repos/316763653/shield?branch=v13.x)](https://github.styleci.io/repos/316763653)

## Introduction

Expand Down
20 changes: 20 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# Upgrading

## Version Changes

### Dependencies
- **illuminate/support**: Updated to version `^12.0`
- **illuminate/validation**: Updated to version `^12.0`
- **nesbot/carbon**: Updated to version `^3.0`
- **phpunit/phpunit**: Updated to version `^11.0` for development.

### Minimum Stability
- The minimum stability is set to `dev`, which may allow for unstable packages to be installed. Ensure that you are aware of the implications of using development versions.

## Upgrade Steps
1. **Update Dependencies**: Run `composer update` to install the latest versions of the required packages.
2. **Check for Breaking Changes**: Review the changelogs for `illuminate/support`, `illuminate/validation`, and `nesbot/carbon` for any breaking changes that may affect your application.
3. **Test Your Application**: After updating, run your tests to ensure everything works as expected. Use the command `composer test` to execute your PHPUnit tests.
4. **Review Laravel Configuration**: Ensure that the service provider and facade alias are correctly registered in your Laravel application.

## Additional Notes
- If you encounter issues, consider checking the documentation for each package for guidance on resolving compatibility problems.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"email": "cyrill.kalita@gmail.com"
}],
"require": {
"illuminate/support": "^8.0|^9.0",
"illuminate/validation": "^8.0|^9.0",
"nesbot/carbon": "^2.0"
"illuminate/support": "^12.0|^13.0",
"illuminate/validation": "^12.0|^13.0",
"nesbot/carbon": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 8 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
<phpunit
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Sanitizer Test Suite">
<directory suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/Contracts/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ interface Filter
/**
* Return the result of applying this filter to the given input.
*
* @param mixed $value
* @return mixed
* @param mixed $value
* @return mixed
*/
public function apply($value, $options = []);
}
4 changes: 2 additions & 2 deletions src/Filters/Capitalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Capitalize implements Filter
/**
* Capitalize the given string.
*
* @param string $value
* @return string
* @param string $value
* @return string
*/
public function apply($value, $options = [])
{
Expand Down
39 changes: 13 additions & 26 deletions src/Filters/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,22 @@ class Cast implements Filter
/**
* Capitalize the given string.
*
* @param string $value
* @return string
* @param string $value
* @return string
*/
public function apply($value, $options = [])
{
$type = isset($options[0]) ? $options[0] : null;
switch ($type) {
case 'int':
case 'integer':
return (int) $value;
case 'real':
case 'float':
case 'double':
return (float) $value;
case 'string':
return (string) $value;
case 'bool':
case 'boolean':
return (bool) $value;
case 'object':
return is_array($value) ? (object) $value : json_decode($value, false);
case 'array':
return json_decode($value, true);
case 'collection':
$array = is_array($value) ? $value : json_decode($value, true);
$type = $options[0] ?? null;

return new Collection($array);
default:
throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}.");
}
return match ($type) {
'int', 'integer' => (int) $value,
'real', 'float', 'double' => (float) $value,
'string' => (string) $value,
'bool', 'boolean' => (bool) $value,
'object' => is_array($value) ? (object) $value : json_decode($value, false),
'array' => json_decode($value, true),
'collection' => new Collection(is_array($value) ? $value : json_decode($value, true)),
default => throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}."),
};
}
}
4 changes: 2 additions & 2 deletions src/Filters/Digit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Digit implements Filter
/**
* Get only digit characters from the string.
*
* @param string $value
* @return string
* @param string $value
* @return string
*/
public function apply($value, $options = [])
{
Expand Down
6 changes: 3 additions & 3 deletions src/Filters/EscapeHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class EscapeHTML implements Filter
/**
* Remove HTML tags and encode special characters from the given string.
*
* @param string $value
* @return string
* @param string $value
* @return string
*/
public function apply($value, $options = [])
{
return is_string($value) ? filter_var($value, FILTER_SANITIZE_STRING) : $value;
return is_string($value) ? htmlspecialchars(strip_tags($value), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') : $value;
}
}
6 changes: 3 additions & 3 deletions src/Filters/FilterIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class FilterIf implements Filter
/**
* Checks if filters should run if there is value passed that matches.
*
* @param array $values
* @param array $options
* @return bool
* @param array $values
* @param array $options
* @return bool
*/
public function apply($values, $options = [])
{
Expand Down
Loading
Loading