Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/di/attribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Whole-method defaults:
public function execute(int $retries, int $delay) {}
}

*Arguments provided* via :php:meth:`Container::call`,
*Arguments provided* via :php:meth:`Infocyph\InterMix\DI\Container::call`,
:php:meth:`Infocyph\InterMix\DI\Managers\RegistrationManager::registerMethod`
or explicit arrays always **override** attributes.

Expand Down
161 changes: 135 additions & 26 deletions docs/di/cheat_sheet.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,137 @@
.. _di.cheat_sheet:

=============
Cheat‑Sheet
=============

A quick reference for the most common InterMix container actions:

+----------+-----------------------------------------------------+-----------------------------+
| Task | Fluent Chain | Stand‑Alone Call |
+==========+=====================================================+=============================+
| Bind | ``$c->definitions()->bind('k', 1)`` | – |
+----------+-----------------------------------------------------+-----------------------------+
| Register | ``$c->registration()->registerClass(Foo::class)`` | – |
+----------+-----------------------------------------------------+-----------------------------+
| Options | ``$c->options()->setOptions(...)`` | – |
+----------+-----------------------------------------------------+-----------------------------+
| Call | ``$c->invocation()->call(Foo::class)`` | ``$c->call(Foo::class)`` |
+----------+-----------------------------------------------------+-----------------------------+
| Make | ``$c->invocation()->make(Foo::class)`` | ``$c->make(Foo::class)`` |
+----------+-----------------------------------------------------+-----------------------------+

.. note::

Fluent chains allow batch configuration with optional chaining of multiple actions.
Stand-alone calls are shortcut helpers available directly from the container.

See also: :ref:`di.quickstart`, :ref:`di.usage`, :ref:`di.invocation`
=================
DI Cheat Sheet
=================

Quick reference for the current InterMix DI API.

-------------------------
Container Entry Points
-------------------------

+-----------------------------------------------+---------------------------------------------------------+
| Action | API |
+===============================================+=========================================================+
| Create/get instance | ``container('app')`` / ``Container::instance('app')`` |
+-----------------------------------------------+---------------------------------------------------------+
| Get manager | ``$c->definitions()`` / ``$c->registration()`` / |
| | ``$c->options()`` / ``$c->invocation()`` |
+-----------------------------------------------+---------------------------------------------------------+
| Resolve by ID/class | ``$c->get($id)`` |
+-----------------------------------------------+---------------------------------------------------------+
| Resolve + execute default/registered method | ``$c->getReturn(Foo::class)`` |
+-----------------------------------------------+---------------------------------------------------------+
| Build class (optional method) | ``$c->make(Foo::class, false|'run')`` |
+-----------------------------------------------+---------------------------------------------------------+
| Call closure/function/class/method | ``$c->call($target, $methodOrArgs)`` |
+-----------------------------------------------+---------------------------------------------------------+
| Scopes | ``$c->enterScope('req-1')`` / ``$c->leaveScope()`` / |
| | ``$c->withinScope('req-1', fn () => ...)`` |
+-----------------------------------------------+---------------------------------------------------------+
| Tags / tracing / graph | ``$c->findByTag('event')``, ``$c->debug($id)``, |
| | ``$c->tracer()->toArray()``, ``$c->exportGraph()`` |
+-----------------------------------------------+---------------------------------------------------------+
| Freeze config | ``$c->lock()`` |
+-----------------------------------------------+---------------------------------------------------------+

-----------------------------
Managers At A Glance
-----------------------------

+-----------------------+--------------------------------------------------------------+
| Manager | Core methods |
+=======================+==============================================================+
| ``definitions()`` | ``bind()``, ``addDefinitions()``, ``enableDefinitionCache()``,|
| | ``cacheAllDefinitions()``, ``setMetaForEnv()`` |
+-----------------------+--------------------------------------------------------------+
| ``registration()`` | ``registerClass()``, ``registerMethod()``, ``registerProperty()``, |
| | ``registerClosure()``, ``import()`` |
+-----------------------+--------------------------------------------------------------+
| ``options()`` | ``setOptions()``, ``enableLazyLoading()``, ``setEnvironment()``, |
| | ``bindInterfaceForEnv()``, ``setDefinitionMetaForEnv()``, |
| | ``enableDebugTracing()``, ``registerAttributeResolver()``, |
| | ``generatePreload()`` |
+-----------------------+--------------------------------------------------------------+
| ``invocation()`` | ``call()``, ``make()``, ``get()``, ``getReturn()``, ``has()`` |
+-----------------------+--------------------------------------------------------------+

All managers support ``->end()`` to return to the container and continue chaining.

------------------------------------------
Task Matrix (Fluent vs Shortcut)
------------------------------------------

