actinity / actinite-client
Requires
- php: ^8.2
- ext-gmp: *
Requires (Dev)
- laravel/pint: ^1.29
- orchestra/testbench: ^11.0
- phpunit/phpunit: ^11.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Laravel client for an exact-locale, published CMS content graph.
use Actinity\ActiniteClient\ActiniteClient; $cms = new ActiniteClient('en_GB'); $conference = $cms->byRef('conference.2026'); foreach ($conference->speakers as $speaker) { echo $speaker->name; }
Finding nodes
byId() and byRef() return a Node or null. Public IDs are base-62 strings;
database ID 62 is public ID "10".
$conference = $cms->byId('10'); $participants = $cms->nodes() ->whereDefinition('speaker', 'organisation') ->orderBy('name') ->get();
nodes() returns a lazy NodeQuery. Definitions are exact matches: one
whereDefinition() matches any of its arguments, without inheritance. Additional
filters are combined with AND. Queries always require publication in the client's
locale, even when content exists in other locales. There is no locale fallback.
$query = $cms->nodes() ->whereDefinition('speaker') ->where('name', 'like', 'Ada%') ->whereIn('country', ['GB', 'FR']); $speakers = $query->get(); // Laravel Collection of Node objects $first = $query->first(); // Node or null $count = $query->count(); $exists = $query->exists();
Supported content operators are =, !=, <>, <, <=, >, >=, like, and
not like. The two-argument where('name', 'Ada Lovelace') uses equality. Values
are bound as text; numeric values such as 0 are accepted and converted to strings.
Missing fields do not match content predicates. Comparisons follow the database's
collation, and numeric-looking strings are compared and sorted as text.
whereId(), whereIds() and whereRef() filter metadata. where() and
orderBy() always refer to content fields. id and underscore-prefixed names are
reserved for system fields and cannot be used as content field slugs.
Traversing relationships
Relationship queries return the same builder as nodes():
$speakers = $conference->related('speakers') ->whereDefinition('speaker') ->where('name', 'like', 'Ada%') ->get(); $conferences = $speaker->incoming('speakers') ->whereDefinition('conference') ->get();
related() follows outgoing edges, while incoming() finds sources of incoming
edges with the supplied name. Both the anchor and result nodes must be published
in the client's locale. Incoming queries search the database regardless of which
nodes have previously been loaded.
Property access such as $conference->speakers lazily retrieves the complete
outgoing relationship. A filtered related() query never replaces that collection.
Every explicit relationship query is independent and sees the published store.
Property results are retained on that particular Node instance after loading.
An explicit query for an unknown relationship returns an empty collection. An unknown property returns null; a known relationship whose targets are all unpublished returns an empty collection. Preloading preserves those distinctions. Traversal works at arbitrary depth, including finite walks through cycles.
Relationship predicates and preloading
$conferences = $cms->nodes() ->whereDefinition('conference') ->whereHas('speakers', fn ($speakers) => $speakers ->where('name', 'Ada Lovelace') ) ->with('speakers.organisation') ->get();
whereHas() filters roots by the existence of matching outgoing targets, without
duplicating roots when several targets match. whereDoesntHave() expresses the
inverse existence condition. Both support dot-separated paths:
$cms->nodes()->whereHas('speakers.organisation', fn ($organisations) => $organisations ->where('name', 'Computing Society') )->get();
Every intermediate node must also be published. A path cannot skip unpublished nodes to reach published descendants.
with('speakers.organisation', 'sponsors') preloads complete outgoing relationships
in batches. It does not filter roots or constrain relationship membership based on
whereHas(). No constrained eager-loading syntax is provided in this version.
Only explicitly named paths are preloaded; cyclic graphs do not trigger recursive
loading of the entire graph.
Ordering and execution
- Root and incoming queries default to ascending database ID.
- Outgoing queries default to
r_order, followed by ascending target ID. - Explicit
orderBy('field', 'asc'|'desc')clauses replace editorial ordering. Multiple clauses are supported, with ascending database ID as the final tie-breaker. - Missing sort fields come last in either direction.
limit()andoffset()restrict the selected window, includingcount()andexists(). Terminal methods do not mutate the builder;first()does not limit a laterget()to one result.
Builders are mutable, like Laravel query builders. Clone a query to branch it:
$speakers = $cms->nodes()->whereDefinition('speaker'); $ada = (clone $speakers)->where('name', 'Ada Lovelace')->first(); $all = $speakers->get();
Database queries and hydration currently run directly against the database.
There is no shared database-result cache or client-wide graph cache. Lazy property
loading and explicit with() loading are separate from query filtering, leaving
room for later batching and caching changes without changing this interface.
Fields, metadata and names
Nodes expose read-only id, _definition, _ref and _relations system fields. Content is available
through properties, array access, or explicit field access:
$speaker->name; $speaker['name']; $speaker->field('name');
Use field() and related() when a field and relationship have the same name:
field('speakers') and related('speakers'). Fields win over relationship property
shorthand. System fields cannot collide with content: id is reserved and content
field slugs cannot start with an underscore. Ordinary fields named definition
or ref are allowed and remain separate from _definition and _ref. No dynamic
relationship methods such as speakers() are provided.
Field slugs, definitions and relationship names must be nonempty ASCII letters,
digits or underscores ([A-Za-z0-9_]+). Leading digits are allowed. Dots separate
relationship path segments and cannot appear in individual slugs. References such
as conference.2026 are not subject to slug validation.
Content field slugs additionally cannot be id or start with an underscore.
These rules are checked in field access, content predicates, sorting and hydration.
JSON serialization returns a single flat object containing the system fields and content fields, without a nested field container:
{
"id": "11",
"_definition": "speaker",
"_ref": "speaker.ada",
"_relations": {"organisation": ["13"]},
"name": "Ada Lovelace",
"biography": "Mathematician and writer."
}
_relations is null when the node has no outgoing relationships. Otherwise it is
an object keyed by relationship name, containing arrays of public base-62 target
IDs in r_order, with target ID as the tie-breaker. Unpublished targets are omitted;
a known relationship with no published targets is represented by an empty array.
Even numeric relationship names serialize as object keys.
The ID map is populated during hydration, so serialization does not fetch related objects or issue further queries. Filtered relationship queries and eager loading do not change the map. Only IDs are serialized, keeping cyclic graphs safe and avoiding duplicated objects in front-end payloads.
Breaking changes
- The legacy
query('definition=...')API andActiniteQueryclass are removed. Usenodes()->whereDefinition(...)->get(). up()and the client-levelreverseRelation()are removed. Useincoming().- Raw
dataaccess is replaced by direct property/array access andfield(). JSON remains flat, withid,_definition,_ref,_relationsand content fields together. - Database lookups no longer preload an implicit two-hop neighbourhood or cache partially hydrated nodes across calls.
API mode retains direct byId() / byRef() lookups, property traversal and the
existing API-response cache. Fluent queries and relationship builders require
database mode and throw in API mode instead of reading the local database.
CSV content and tests
The existing act:fetch, act:dump, act:load and act:clear-cache commands remain
available. Empty strings are not valid stored content; empty CSV cells represent
null values for nullable columns. The authoring system applies fallback before
content reaches this package.
act:clear-cache invalidates API response caches only in API mode. In database
mode (the default), it returns successfully without using Redis or clearing cache
entries, so act:load does not require Redis.
Run vendor/bin/phpunit from the package root. See tests/README.md
for fixture details and the test environment.