# UserFrosting Patches

This directory contains patches for vendor files to fix compatibility issues with newer PHP versions.

## Current Patches

### SlimFlashPatch

Fixes PHP 8.1+ deprecation warnings in Slim\Middleware\Flash by adding the `#[\ReturnTypeWillChange]` attribute to methods that implement the `ArrayAccess`, `IteratorAggregate`, and `Countable` interfaces.

The following methods are patched:
- `offsetExists($offset)`
- `offsetGet($offset)`
- `offsetSet($offset, $value)`
- `offsetUnset($offset)`
- `getIterator()`
- `count()`

### TwigNodePatch

Fixes PHP 8.4+ deprecation warnings in Twig\Node\Node by adding the `#[\ReturnTypeWillChange]` attribute to methods that implement the `Countable` and `IteratorAggregate` interfaces.

The following methods are patched:
- `count()`
- `getIterator()`

### SlimResponsePatch

Fixes PHP 8.4+ deprecation warnings in Slim\Http\Response by adding the `#[\ReturnTypeWillChange]` attribute to methods that implement the `ArrayAccess`, `IteratorAggregate`, and `Countable` interfaces.

The following methods are patched:
- `offsetExists($offset)`
- `offsetGet($offset)`
- `offsetSet($offset, $value)`
- `offsetUnset($offset)`
- `getIterator()`
- `count()`

### FortressDataSanitizerPatch

Fixes PHP 8.1+ deprecation warnings in Fortress\DataSanitizer by replacing the deprecated `FILTER_SANITIZE_STRING` constant with `FILTER_SANITIZE_ADD_SLASHES` and fixing a PHP 7.3+ warning about `continue` in switch statements.

The following changes are made:
- All instances of `FILTER_SANITIZE_STRING` are replaced with `FILTER_SANITIZE_ADD_SLASHES`
- Fixed `continue` in switch statement to `continue 2` to properly target the foreach loop

## How to Apply Patches

Patches are automatically applied during application initialization in `initialize.php`.

You can also manually apply all patches by running:

```
php apply-patches.php
```

## Troubleshooting

### Duplicate Attributes Error

If you encounter a fatal error about duplicate `ReturnTypeWillChange` attributes, you can fix it by running:

```
php patches/fix-flash-attributes.php
```

This script will remove all existing attributes and then add them back correctly, ensuring there are no duplicates. 