PHPackages                             php-architecture-kit/actor - 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. php-architecture-kit/actor

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

php-architecture-kit/actor
==========================

Actor abstraction for PHP applications - represents who performs actions in the system.

1.0.1(1mo ago)10[1 issues](https://github.com/php-architecture-kit/actor/issues)MITPHPPHP ^7.4 || ^8.0

Since Feb 12Pushed 1mo agoCompare

[ Source](https://github.com/php-architecture-kit/actor)[ Packagist](https://packagist.org/packages/php-architecture-kit/actor)[ Docs](https://github.com/php-architecture-kit/actor)[ RSS](/packages/php-architecture-kit-actor/feed)WikiDiscussions main Synced 1w ago

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

php-architecture-kit/actor
==========================

[](#php-architecture-kitactor)

Actor abstraction for PHP applications. Represents who performs actions in the system - users, system processes, or unknown sources.

Features
--------

[](#features)

- **Actor interface** - Simple contract with `identifier()` method
- **IdentifiedActor** - For actors with UUID-based identity (users, entities)
- **NamedActor** - For system processes (cron, workers, schedulers)
- **UnknownActor** - For anonymous or unidentified actors
- **ActorId** - UUID-based identity extending `php-architecture-kit/uuid`
- **PHP 7.4+** - Compatible with legacy and modern PHP

Installation
------------

[](#installation)

```
composer require php-architecture-kit/actor
```

Quick Start
-----------

[](#quick-start)

```
use PhpArchitecture\Actor\IdentifiedActor;
use PhpArchitecture\Actor\NamedActor;
use PhpArchitecture\Actor\UnknownActor;
use PhpArchitecture\Actor\Identity\ActorId;

// User actor (with UUID identity)
$userId = ActorId::fromString('df516cba-fb13-4f45-8335-00252f1b87e2');
$userActor = new IdentifiedActor($userId);
echo $userActor->identifier(); // 'df516cba-fb13-4f45-8335-00252f1b87e2'

// System actor (cron job, worker, etc.)
$NamedActor = new NamedActor('order-processor');
echo $NamedActor->identifier(); // 'order-processor'

// Unknown actor (anonymous, unidentified)
$unknownActor = new UnknownActor();
echo $unknownActor->identifier(); // 'unknown'
```

Actor Implementations
---------------------

[](#actor-implementations)

ActorUse CaseIdentifier`IdentifiedActor`Users, entities with UUIDUUID string`NamedActor`Cron jobs, workers, servicesCustom name`UnknownActor`Anonymous, unidentified`'unknown'`Creating Domain-Specific Actors
-------------------------------

[](#creating-domain-specific-actors)

Extend base actors for your domain:

```
use PhpArchitecture\Actor\IdentifiedActor;
use PhpArchitecture\Actor\Identity\ActorId;
use PhpArchitecture\Uuid\Uuid;

// Domain-specific actor ID
final class UserId extends ActorId
{
    public static function new(): static
    {
        return static::v7();
    }
}

// Domain-specific actor
class UserActor extends IdentifiedActor
{
    private string $email;
    private array $roles;

    public function __construct(UserId $id, string $email, array $roles = [])
    {
        parent::__construct($id);
        $this->email = $email;
        $this->roles = $roles;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

    public function hasRole(string $role): bool
    {
        return in_array($role, $this->roles, true);
    }
}
```

Usage in Aggregates
-------------------

[](#usage-in-aggregates)

Pass Actor to aggregate methods for authorization and audit:

```
use PhpArchitecture\Actor\Actor;
use PhpArchitecture\DomainCore\AggregateRoot;
use PhpArchitecture\DomainCore\Exception\InsufficientPrivilegeException;

class Order extends AggregateRoot
{
    private string $ownerId;

    public function cancel(Actor $actor): void
    {
        if ($actor->identifier() !== $this->ownerId) {
            throw new InsufficientPrivilegeException('Only owner can cancel order');
        }

        $this->status = 'cancelled';
        $this->recordEvent(new OrderCancelled($this->id, $actor->identifier()));
    }
}
```

Usage in Domain Events
----------------------

[](#usage-in-domain-events)

Track who performed actions:

```
use PhpArchitecture\DomainCore\DomainEvent;

class OrderCancelled implements DomainEvent
{
    public function __construct(
        public readonly string $orderId,
        public readonly string $cancelledBy, // Actor identifier
        public readonly \DateTimeImmutable $cancelledAt,
    ) {}
}
```

Creating Actor from Request (Infrastructure)
--------------------------------------------

[](#creating-actor-from-request-infrastructure)

```
// Symfony Controller
use PhpArchitecture\Actor\Actor;
use PhpArchitecture\Actor\IdentifiedActor;
use PhpArchitecture\Actor\UnknownActor;
use PhpArchitecture\Actor\Identity\ActorId;

class OrderController
{
    public function cancel(Request $request, OrderService $service): Response
    {
        $actor = $this->resolveActor($request);
        $service->cancelOrder($request->get('orderId'), $actor);

        return new JsonResponse(['status' => 'cancelled']);
    }

    private function resolveActor(Request $request): Actor
    {
        $userId = $request->attributes->get('user_id');

        if ($userId) {
            return new IdentifiedActor(ActorId::fromString($userId));
        }

        return new UnknownActor();
    }
}
```

API Reference
-------------

[](#api-reference)

### Actor (interface)

[](#actor-interface)

MethodDescription`identifier(): string`Returns unique identifier for the actor### IdentifiedActor

[](#identifiedactor)

MethodDescription`__construct(ActorId $id)`Create actor with UUID identity`identifier(): string`Returns UUID string### NamedActor

[](#namedactor)

MethodDescription`__construct(string $name)`Create actor with custom name`identifier(): string`Returns the name### UnknownActor

[](#unknownactor)

MethodDescription`identifier(): string`Returns `'unknown'``IDENTIFIER` (const)`'unknown'`### ActorId

[](#actorid)

Extends `Uuid` - all UUID methods available. See [php-architecture-kit/uuid](https://github.com/php-architecture-kit/uuid).

Testing
-------

[](#testing)

Package is tested with PHPUnit in the [php-architecture-kit/workspace](https://github.com/php-architecture-kit/workspace) project.

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 70% of packages

Maintenance73

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~83 days

Total

2

Last Release

34d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/145db325ca53baabce2d955faebe43d56bc4f3122b9ae463d41ee0e5da487cea?d=identicon)[patrykbaszak](/maintainers/patrykbaszak)

---

Top Contributors

[![patrykbaszak](https://avatars.githubusercontent.com/u/66377724?v=4)](https://github.com/patrykbaszak "patrykbaszak (6 commits)")

---

Tags

identitydddframework agnosticactor

### Embed Badge

![Health badge](/badges/php-architecture-kit-actor/health.svg)

```
[![Health](https://phpackages.com/badges/php-architecture-kit-actor/health.svg)](https://phpackages.com/packages/php-architecture-kit-actor)
```

###  Alternatives

[prooph/service-bus

PHP Enterprise Service Bus Implementation supporting CQRS and DDD

4421.4M32](/packages/prooph-service-bus)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k41](/packages/ecotone-ecotone)[prooph/event-sourcing

PHP EventSourcing library

266818.8k18](/packages/prooph-event-sourcing)[php-flasher/flasher

The foundational PHP library for PHPFlasher, enabling the creation of framework-agnostic flash notifications. Ideal for building custom integrations or for use in PHP projects.

634.7M41](/packages/php-flasher-flasher)[phpmentors/domain-kata

Kata for domain models

73441.4k9](/packages/phpmentors-domain-kata)[aura/payload

A Domain Payload implementation.

55377.9k9](/packages/aura-payload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
