Menu

## Mixin

Mixin.php : 31

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

Mixin.php : 36

Stack of macro instance contexts.

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

### Methods

#### mixin()

Mixin.php : 65

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()

Mixin.php : 182

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()

Mixin.php : 196

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

`protected static context() : static|null`

##### Return values

static|null

#### this()

Mixin.php : 204

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

`protected static this() : static`

##### Return values

static

#### getAnonymousClassCodeForTrait()

Mixin.php : 163
`private static getAnonymousClassCodeForTrait(string $trait) : string`

##### Parameters

$trait : string

##### Return values

string

#### getMixableMethods()

Mixin.php : 168
`private static getMixableMethods(self $context) : Generator`

##### Parameters

$context : self

##### Return values

Generator

#### loadMixinClass()

Mixin.php : 75
`private static loadMixinClass(object|string $mixin) : void`

##### Parameters

$mixin : object|string

##### Tags

throws
  ReflectionException

#### loadMixinTrait()

Mixin.php : 94
`private static loadMixinTrait(string $trait) : void`

##### Parameters

$trait : string

## Search results