+--------------------------+----------------------------------------------------+-----------------------------------+
| Task | Fluent chain | Shortcut on container |
+==========================+====================================================+===================================+
| Bind definition | ``$c->definitions()->bind('answer', 42)`` | - |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Register constructor map | ``$c->registration()->registerClass(Foo::class)`` | - |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Set options | ``$c->options()->setOptions(...)`` | ``$c->enableLazyLoading(true)`` |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Resolve service | ``$c->invocation()->get(Foo::class)`` | ``$c->get(Foo::class)`` |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Resolve return value | ``$c->invocation()->getReturn(Foo::class)`` | ``$c->getReturn(Foo::class)`` |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Call target | ``$c->invocation()->call($target)`` | ``$c->call($target)`` |
+--------------------------+----------------------------------------------------+-----------------------------------+
| Build target | ``$c->invocation()->make(Foo::class)`` | ``$c->make(Foo::class)`` |
+--------------------------+----------------------------------------------------+-----------------------------------+

----------------------
Common Recipes
----------------------

Bootstrap chain:

.. code-block:: php

$c->definitions()
->bind(LoggerInterface::class, FileLogger::class)
->registration()
->registerClass(App::class, ['name' => 'InterMix'])
->options()
->setOptions(injection: true, methodAttributes: true)
->enableLazyLoading(true)
->end();

Environment-specific binding + metadata:

.. code-block:: php

use Infocyph\InterMix\DI\Support\LifetimeEnum;

$c->options()
->bindInterfaceForEnv('prod', MailerInterface::class, SmtpMailer::class)
->bindInterfaceForEnv('test', MailerInterface::class, FakeMailer::class)
->setDefinitionMetaForEnv('test', 'mailer', LifetimeEnum::Transient, ['core', 'test-only'])
->setEnvironment('test');

Definition cache warmup:

.. code-block:: php

$c->definitions()
->enableDefinitionCache('intermix')
->cacheAllDefinitions(forceClearFirst: true);

Scoped resolution:

.. code-block:: php

$result = $c->withinScope('request-42', function () use ($c) {
return $c->get(RequestContext::class);
});

---------------------------
Advanced Helpers
---------------------------

* ``$c->parseCallable($spec)``: normalize closure/function/class/method input.
* ``$c->resolveNow(...)``: resolve with explicit runtime knobs.
* ``$c->getRepository()``: inspect low-level runtime state.
* ``$c->setResolverClass(FooResolver::class)``: swap resolver implementation.

See also: :ref:`di.quickstart`, :ref:`di.definitions`, :ref:`di.registration`, :ref:`di.options`, :ref:`di.invocation`, :ref:`di.scopes`, :ref:`di.environment`, :ref:`di.debug_tracing`
5 changes: 3 additions & 2 deletions docs/di/environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ Priority & Resolution Order
-----------------------------

If multiple environments are defined, InterMix **only uses** the one explicitly
set via :php:meth:`setEnvironment`.
set via :php:meth:`Infocyph\InterMix\DI\Managers\OptionsManager::setEnvironment`.

Resolution priority:

1. **Environment-bound class** (if active)
2. **Globally bound class** via :php:meth:`bind()`
2. **Globally bound class** via
:php:meth:`Infocyph\InterMix\DI\Managers\DefinitionManager::bind`
3. **Autowire fallback** (if `injection=true`)

-------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/di/invoker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Overview

.. code-block:: php

use Infocyph\InterMix\Container;
use Infocyph\InterMix\DI\Container;
use Infocyph\InterMix\DI\Invoker;

$invoker = Invoker::with(new Container());
Expand Down
5 changes: 3 additions & 2 deletions docs/di/tagging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ collection.
Add a Tag 🏷️
-----------------

Simply pass **`tags:[…]`** to :php:meth:`DefinitionManager::bind`.
Simply pass **`tags:[…]`** to
:php:meth:`Infocyph\InterMix\DI\Managers\DefinitionManager::bind`.

.. code-block:: php

Expand All @@ -35,7 +36,7 @@ Retrieve All by Tag 📬
$factory()->handle($event);
}

* :php:meth:`Container.findByTag()` returns an **array**:
* :php:meth:`Infocyph\InterMix\DI\Container::findByTag` returns an **array**:
``[id => callable|object, …]``
* Services are resolved **lazily** – if the definition was a class string the
container still honours lazy loading & lifetimes.
Expand Down
5 changes: 3 additions & 2 deletions docs/serializer/value_serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Under the hood it relies on:
anonymous classes & deep object graphs.
2. A **plugin system** (“resource handlers”) that can *wrap* any PHP
**resource** into plain data and *restore* it on the way back.
3. A tiny **memo-cache** inside :php:meth:`isSerializedClosure()` to detect
3. A tiny **memo-cache** inside
:php:meth:`Infocyph\InterMix\Serializer\ValueSerializer::isSerializedClosure`
to detect
Opis payloads with **O(1)** string checks.

Why?
Expand Down Expand Up @@ -120,4 +122,3 @@ Registering a Resource Handler
fn ($res) => /* …wrap… */ ,
fn ($data) => /* …restore… */
);

Loading