Lightweight and minimalistic PHP library providing a set of foundational tools for development.
Designed to be practical, extendable, and easy to integrate into projects, offering a flexible base for building more complex functionality.
composer require sevaske/support- Store attributes dynamically with magic methods:
__get,__set,__isset,__unset. - Supports array-style access via
ArrayAccess. - Utility methods:
fill(array $attributes)— bulk set attributes.has(string $key)— check if an attribute exists.keys()— list all attribute keys.replicate()— clone object with same attributes.toArray(),jsonSerialize()— export attributes.
Example:
use Sevaske\Support\Traits\HasAttributes;
class User {
use HasAttributes;
}
$user = new User();
$user->fill(['name' => 'John', 'age' => 30]);
$user->age = 31;
$user->age; // 31
$user['age']; // 31
unset($user->name);
$copy = $user->replicate();- Implements a contract to define read-only behavior.
readOnlyAttributescan betrue(all) or an array of keys.- Modifying locked attributes throws
LogicException.
Example:
class User implements HasReadOnlyAttributesContract {
use HasAttributes;
public function getReadOnlyAttributes(): bool|array
{
return ['age'];
}
}
$user = new User();
$user->fill(['name' => 'John', 'age' => 30]);
$user->name = 'Alice'; // allowed
$user->age = 32; // throws LogicException- Attach metadata to exceptions.
- Fluent
withContext()method andcontext()retrieval.
Example:
use Sevaske\Support\Exceptions\ContextableException;
$ex = new ContextableException('Error', ['user_id' => 123]);
$ex->withContext(['ip' => '127.0.0.1']);
print_r($ex->context());Contributions are welcome! Feel free to open issues or submit pull requests.
Please follow PSR-12 coding standards and include tests for any new features or fixes.
This project is licensed under the MIT License. See the LICENSE file for details.