PHPackages                             din9xtr/source-context - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. din9xtr/source-context

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

din9xtr/source-context
======================

Package for managing source context and proxy pattern implementation for PHP classes with enum support

v1.0.2(2mo ago)10MITPHPPHP ^8.3

Since Feb 28Pushed 2mo agoCompare

[ Source](https://github.com/din9xtr/source-context)[ Packagist](https://packagist.org/packages/din9xtr/source-context)[ Docs](https://github.com/din9xtr/source-context)[ RSS](/packages/din9xtr-source-context/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Source Context Validation Library
=================================

[](#source-context-validation-library)

A library for validating access to methods based on the source context (API, Web, CLI, etc.) using attributes and dynamic proxies

---

Features
--------

[](#features)

- **Source Validation** — Restrict access to methods by source type
- **Dynamic Proxies** — Automatic generation of proxy classes
- **Attributes** — Simple declarative configuration via PHP attributes
- **Laravel Integration** — Ready-to-use Laravel integration
- **Multiple Contexts** — Support for various context implementations

---

📦 Installation
--------------

[](#-installation)

```
composer require din9xtr/source-context
```

---

🎯 Quick Start
-------------

[](#-quick-start)

### 1. Add an attribute to the class

[](#1-add-an-attribute-to-the-class)

```
#[AutoValidateSources]
class UserService implements SomeInterface // it's important
{
    // ...
}
```

### 2. Protect methods with the AllowedSources attribute

[](#2-protect-methods-with-the-allowedsources-attribute)

```
class UserService implements SomeInterface // it's important
{
    #[AllowedSources([Source::API, Source::WEB])]
    public function createUser(array $data): User
    {
    }

    #[AllowedSources([Source::CLI, Source::CRON])]
    public function listUsers(): void
    {
    }
}
```

### 3. Set the source context

[](#3-set-the-source-context)

```
