Skip to content

Commit ff25132

Browse files
committed
Fixed macrocalls for static & non-static
1 parent 4eb240d commit ff25132

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/K8s.php

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class K8s
88
{
99
use Macroable {
1010
__call as macroCall;
11+
__callStatic as macroCallStatic;
1112
}
1213

1314
/**
@@ -417,4 +418,20 @@ public function __call($method, $parameters)
417418

418419
return $this->cluster->{$method}(...$parameters);
419420
}
421+
422+
/**
423+
* Proxy the K8s static call to cluster object.
424+
*
425+
* @param string $method
426+
* @param array $parameters
427+
* @return mixed
428+
*/
429+
public static function __callStatic($method, $parameters)
430+
{
431+
if (static::hasMacro($method)) {
432+
return static::macroCallStatic($method, $parameters);
433+
}
434+
435+
return new static;
436+
}
420437
}

tests/Kinds/NewResource.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace RenokiCo\PhpK8s\Test\Kinds;
4+
5+
use RenokiCo\PhpK8s\Kinds\K8sPod;
6+
7+
class NewResource extends K8sPod
8+
{
9+
//
10+
}

tests/MacroTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public function test_resource_macro()
4141
public function test_k8s_macro()
4242
{
4343
K8s::macro('newResource', function ($cluster = null, $attributes = []) {
44-
return new K8sPod($cluster, $attributes);
44+
return new Kinds\NewResource($cluster, $attributes);
4545
});
4646

47-
$this->assertInstanceOf(K8sPod::class, K8s::newResource());
48-
$this->assertInstanceOf(K8sPod::class, $this->cluster->newResource());
47+
$this->assertInstanceOf(Kinds\NewResource::class, K8s::newResource());
48+
$this->assertInstanceOf(Kinds\NewResource::class, (new K8s)->newResource());
49+
$this->assertInstanceOf(Kinds\NewResource::class, $this->cluster->newResource());
4950
}
5051
}

0 commit comments

Comments
 (0)