\Greg\Support\Obj
is working with objects.
- call - Call a callable with arguments;
- callRef - Call a callable with arguments reference;
- callMixed - Call a callable with mixed arguments. You don't care anymore of arguments order;
- callMixedRef - Call a callable with mixed arguments reference. You don't care anymore of arguments order;
- baseName - Get basename of a class;
- exists - Determine if a class exists;
- uses - Get all uses of a class;
- usesRecursive - Get all uses of a class and its parents.
Call a callable with arguments.
call(callable(...$args): mixed $callable, ...$args): mixed
$callable
- Callable;
...$args
- Arguments that was set in ...$args
;
...$args
- Callable arguments.
Example:
\Greg\Support\Obj::call(function($foo) { return $foo; }, 'foo'); // result: foo
Call a callable with arguments reference. See call method.
Call a callable with mixed arguments. You don't care anymore of arguments order.
callMixed(callable(...$args): mixed $callable, ...$args): mixed
$callable
- Callable;
...$args
- Arguments that was set in ...$args
;
...$args
- Callable arguments.
Example:
class Foo
{
}
$foo = new Foo();
\Greg\Support\Obj::callMixed(function (Foo $foo, $one, $two, $three = 3) { return func_get_args(); }, 1, $foo, 2); // result: [Foo, 1, 2]
Call a callable with mixed arguments reference. See callMixed method.
Get basename of a class.
baseName(string|object $class): string
$class
- The class.
Example:
\Greg\Support\Obj::baseName(Foo\Bar::class); // result: Bar
Determine if a class exists.
exists(string|array $name, string|array $prefix = null, string|array $suffix = null): boolean
$name
- Name or name parts as array;
$prefix
- Prefix;
$suffix
- Suffix.
Example:
// Let say we have a class \Foo\BarStrategy
\Greg\Support\Obj::exists('Bar', 'Foo\\', 'Strategy'); // result: true
Get all uses of a class.
uses(string|object $class): array
$class
- The class.
Example:
trait FooTrait
{
}
trait BarTrait
{
use FooTrait;
}
class Baz
{
use BarTrait;
}
\Greg\Support\Obj::uses(Baz::class); // result: ['BarTrait' => 'BarTrait', 'FooTrait' => 'FooTrait']
Get all uses of a class and its parents. See uses method.