Pionia Core

Mixin

Trait Mixin.

Allows mixing in entire classes with multiple macros.

Table of Contents

Properties

$macroContextStack  : array<string|int, mixed>
Stack of macro instance contexts.

Methods

mixin()  : void
Mix another object into the class.
bindMacroContext()  : mixed
Stack a Carbon context from inside calls of self::this() and execute a given action.
context()  : static|null
Return the current context from inside a macro callee or a null if static.
this()  : static
Return the current context from inside a macro callee or a new one if static.
getAnonymousClassCodeForTrait()  : string
getMixableMethods()  : Generator
loadMixinClass()  : void
loadMixinTrait()  : void

Properties

$macroContextStack

Stack of macro instance contexts.

protected static array<string|int, mixed> $macroContextStack = []

Methods

mixin()

Mix another object into the class.

public static mixin(object|string $mixin) : void
Parameters
$mixin : object|string
Tags
example
Carbon::mixin(new class {
  public function addMoon() {
    return function () {
      return $this->addDays(30);
    };
  }
  public function subMoon() {
    return function () {
      return $this->subDays(30);
    };
  }
});
$fullMoon = Carbon::create('2018-12-22');
$nextFullMoon = $fullMoon->addMoon();
$blackMoon = Carbon::create('2019-01-06');
$previousBlackMoon = $blackMoon->subMoon();
echo "$nextFullMoon\n";
echo "$previousBlackMoon\n";
throws
ReflectionException

bindMacroContext()

Stack a Carbon context from inside calls of self::this() and execute a given action.

protected static bindMacroContext(self|null $context, callable $callable) : mixed
Parameters
$context : self|null
$callable : callable

context()

Return the current context from inside a macro callee or a null if static.

protected static context() : static|null
Return values
static|null

this()

Return the current context from inside a macro callee or a new one if static.

protected static this() : static
Return values
static

getAnonymousClassCodeForTrait()

private static getAnonymousClassCodeForTrait(string $trait) : string
Parameters
$trait : string
Return values
string

getMixableMethods()

private static getMixableMethods(self $context) : Generator
Parameters
$context : self
Return values
Generator

loadMixinClass()

private static loadMixinClass(object|string $mixin) : void
Parameters
$mixin : object|string
Tags
throws
ReflectionException

loadMixinTrait()

private static loadMixinTrait(string $trait) : void
Parameters
$trait : string

        
On this page

Search results