🆙 Add cms i using 🆙

This commit is contained in:
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,33 @@
<?php
namespace Spatie\Invade;
/**
* @template T of object
* @mixin T
*/
class Invader
{
/**
* @param T $obj
*/
public function __construct(
public object $obj
) {
}
public function __get(string $name): mixed
{
return (fn () => $this->{$name})->call($this->obj);
}
public function __set(string $name, mixed $value): void
{
(fn () => $this->{$name} = $value)->call($this->obj);
}
public function __call(string $name, array $params = []): mixed
{
return (fn () => $this->{$name}(...$params))->call($this->obj);
}
}
@@ -0,0 +1,49 @@
<?php
namespace Spatie\Invade;
use Exception;
class StaticInvader
{
private ?string $method = null;
/**
* @param class-string $className
*/
public function __construct(
public string $className,
) {
}
public function get(string $name): mixed
{
return (fn () => static::${$name})->bindTo(null, $this->className)();
}
public function set(string $name, mixed $value): void
{
(fn ($value) => static::${$name} = $value)->bindTo(null, $this->className)($value);
}
public function method(string $name): self
{
$this->method = $name;
return $this;
}
/**
* @throws Exception
*/
public function call(...$params): mixed
{
if ($this->method === null) {
throw new Exception(
'No method to be called. Use it like: invadeStatic(Foo::class)->method(\'bar\')->call()'
);
}
return (fn ($method) => static::{$method}(...$params))->bindTo(null, $this->className)($this->method);
}
}
@@ -0,0 +1,21 @@
<?php
use Spatie\Invade\Invader;
use Spatie\Invade\StaticInvader;
if (! function_exists('invade')) {
/**
* @template T of object
*
* @param T|class-string $object
* @return Invader<T>|StaticInvader
*/
function invade(object|string $object): Invader|StaticInvader
{
if (is_object($object)) {
return new Invader($object);
}
return new StaticInvader($object);
}
}